restart project from django-cookiecutter
This commit is contained in:
parent
7bb2b23ba5
commit
7477a35001
|
@ -1,4 +1,5 @@
|
|||
[run]
|
||||
omit=
|
||||
*manage.py*
|
||||
*migrations*
|
||||
include = heima/*
|
||||
omit = *migrations*, *tests*
|
||||
plugins =
|
||||
django_coverage_plugin
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
.*
|
||||
!.coveragerc
|
||||
!.env
|
||||
!.pylintrc
|
|
@ -1,92 +1,66 @@
|
|||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
### OSX ###
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
### SublimeText ###
|
||||
# cache files for sublime text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
|
||||
# workspace files are user-specific
|
||||
*.sublime-workspace
|
||||
|
||||
# project files should be checked into the repository, unless a significant
|
||||
# proportion of contributors will probably not be using SublimeText
|
||||
# *.sublime-project
|
||||
|
||||
# sftp configuration file
|
||||
sftp-config.json
|
||||
|
||||
# Basics
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
__pycache__
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
env/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
npm-debug.log*
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
.tox
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*,cover
|
||||
.hypothesis/
|
||||
htmlcov
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
# Pycharm
|
||||
.idea/*
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
# Vim
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
*~
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
# npm
|
||||
node_modules/
|
||||
|
||||
# IPython Notebook
|
||||
.ipynb_checkpoints
|
||||
# Compass
|
||||
.sass-cache
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# dotenv
|
||||
# virtual environments
|
||||
.env
|
||||
|
||||
# virtualenv
|
||||
venv/
|
||||
ENV/
|
||||
# User-uploaded media
|
||||
heima/media/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
.editorconfig
|
||||
.pylintrc
|
||||
.travis.yml
|
||||
|
||||
staticfiles/
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
[MASTER]
|
||||
load-plugins=pylint_common, pylint_django
|
||||
|
||||
[FORMAT]
|
||||
max-line-length=120
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
disable=missing-docstring,invalid-name
|
||||
|
||||
[DESIGN]
|
||||
max-parents=13
|
||||
|
||||
[TYPECHECK]
|
||||
generated-members=REQUEST,acl_users,aq_parent,"[a-zA-Z]+_set{1,2}",save,delete
|
|
@ -0,0 +1,12 @@
|
|||
sudo: true
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq build-essential gettext python-dev zlib1g-dev libpq-dev xvfb
|
||||
- sudo apt-get install -qq libtiff4-dev libjpeg8-dev libfreetype6-dev liblcms1-dev libwebp-dev
|
||||
- sudo apt-get install -qq graphviz-dev python-setuptools python3-dev python-virtualenv python-pip
|
||||
- sudo apt-get install -qq firefox automake libtool libreadline6 libreadline6-dev libreadline-dev
|
||||
- sudo apt-get install -qq libsqlite3-dev libxml2 libxml2-dev libssl-dev libbz2-dev wget curl llvm
|
||||
language: python
|
||||
python:
|
||||
- "3.5"
|
||||
|
|
@ -0,0 +1 @@
|
|||
Fred Pauchou
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2017, Fred Pauchou
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
|
@ -1 +0,0 @@
|
|||
[![build status](https://framagit.org/Grimbox/heima/badges/master/build.svg)](https://framagit.org/Grimbox/heima/commits/master)
|
|
@ -0,0 +1,93 @@
|
|||
Heima
|
||||
=====
|
||||
|
||||
Heima a little project for home energy follow-up
|
||||
|
||||
.. image:: https://img.shields.io/badge/built%20with-Cookiecutter%20Django-ff69b4.svg
|
||||
:target: https://github.com/pydanny/cookiecutter-django/
|
||||
:alt: Built with Cookiecutter Django
|
||||
|
||||
|
||||
:License: MIT
|
||||
|
||||
|
||||
Settings
|
||||
--------
|
||||
|
||||
Moved to settings_.
|
||||
|
||||
.. _settings: http://cookiecutter-django.readthedocs.io/en/latest/settings.html
|
||||
|
||||
Basic Commands
|
||||
--------------
|
||||
|
||||
Setting Up Your Users
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
* To create a **normal user account**, just go to Sign Up and fill out the form. Once you submit it, you'll see a "Verify Your E-mail Address" page. Go to your console to see a simulated email verification message. Copy the link into your browser. Now the user's email should be verified and ready to go.
|
||||
|
||||
* To create an **superuser account**, use this command::
|
||||
|
||||
$ python manage.py createsuperuser
|
||||
|
||||
For convenience, you can keep your normal user logged in on Chrome and your superuser logged in on Firefox (or similar), so that you can see how the site behaves for both kinds of users.
|
||||
|
||||
Test coverage
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
To run the tests, check your test coverage, and generate an HTML coverage report::
|
||||
|
||||
$ coverage run manage.py test
|
||||
$ coverage html
|
||||
$ open htmlcov/index.html
|
||||
|
||||
Running tests with py.test
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
::
|
||||
|
||||
$ py.test
|
||||
|
||||
Live reloading and Sass CSS compilation
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Moved to `Live reloading and SASS compilation`_.
|
||||
|
||||
.. _`Live reloading and SASS compilation`: http://cookiecutter-django.readthedocs.io/en/latest/live-reloading-and-sass-compilation.html
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Sentry
|
||||
^^^^^^
|
||||
|
||||
Sentry is an error logging aggregator service. You can sign up for a free account at https://sentry.io/signup/?code=cookiecutter or download and host it yourself.
|
||||
The system is setup with reasonable defaults, including 404 logging and integration with the WSGI application.
|
||||
|
||||
You must set the DSN url in production.
|
||||
|
||||
|
||||
Deployment
|
||||
----------
|
||||
|
||||
The following details how to deploy this application.
|
||||
|
||||
|
||||
Heroku
|
||||
^^^^^^
|
||||
|
||||
See detailed `cookiecutter-django Heroku documentation`_.
|
||||
|
||||
.. _`cookiecutter-django Heroku documentation`: http://cookiecutter-django.readthedocs.io/en/latest/deployment-on-heroku.html
|
||||
|
||||
|
||||
|
||||
Docker
|
||||
^^^^^^
|
||||
|
||||
See detailed `cookiecutter-django Docker documentation`_.
|
||||
|
||||
.. _`cookiecutter-django Docker documentation`: http://cookiecutter-django.readthedocs.io/en/latest/deployment-with-docker.html
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
FROM python:3.5
|
||||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
# Requirements have to be pulled and installed here, otherwise caching won't work
|
||||
COPY ./requirements /requirements
|
||||
|
||||
RUN pip install -r /requirements/production.txt \
|
||||
&& groupadd -r django \
|
||||
&& useradd -r -g django django
|
||||
|
||||
COPY . /app
|
||||
RUN chown -R django /app
|
||||
|
||||
COPY ./compose/django/gunicorn.sh /gunicorn.sh
|
||||
COPY ./compose/django/entrypoint.sh /entrypoint.sh
|
||||
RUN sed -i 's/\r//' /entrypoint.sh \
|
||||
&& sed -i 's/\r//' /gunicorn.sh \
|
||||
&& chmod +x /entrypoint.sh \
|
||||
&& chown django /entrypoint.sh \
|
||||
&& chmod +x /gunicorn.sh \
|
||||
&& chown django /gunicorn.sh
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
|
@ -0,0 +1,19 @@
|
|||
FROM python:3.5
|
||||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
# Requirements have to be pulled and installed here, otherwise caching won't work
|
||||
COPY ./requirements /requirements
|
||||
RUN pip install -r /requirements/local.txt
|
||||
|
||||
COPY ./compose/django/entrypoint.sh /entrypoint.sh
|
||||
RUN sed -i 's/\r//' /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
COPY ./compose/django/start-dev.sh /start-dev.sh
|
||||
RUN sed -i 's/\r//' /start-dev.sh
|
||||
RUN chmod +x /start-dev.sh
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
cmd="$@"
|
||||
|
||||
# This entrypoint is used to play nicely with the current cookiecutter configuration.
|
||||
# Since docker-compose relies heavily on environment variables itself for configuration, we'd have to define multiple
|
||||
# environment variables just to support cookiecutter out of the box. That makes no sense, so this little entrypoint
|
||||
# does all this for us.
|
||||
export REDIS_URL=redis://redis:6379
|
||||
|
||||
# the official postgres image uses 'postgres' as default user if not set explictly.
|
||||
if [ -z "$POSTGRES_USER" ]; then
|
||||
export POSTGRES_USER=postgres
|
||||
fi
|
||||
|
||||
export DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:5432/$POSTGRES_USER
|
||||
|
||||
|
||||
function postgres_ready(){
|
||||
python << END
|
||||
import sys
|
||||
import psycopg2
|
||||
try:
|
||||
conn = psycopg2.connect(dbname="$POSTGRES_USER", user="$POSTGRES_USER", password="$POSTGRES_PASSWORD", host="postgres")
|
||||
except psycopg2.OperationalError:
|
||||
sys.exit(-1)
|
||||
sys.exit(0)
|
||||
END
|
||||
}
|
||||
|
||||
until postgres_ready; do
|
||||
>&2 echo "Postgres is unavailable - sleeping"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
>&2 echo "Postgres is up - continuing..."
|
||||
exec $cmd
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
python /app/manage.py collectstatic --noinput
|
||||
/usr/local/bin/gunicorn config.wsgi -w 4 -b 0.0.0.0:5000 --chdir=/app
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
python manage.py migrate
|
||||
python manage.py runserver_plus 0.0.0.0:8000
|
|
@ -0,0 +1,9 @@
|
|||
FROM nginx:latest
|
||||
ADD nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
|
||||
ADD start.sh /start.sh
|
||||
ADD nginx-secure.conf /etc/nginx/nginx-secure.conf
|
||||
ADD dhparams.pem /etc/ssl/private/dhparams.pem
|
||||
CMD /start.sh
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
-----BEGIN DH PARAMETERS-----
|
||||
EXAMPLE_FILE
|
||||
-----END DH PARAMETERS-----
|
|
@ -0,0 +1,96 @@
|
|||
user nginx;
|
||||
worker_processes 1;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
proxy_headers_hash_bucket_size 52;
|
||||
|
||||
gzip on;
|
||||
|
||||
upstream app {
|
||||
server django:5000;
|
||||
}
|
||||
server {
|
||||
listen 80;
|
||||
server_name ___my.example.com___ www.___my.example.com___;
|
||||
|
||||
location /.well-known/acme-challenge {
|
||||
# Since the certbot container isn't up constantly, need to resolve ip dynamically using docker's dns
|
||||
resolver ___NAMESERVER___;
|
||||
set $certbot_addr_port certbot:80;
|
||||
proxy_pass http://$certbot_addr_port;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location / {
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443;
|
||||
server_name ___my.example.com___ www.___my.example.com___;
|
||||
|
||||
ssl on;
|
||||
ssl_certificate /etc/letsencrypt/live/___my.example.com___/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/___my.example.com___/privkey.pem;
|
||||
ssl_session_timeout 5m;
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_dhparam /etc/ssl/private/dhparams.pem;
|
||||
|
||||
location /.well-known/acme-challenge {
|
||||
resolver ___NAMESERVER___;
|
||||
set $certbot_addr_port certbot:443;
|
||||
proxy_pass http://$certbot_addr_port;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
}
|
||||
|
||||
location / {
|
||||
# checks for static file, if not found proxy to app
|
||||
try_files $uri @proxy_to_app;
|
||||
}
|
||||
|
||||
# cookiecutter-django app
|
||||
location @proxy_to_app {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_redirect off;
|
||||
|
||||
proxy_pass http://app;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
user nginx;
|
||||
worker_processes 1;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
|
||||
upstream app {
|
||||
server django:5000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
charset utf-8;
|
||||
|
||||
|
||||
server_name ___my.example.com___ ;
|
||||
|
||||
location /.well-known/acme-challenge {
|
||||
proxy_pass http://certbot:80;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
}
|
||||
|
||||
|
||||
location / {
|
||||
# checks for static file, if not found proxy to app
|
||||
try_files $uri @proxy_to_app;
|
||||
}
|
||||
|
||||
# cookiecutter-django app
|
||||
location @proxy_to_app {
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $http_host;
|
||||
proxy_redirect off;
|
||||
proxy_pass http://app;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
echo sleep 5
|
||||
sleep 5
|
||||
|
||||
echo build starting nginx config
|
||||
|
||||
|
||||
echo replacing ___my.example.com___/$MY_DOMAIN_NAME
|
||||
|
||||
# Put your domain name into the nginx reverse proxy config.
|
||||
sed -i "s/___my.example.com___/$MY_DOMAIN_NAME/g" /etc/nginx/nginx.conf
|
||||
|
||||
cat /etc/nginx/nginx.conf
|
||||
echo .
|
||||
echo Firing up nginx in the background.
|
||||
nginx
|
||||
|
||||
# # Check user has specified domain name
|
||||
if [ -z "$MY_DOMAIN_NAME" ]; then
|
||||
echo "Need to set MY_DOMAIN_NAME (to a letsencrypt-registered name)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# This bit waits until the letsencrypt container has done its thing.
|
||||
# We see the changes here bceause there's a docker volume mapped.
|
||||
echo Waiting for folder /etc/letsencrypt/live/$MY_DOMAIN_NAME to exist
|
||||
while [ ! -d /etc/letsencrypt/live/$MY_DOMAIN_NAME ] ;
|
||||
do
|
||||
sleep 2
|
||||
done
|
||||
|
||||
while [ ! -f /etc/letsencrypt/live/$MY_DOMAIN_NAME/fullchain.pem ] ;
|
||||
do
|
||||
echo Waiting for file fullchain.pem to exist
|
||||
sleep 2
|
||||
done
|
||||
|
||||
while [ ! -f /etc/letsencrypt/live/$MY_DOMAIN_NAME/privkey.pem ] ;
|
||||
do
|
||||
echo Waiting for file privkey.pem to exist
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# This is added so that when the certificate is being renewed or is already in place, nginx waits for everything to be good.
|
||||
sleep 15
|
||||
|
||||
echo replacing ___my.example.com___/$MY_DOMAIN_NAME
|
||||
|
||||
|
||||
# Put your domain name into the nginx reverse proxy config.
|
||||
sed -i "s/___my.example.com___/$MY_DOMAIN_NAME/g" /etc/nginx/nginx-secure.conf
|
||||
|
||||
# Add the system's nameserver (the docker network dns) so we can resolve container names in nginx
|
||||
NAMESERVER=`cat /etc/resolv.conf | grep "nameserver" | awk '{print $2}' | tr '\n' ' '`
|
||||
echo replacing ___NAMESERVER___/$NAMESERVER
|
||||
sed -i "s/___NAMESERVER___/$NAMESERVER/g" /etc/nginx/nginx-secure.conf
|
||||
|
||||
|
||||
#go!
|
||||
kill $(ps aux | grep 'nginx' | grep -v 'grep' | awk '{print $2}')
|
||||
cp /etc/nginx/nginx-secure.conf /etc/nginx/nginx.conf
|
||||
|
||||
nginx -g 'daemon off;'
|
|
@ -0,0 +1,11 @@
|
|||
FROM postgres:9.6
|
||||
|
||||
# add backup scripts
|
||||
ADD backup.sh /usr/local/bin/backup
|
||||
ADD restore.sh /usr/local/bin/restore
|
||||
ADD list-backups.sh /usr/local/bin/list-backups
|
||||
|
||||
# make them executable
|
||||
RUN chmod +x /usr/local/bin/restore
|
||||
RUN chmod +x /usr/local/bin/list-backups
|
||||
RUN chmod +x /usr/local/bin/backup
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
# stop on errors
|
||||
set -e
|
||||
|
||||
# we might run into trouble when using the default `postgres` user, e.g. when dropping the postgres
|
||||
# database in restore.sh. Check that something else is used here
|
||||
if [ "$POSTGRES_USER" == "postgres" ]
|
||||
then
|
||||
echo "creating a backup as the postgres user is not supported, make sure to set the POSTGRES_USER environment variable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# export the postgres password so that subsequent commands don't ask for it
|
||||
export PGPASSWORD=$POSTGRES_PASSWORD
|
||||
|
||||
echo "creating backup"
|
||||
echo "---------------"
|
||||
|
||||
FILENAME=backup_$(date +'%Y_%m_%dT%H_%M_%S').sql.gz
|
||||
pg_dump -h postgres -U $POSTGRES_USER | gzip > /backups/$FILENAME
|
||||
|
||||
echo "successfully created backup $FILENAME"
|
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
echo "listing available backups"
|
||||
echo "-------------------------"
|
||||
ls /backups/
|
|
@ -0,0 +1,56 @@
|
|||
#!/bin/bash
|
||||
|
||||
# stop on errors
|
||||
set -e
|
||||
|
||||
# we might run into trouble when using the default `postgres` user, e.g. when dropping the postgres
|
||||
# database in restore.sh. Check that something else is used here
|
||||
if [ "$POSTGRES_USER" == "postgres" ]
|
||||
then
|
||||
echo "restoring as the postgres user is not supported, make sure to set the POSTGRES_USER environment variable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# export the postgres password so that subsequent commands don't ask for it
|
||||
export PGPASSWORD=$POSTGRES_PASSWORD
|
||||
|
||||
# check that we have an argument for a filename candidate
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
echo 'usage:'
|
||||
echo ' docker-compose run postgres restore <backup-file>'
|
||||
echo ''
|
||||
echo 'to get a list of available backups, run:'
|
||||
echo ' docker-compose run postgres list-backups'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# set the backupfile variable
|
||||
BACKUPFILE=/backups/$1
|
||||
|
||||
# check that the file exists
|
||||
if ! [ -f $BACKUPFILE ]; then
|
||||
echo "backup file not found"
|
||||
echo 'to get a list of available backups, run:'
|
||||
echo ' docker-compose run postgres list-backups'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "beginning restore from $1"
|
||||
echo "-------------------------"
|
||||
|
||||
# delete the db
|
||||
# deleting the db can fail. Spit out a comment if this happens but continue since the db
|
||||
# is created in the next step
|
||||
echo "deleting old database $POSTGRES_USER"
|
||||
if dropdb -h postgres -U $POSTGRES_USER $POSTGRES_USER
|
||||
then echo "deleted $POSTGRES_USER database"
|
||||
else echo "database $POSTGRES_USER does not exist, continue"
|
||||
fi
|
||||
|
||||
# create a new database
|
||||
echo "creating new database $POSTGRES_USER"
|
||||
createdb -h postgres -U $POSTGRES_USER $POSTGRES_USER -O $POSTGRES_USER
|
||||
|
||||
# restore the database
|
||||
echo "restoring database $POSTGRES_USER"
|
||||
gunzip -c $BACKUPFILE | psql -h postgres -U $POSTGRES_USER
|
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
|
@ -0,0 +1,272 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Django settings for Heima project.
|
||||
|
||||
For more information on this file, see
|
||||
https://docs.djangoproject.com/en/dev/topics/settings/
|
||||
|
||||
For the full list of settings and their values, see
|
||||
https://docs.djangoproject.com/en/dev/ref/settings/
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import environ
|
||||
|
||||
ROOT_DIR = environ.Path(__file__) - 3 # (heima/config/settings/common.py - 3 = heima/)
|
||||
APPS_DIR = ROOT_DIR.path('heima')
|
||||
|
||||
env = environ.Env()
|
||||
|
||||
# Load operating system environment variables and then prepare to use them
|
||||
env = environ.Env()
|
||||
|
||||
# .env file, should load only in development environment
|
||||
READ_DOT_ENV_FILE = env('DJANGO_READ_DOT_ENV_FILE', default=False)
|
||||
|
||||
if READ_DOT_ENV_FILE:
|
||||
# Operating System Environment variables have precedence over variables defined in the .env file,
|
||||
# that is to say variables from the .env files will only be used if not defined
|
||||
# as environment variables.
|
||||
env_file = str(ROOT_DIR.path('.env'))
|
||||
print('Loading : {}'.format(env_file))
|
||||
env.read_env(env_file)
|
||||
print('The .env file has been loaded. See common.py for more information')
|
||||
|
||||
# APP CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
DJANGO_APPS = (
|
||||
# Default Django apps:
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
'django.contrib.sessions',
|
||||
'django.contrib.sites',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
# Useful template tags:
|
||||
# 'django.contrib.humanize',
|
||||
|
||||
# Admin
|
||||
'django.contrib.admin',
|
||||
)
|
||||
THIRD_PARTY_APPS = (
|
||||
'crispy_forms', # Form layouts
|
||||
'allauth', # registration
|
||||
'allauth.account', # registration
|
||||
'allauth.socialaccount', # registration
|
||||
)
|
||||
|
||||
# Apps specific for this project go here.
|
||||
LOCAL_APPS = (
|
||||
# custom users app
|
||||
'heima.users.apps.UsersConfig',
|
||||
# Your stuff: custom apps go here
|
||||
'heima.sherlock',
|
||||
)
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
||||
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
||||
|
||||
# MIDDLEWARE CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
MIDDLEWARE = (
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
)
|
||||
|
||||
# MIGRATIONS CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
MIGRATION_MODULES = {
|
||||
'sites': 'heima.contrib.sites.migrations'
|
||||
}
|
||||
|
||||
# DEBUG
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
|
||||
DEBUG = env.bool('DJANGO_DEBUG', False)
|
||||
|
||||
# FIXTURE CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS
|
||||
FIXTURE_DIRS = (
|
||||
str(APPS_DIR.path('fixtures')),
|
||||
)
|
||||
|
||||
# EMAIL CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.smtp.EmailBackend')
|
||||
|
||||
# MANAGER CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins
|
||||
ADMINS = (
|
||||
("""Fred Pauchou""", 'fred@grimbox.be'),
|
||||
)
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers
|
||||
MANAGERS = ADMINS
|
||||
|
||||
# DATABASE CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||
DATABASES = {
|
||||
'default': env.db('DATABASE_URL', default='postgres:///django_heima'),
|
||||
}
|
||||
DATABASES['default']['ATOMIC_REQUESTS'] = True
|
||||
|
||||
|
||||
# GENERAL CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# Local time zone for this installation. Choices can be found here:
|
||||
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
|
||||
# although not all choices may be available on all operating systems.
|
||||
# In a Windows environment this must be set to your system time zone.
|
||||
TIME_ZONE = 'UTC'
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id
|
||||
SITE_ID = 1
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
|
||||
USE_I18N = True
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n
|
||||
USE_L10N = True
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
|
||||
USE_TZ = True
|
||||
|
||||
# TEMPLATE CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#templates
|
||||
TEMPLATES = [
|
||||
{
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
|
||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
|
||||
'DIRS': [
|
||||
str(APPS_DIR.path('templates')),
|
||||
],
|
||||
'OPTIONS': {
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
|
||||
'debug': DEBUG,
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
|
||||
# https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
|
||||
'loaders': [
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
],
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
|
||||
'context_processors': [
|
||||
'django.template.context_processors.debug',
|
||||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.template.context_processors.i18n',
|
||||
'django.template.context_processors.media',
|
||||
'django.template.context_processors.static',
|
||||
'django.template.context_processors.tz',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
# Your stuff: custom template context processors go here
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
# See: http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
|
||||
CRISPY_TEMPLATE_PACK = 'bootstrap4'
|
||||
|
||||
# STATIC FILE CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root
|
||||
STATIC_ROOT = str(ROOT_DIR('staticfiles'))
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
|
||||
STATICFILES_DIRS = (
|
||||
str(APPS_DIR.path('static')),
|
||||
)
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
|
||||
STATICFILES_FINDERS = (
|
||||
'django.contrib.staticfiles.finders.FileSystemFinder',
|
||||
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
||||
)
|
||||
|
||||
# MEDIA CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root
|
||||
MEDIA_ROOT = str(APPS_DIR('media'))
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url
|
||||
MEDIA_URL = '/media/'
|
||||
|
||||
# URL Configuration
|
||||
# ------------------------------------------------------------------------------
|
||||
ROOT_URLCONF = 'config.urls'
|
||||
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
|
||||
WSGI_APPLICATION = 'config.wsgi.application'
|
||||
|
||||
|
||||
# PASSWORD VALIDATION
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
AUTH_PASSWORD_VALIDATORS = [
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
|
||||
},
|
||||
{
|
||||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
|
||||
},
|
||||
]
|
||||
|
||||
# AUTHENTICATION CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
AUTHENTICATION_BACKENDS = (
|
||||
'django.contrib.auth.backends.ModelBackend',
|
||||
'allauth.account.auth_backends.AuthenticationBackend',
|
||||
)
|
||||
|
||||
# Some really nice defaults
|
||||
ACCOUNT_AUTHENTICATION_METHOD = 'username'
|
||||
ACCOUNT_EMAIL_REQUIRED = True
|
||||
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
|
||||
|
||||
ACCOUNT_ALLOW_REGISTRATION = env.bool('DJANGO_ACCOUNT_ALLOW_REGISTRATION', True)
|
||||
ACCOUNT_ADAPTER = 'heima.users.adapters.AccountAdapter'
|
||||
SOCIALACCOUNT_ADAPTER = 'heima.users.adapters.SocialAccountAdapter'
|
||||
|
||||
# Custom user app defaults
|
||||
# Select the correct user model
|
||||
AUTH_USER_MODEL = 'users.User'
|
||||
LOGIN_REDIRECT_URL = 'users:redirect'
|
||||
LOGIN_URL = 'account_login'
|
||||
|
||||
# SLUGLIFIER
|
||||
AUTOSLUG_SLUGIFY_FUNCTION = 'slugify.slugify'
|
||||
# django-compressor
|
||||
# ------------------------------------------------------------------------------
|
||||
INSTALLED_APPS += ("compressor", )
|
||||
STATICFILES_FINDERS += ("compressor.finders.CompressorFinder", )
|
||||
|
||||
# Location of root django.contrib.admin URL, use {% url 'admin:index' %}
|
||||
ADMIN_URL = r'^admin/'
|
||||
|
||||
# Your common stuff: Below this line define 3rd party library settings
|
||||
# ------------------------------------------------------------------------------
|
|
@ -0,0 +1,74 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Local settings
|
||||
|
||||
- Run in Debug mode
|
||||
|
||||
- Use console backend for emails
|
||||
|
||||
- Add Django Debug Toolbar
|
||||
- Add django-extensions as app
|
||||
"""
|
||||
|
||||
import socket
|
||||
import os
|
||||
from .common import * # noqa
|
||||
|
||||
# DEBUG
|
||||
# ------------------------------------------------------------------------------
|
||||
DEBUG = env.bool('DJANGO_DEBUG', default=True)
|
||||
TEMPLATES[0]['OPTIONS']['debug'] = DEBUG
|
||||
|
||||
# SECRET CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
||||
# Note: This key only used for development and testing.
|
||||
SECRET_KEY = env('DJANGO_SECRET_KEY', default='6&(gvn(i2m17@)n4t*@4!uzvp#l1e#4tlx4pd=012eykkxsf*8')
|
||||
|
||||
# Mail settings
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
EMAIL_PORT = 1025
|
||||
|
||||
EMAIL_HOST = 'localhost'
|
||||
EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND',
|
||||
default='django.core.mail.backends.console.EmailBackend')
|
||||
|
||||
|
||||
# CACHING
|
||||
# ------------------------------------------------------------------------------
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': ''
|
||||
}
|
||||
}
|
||||
|
||||
# django-debug-toolbar
|
||||
# ------------------------------------------------------------------------------
|
||||
MIDDLEWARE += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
|
||||
INSTALLED_APPS += ('debug_toolbar', )
|
||||
|
||||
INTERNAL_IPS = ['127.0.0.1', '10.0.2.2', ]
|
||||
# tricks to have debug toolbar when developing with docker
|
||||
if os.environ.get('USE_DOCKER') == 'yes':
|
||||
ip = socket.gethostbyname(socket.gethostname())
|
||||
INTERNAL_IPS += [ip[:-1] + "1"]
|
||||
|
||||
DEBUG_TOOLBAR_CONFIG = {
|
||||
'DISABLE_PANELS': [
|
||||
'debug_toolbar.panels.redirects.RedirectsPanel',
|
||||
],
|
||||
'SHOW_TEMPLATE_CONTEXT': True,
|
||||
}
|
||||
|
||||
# django-extensions
|
||||
# ------------------------------------------------------------------------------
|
||||
INSTALLED_APPS += ('django_extensions', )
|
||||
|
||||
# TESTING
|
||||
# ------------------------------------------------------------------------------
|
||||
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
|
||||
|
||||
# Your local stuff: Below this line define 3rd party library settings
|
||||
# ------------------------------------------------------------------------------
|
|
@ -0,0 +1,237 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Production Configurations
|
||||
|
||||
- Use Amazon's S3 for storing static files and uploaded media
|
||||
- Use mailgun to send emails
|
||||
- Use Redis for cache
|
||||
|
||||
- Use sentry for error logging
|
||||
|
||||
|
||||
- Use opbeat for error reporting
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from boto.s3.connection import OrdinaryCallingFormat
|
||||
from django.utils import six
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
from .common import * # noqa
|
||||
|
||||
# SECRET CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
||||
# Raises ImproperlyConfigured exception if DJANGO_SECRET_KEY not in os.environ
|
||||
SECRET_KEY = env('DJANGO_SECRET_KEY')
|
||||
|
||||
|
||||
# This ensures that Django will be able to detect a secure connection
|
||||
# properly on Heroku.
|
||||
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||
# raven sentry client
|
||||
# See https://docs.sentry.io/clients/python/integrations/django/
|
||||
INSTALLED_APPS += ('raven.contrib.django.raven_compat', )
|
||||
|
||||
# Use Whitenoise to serve static files
|
||||
# See: https://whitenoise.readthedocs.io/
|
||||
WHITENOISE_MIDDLEWARE = ('whitenoise.middleware.WhiteNoiseMiddleware', )
|
||||
MIDDLEWARE = WHITENOISE_MIDDLEWARE + MIDDLEWARE
|
||||
RAVEN_MIDDLEWARE = ('raven.contrib.django.raven_compat.middleware.SentryResponseErrorIdMiddleware', )
|
||||
MIDDLEWARE = RAVEN_MIDDLEWARE + MIDDLEWARE
|
||||
# opbeat integration
|
||||
# See https://opbeat.com/languages/django/
|
||||
INSTALLED_APPS += ('opbeat.contrib.django',)
|
||||
OPBEAT = {
|
||||
'ORGANIZATION_ID': env('DJANGO_OPBEAT_ORGANIZATION_ID'),
|
||||
'APP_ID': env('DJANGO_OPBEAT_APP_ID'),
|
||||
'SECRET_TOKEN': env('DJANGO_OPBEAT_SECRET_TOKEN')
|
||||
}
|
||||
MIDDLEWARE = (
|
||||
'opbeat.contrib.django.middleware.OpbeatAPMMiddleware',
|
||||
) + MIDDLEWARE
|
||||
|
||||
|
||||
# SECURITY CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See https://docs.djangoproject.com/en/1.9/ref/middleware/#module-django.middleware.security
|
||||
# and https://docs.djangoproject.com/ja/1.9/howto/deployment/checklist/#run-manage-py-check-deploy
|
||||
|
||||
# set this to 60 seconds and then to 518400 when you can prove it works
|
||||
SECURE_HSTS_SECONDS = 60
|
||||
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
|
||||
'DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS', default=True)
|
||||
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
|
||||
'DJANGO_SECURE_CONTENT_TYPE_NOSNIFF', default=True)
|
||||
SECURE_BROWSER_XSS_FILTER = True
|
||||
SESSION_COOKIE_SECURE = True
|
||||
SESSION_COOKIE_HTTPONLY = True
|
||||
SECURE_SSL_REDIRECT = env.bool('DJANGO_SECURE_SSL_REDIRECT', default=True)
|
||||
CSRF_COOKIE_SECURE = True
|
||||
CSRF_COOKIE_HTTPONLY = True
|
||||
X_FRAME_OPTIONS = 'DENY'
|
||||
|
||||
# SITE CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# Hosts/domain names that are valid for this site
|
||||
# See https://docs.djangoproject.com/en/1.6/ref/settings/#allowed-hosts
|
||||
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['heima.grimbox.be'])
|
||||
# END SITE CONFIGURATION
|
||||
|
||||
INSTALLED_APPS += ('gunicorn', )
|
||||
|
||||
|
||||
# STORAGE CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# Uploaded Media Files
|
||||
# ------------------------
|
||||
# See: http://django-storages.readthedocs.io/en/latest/index.html
|
||||
INSTALLED_APPS += (
|
||||
'storages',
|
||||
)
|
||||
|
||||
AWS_ACCESS_KEY_ID = env('DJANGO_AWS_ACCESS_KEY_ID')
|
||||
AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY')
|
||||
AWS_STORAGE_BUCKET_NAME = env('DJANGO_AWS_STORAGE_BUCKET_NAME')
|
||||
AWS_AUTO_CREATE_BUCKET = True
|
||||
AWS_QUERYSTRING_AUTH = False
|
||||
AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat()
|
||||
|
||||
# AWS cache settings, don't change unless you know what you're doing:
|
||||
AWS_EXPIRY = 60 * 60 * 24 * 7
|
||||
|
||||
# TODO See: https://github.com/jschneier/django-storages/issues/47
|
||||
# Revert the following and use str after the above-mentioned bug is fixed in
|
||||
# either django-storage-redux or boto
|
||||
AWS_HEADERS = {
|
||||
'Cache-Control': six.b('max-age=%d, s-maxage=%d, must-revalidate' % (
|
||||
AWS_EXPIRY, AWS_EXPIRY))
|
||||
}
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT, used for managing
|
||||
# stored files.
|
||||
MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME
|
||||
|
||||
|
||||
# Static Assets
|
||||
# ------------------------
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
|
||||
# COMPRESSOR
|
||||
# ------------------------------------------------------------------------------
|
||||
COMPRESS_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
|
||||
COMPRESS_URL = STATIC_URL
|
||||
COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)
|
||||
# EMAIL
|
||||
# ------------------------------------------------------------------------------
|
||||
DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
|
||||
default='Heima <noreply@heima.grimbox.be>')
|
||||
EMAIL_SUBJECT_PREFIX = env('DJANGO_EMAIL_SUBJECT_PREFIX', default='[Heima] ')
|
||||
SERVER_EMAIL = env('DJANGO_SERVER_EMAIL', default=DEFAULT_FROM_EMAIL)
|
||||
|
||||
# Anymail with Mailgun
|
||||
INSTALLED_APPS += ("anymail", )
|
||||
ANYMAIL = {
|
||||
"MAILGUN_API_KEY": env('DJANGO_MAILGUN_API_KEY'),
|
||||
"MAILGUN_SENDER_DOMAIN": env('MAILGUN_SENDER_DOMAIN')
|
||||
}
|
||||
EMAIL_BACKEND = "anymail.backends.mailgun.MailgunBackend"
|
||||
|
||||
# TEMPLATE CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See:
|
||||
# https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.cached.Loader
|
||||
TEMPLATES[0]['OPTIONS']['loaders'] = [
|
||||
('django.template.loaders.cached.Loader', [
|
||||
'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ]),
|
||||
]
|
||||
|
||||
# DATABASE CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Use the Heroku-style specification
|
||||
# Raises ImproperlyConfigured exception if DATABASE_URL not in os.environ
|
||||
DATABASES['default'] = env.db('DATABASE_URL')
|
||||
|
||||
# CACHING
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
REDIS_LOCATION = '{0}/{1}'.format(env('REDIS_URL', default='redis://127.0.0.1:6379'), 0)
|
||||
# Heroku URL does not pass the DB number, so we parse it in
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django_redis.cache.RedisCache',
|
||||
'LOCATION': REDIS_LOCATION,
|
||||
'OPTIONS': {
|
||||
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
|
||||
'IGNORE_EXCEPTIONS': True, # mimics memcache behavior.
|
||||
# http://niwinz.github.io/django-redis/latest/#_memcached_exceptions_behavior
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Sentry Configuration
|
||||
SENTRY_DSN = env('DJANGO_SENTRY_DSN')
|
||||
SENTRY_CLIENT = env('DJANGO_SENTRY_CLIENT', default='raven.contrib.django.raven_compat.DjangoClient')
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'disable_existing_loggers': True,
|
||||
'root': {
|
||||
'level': 'WARNING',
|
||||
'handlers': ['sentry'],
|
||||
},
|
||||
'formatters': {
|
||||
'verbose': {
|
||||
'format': '%(levelname)s %(asctime)s %(module)s '
|
||||
'%(process)d %(thread)d %(message)s'
|
||||
},
|
||||
},
|
||||
'handlers': {
|
||||
'sentry': {
|
||||
'level': 'ERROR',
|
||||
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
|
||||
},
|
||||
'console': {
|
||||
'level': 'DEBUG',
|
||||
'class': 'logging.StreamHandler',
|
||||
'formatter': 'verbose'
|
||||
}
|
||||
},
|
||||
'loggers': {
|
||||
'django.db.backends': {
|
||||
'level': 'ERROR',
|
||||
'handlers': ['console'],
|
||||
'propagate': False,
|
||||
},
|
||||
'raven': {
|
||||
'level': 'DEBUG',
|
||||
'handlers': ['console'],
|
||||
'propagate': False,
|
||||
},
|
||||
'sentry.errors': {
|
||||
'level': 'DEBUG',
|
||||
'handlers': ['console'],
|
||||
'propagate': False,
|
||||
},
|
||||
'django.security.DisallowedHost': {
|
||||
'level': 'ERROR',
|
||||
'handlers': ['console', 'sentry'],
|
||||
'propagate': False,
|
||||
},
|
||||
},
|
||||
}
|
||||
SENTRY_CELERY_LOGLEVEL = env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO)
|
||||
RAVEN_CONFIG = {
|
||||
'CELERY_LOGLEVEL': env.int('DJANGO_SENTRY_LOG_LEVEL', logging.INFO),
|
||||
'DSN': SENTRY_DSN
|
||||
}
|
||||
|
||||
# Custom Admin URL, use {% url 'admin:index' %}
|
||||
ADMIN_URL = env('DJANGO_ADMIN_URL')
|
||||
|
||||
# Your production stuff: Below this line define 3rd party library settings
|
||||
# ------------------------------------------------------------------------------
|
|
@ -0,0 +1,62 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Test settings
|
||||
|
||||
- Used to run tests fast on the continuous integration server and locally
|
||||
'''
|
||||
|
||||
from .common import * # noqa
|
||||
|
||||
|
||||
# DEBUG
|
||||
# ------------------------------------------------------------------------------
|
||||
# Turn debug off so tests run faster
|
||||
DEBUG = False
|
||||
TEMPLATES[0]['OPTIONS']['debug'] = False
|
||||
|
||||
# SECRET CONFIGURATION
|
||||
# ------------------------------------------------------------------------------
|
||||
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
|
||||
# Note: This key only used for development and testing.
|
||||
SECRET_KEY = env('DJANGO_SECRET_KEY', default='CHANGEME!!!')
|
||||
|
||||
# Mail settings
|
||||
# ------------------------------------------------------------------------------
|
||||
EMAIL_HOST = 'localhost'
|
||||
EMAIL_PORT = 1025
|
||||
|
||||
# In-memory email backend stores messages in django.core.mail.outbox
|
||||
# for unit testing purposes
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
|
||||
|
||||
# CACHING
|
||||
# ------------------------------------------------------------------------------
|
||||
# Speed advantages of in-memory caching without having to run Memcached
|
||||
CACHES = {
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': ''
|
||||
}
|
||||
}
|
||||
|
||||
# TESTING
|
||||
# ------------------------------------------------------------------------------
|
||||
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
|
||||
|
||||
|
||||
# PASSWORD HASHING
|
||||
# ------------------------------------------------------------------------------
|
||||
# Use fast password hasher so tests run faster
|
||||
PASSWORD_HASHERS = (
|
||||
'django.contrib.auth.hashers.MD5PasswordHasher',
|
||||
)
|
||||
|
||||
# TEMPLATE LOADERS
|
||||
# ------------------------------------------------------------------------------
|
||||
# Keep templates in memory so tests run faster
|
||||
TEMPLATES[0]['OPTIONS']['loaders'] = [
|
||||
('django.template.loaders.cached.Loader', [
|
||||
'django.template.loaders.filesystem.Loader',
|
||||
'django.template.loaders.app_directories.Loader',
|
||||
]),
|
||||
]
|
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.conf.urls import include, url
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.views.generic import TemplateView
|
||||
from django.views import defaults as default_views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name='home'),
|
||||
url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name='about'),
|
||||
|
||||
# Django Admin, use {% url 'admin:index' %}
|
||||
url(settings.ADMIN_URL, admin.site.urls),
|
||||
|
||||
# User management
|
||||
url(r'^users/', include('heima.users.urls', namespace='users')),
|
||||
url(r'^accounts/', include('allauth.urls')),
|
||||
|
||||
# Your stuff: custom urls includes go here
|
||||
|
||||
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
if settings.DEBUG:
|
||||
# This allows the error pages to be debugged during development, just visit
|
||||
# these url in browser to see how these error pages look like.
|
||||
urlpatterns += [
|
||||
url(r'^400/$', default_views.bad_request, kwargs={'exception': Exception('Bad Request!')}),
|
||||
url(r'^403/$', default_views.permission_denied, kwargs={'exception': Exception('Permission Denied')}),
|
||||
url(r'^404/$', default_views.page_not_found, kwargs={'exception': Exception('Page not Found')}),
|
||||
url(r'^500/$', default_views.server_error),
|
||||
]
|
||||
if 'debug_toolbar' in settings.INSTALLED_APPS:
|
||||
import debug_toolbar
|
||||
|
||||
urlpatterns += [
|
||||
url(r'^__debug__/', include(debug_toolbar.urls)),
|
||||
]
|
|
@ -0,0 +1,36 @@
|
|||
"""
|
||||
WSGI config for Heima project.
|
||||
|
||||
This module contains the WSGI application used by Django's development server
|
||||
and any production WSGI deployments. It should expose a module-level variable
|
||||
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
|
||||
this application via the ``WSGI_APPLICATION`` setting.
|
||||
|
||||
Usually you will have the standard Django WSGI application here, but it also
|
||||
might make sense to replace the whole Django WSGI application with a custom one
|
||||
that later delegates to the Django one. For example, you could introduce WSGI
|
||||
middleware here, or combine a Django application with an application of another
|
||||
framework.
|
||||
|
||||
"""
|
||||
import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production':
|
||||
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
|
||||
|
||||
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
|
||||
# if running multiple sites in the same mod_wsgi process. To fix this, use
|
||||
# mod_wsgi daemon mode with each site in its own daemon process, or use
|
||||
# os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings.production"
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production")
|
||||
|
||||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
application = get_wsgi_application()
|
||||
if os.environ.get('DJANGO_SETTINGS_MODULE') == 'config.settings.production':
|
||||
application = Sentry(application)
|
||||
# Apply WSGI middleware here.
|
||||
# from helloworld.wsgi import HelloWorldApplication
|
||||
# application = HelloWorldApplication(application)
|
|
@ -0,0 +1,170 @@
|
|||
[
|
||||
{
|
||||
"model": "sherlock.category",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"name": "Gaz"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.category",
|
||||
"pk": 2,
|
||||
"fields": {
|
||||
"name": "Elec"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.category",
|
||||
"pk": 3,
|
||||
"fields": {
|
||||
"name": "Eau"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.category",
|
||||
"pk": 4,
|
||||
"fields": {
|
||||
"name": "test"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.gauge",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"serial_number": "BL1343401",
|
||||
"category": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.gauge",
|
||||
"pk": 2,
|
||||
"fields": {
|
||||
"serial_number": "20752024",
|
||||
"category": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.gauge",
|
||||
"pk": 3,
|
||||
"fields": {
|
||||
"serial_number": "Undefined",
|
||||
"category": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.gauge",
|
||||
"pk": 4,
|
||||
"fields": {
|
||||
"serial_number": "undefined",
|
||||
"category": 4
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"moment": "2016-08-02T19:22:42Z",
|
||||
"value": "747411.0000",
|
||||
"gauge": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 2,
|
||||
"fields": {
|
||||
"moment": "2016-08-03T19:22:56Z",
|
||||
"value": "747.5869",
|
||||
"gauge": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 3,
|
||||
"fields": {
|
||||
"moment": "2016-08-04T19:24:18Z",
|
||||
"value": "747.8551",
|
||||
"gauge": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 4,
|
||||
"fields": {
|
||||
"moment": "2016-08-02T19:25:06Z",
|
||||
"value": "62672.4500",
|
||||
"gauge": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 5,
|
||||
"fields": {
|
||||
"moment": "2016-08-03T19:25:37Z",
|
||||
"value": "62677.3000",
|
||||
"gauge": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 6,
|
||||
"fields": {
|
||||
"moment": "2016-08-04T19:27:02Z",
|
||||
"value": "62682.4000",
|
||||
"gauge": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 7,
|
||||
"fields": {
|
||||
"moment": "2016-08-02T19:43:01Z",
|
||||
"value": "34397.8450",
|
||||
"gauge": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 8,
|
||||
"fields": {
|
||||
"moment": "2016-08-03T19:43:45Z",
|
||||
"value": "34403.8050",
|
||||
"gauge": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 9,
|
||||
"fields": {
|
||||
"moment": "2016-08-04T19:44:08Z",
|
||||
"value": "34409.9030",
|
||||
"gauge": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 13,
|
||||
"fields": {
|
||||
"moment": "2016-09-27T20:00:00Z",
|
||||
"value": "34731.6500",
|
||||
"gauge": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 14,
|
||||
"fields": {
|
||||
"moment": "2016-09-27T20:00:00Z",
|
||||
"value": "62979.8000",
|
||||
"gauge": 3
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "sherlock.mesure",
|
||||
"pk": 15,
|
||||
"fields": {
|
||||
"moment": "2016-09-27T20:00:00Z",
|
||||
"value": "6757.7578",
|
||||
"gauge": 1
|
||||
}
|
||||
}
|
||||
]
|
|
@ -0,0 +1,36 @@
|
|||
version: '2'
|
||||
|
||||
volumes:
|
||||
postgres_data_dev: {}
|
||||
postgres_backup_dev: {}
|
||||
|
||||
services:
|
||||
postgres:
|
||||
build: ./compose/postgres
|
||||
volumes:
|
||||
- postgres_data_dev:/var/lib/postgresql/data
|
||||
- postgres_backup_dev:/backups
|
||||
environment:
|
||||
- POSTGRES_USER=heima
|
||||
|
||||
django:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./compose/django/Dockerfile-dev
|
||||
command: /start-dev.sh
|
||||
depends_on:
|
||||
- postgres
|
||||
environment:
|
||||
- POSTGRES_USER=heima
|
||||
- USE_DOCKER=yes
|
||||
volumes:
|
||||
- .:/app
|
||||
ports:
|
||||
- "8000:8000"
|
||||
links:
|
||||
- postgres
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
version: '2'
|
||||
|
||||
volumes:
|
||||
postgres_data: {}
|
||||
postgres_backup: {}
|
||||
|
||||
services:
|
||||
postgres:
|
||||
build: ./compose/postgres
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- postgres_backup:/backups
|
||||
env_file: .env
|
||||
|
||||
django:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./compose/django/Dockerfile
|
||||
user: django
|
||||
depends_on:
|
||||
- postgres
|
||||
- redis
|
||||
command: /gunicorn.sh
|
||||
env_file: .env
|
||||
|
||||
nginx:
|
||||
build: ./compose/nginx
|
||||
depends_on:
|
||||
- django
|
||||
|
||||
- certbot
|
||||
|
||||
ports:
|
||||
- "0.0.0.0:80:80"
|
||||
|
||||
environment:
|
||||
- MY_DOMAIN_NAME=heima.grimbox.be
|
||||
ports:
|
||||
- "0.0.0.0:80:80"
|
||||
- "0.0.0.0:443:443"
|
||||
volumes:
|
||||
- /etc/letsencrypt:/etc/letsencrypt
|
||||
- /var/lib/letsencrypt:/var/lib/letsencrypt
|
||||
|
||||
certbot:
|
||||
image: quay.io/letsencrypt/letsencrypt
|
||||
command: bash -c "sleep 6 && certbot certonly -n --standalone -d heima.grimbox.be --text --agree-tos --email fred@grimbox.be --server https://acme-v01.api.letsencrypt.org/directory --rsa-key-size 4096 --verbose --keep-until-expiring --standalone-supported-challenges http-01"
|
||||
entrypoint: ""
|
||||
volumes:
|
||||
- /etc/letsencrypt:/etc/letsencrypt
|
||||
- /var/lib/letsencrypt:/var/lib/letsencrypt
|
||||
ports:
|
||||
- "80"
|
||||
- "443"
|
||||
environment:
|
||||
- TERM=xterm
|
||||
|
||||
|
||||
redis:
|
||||
image: redis:latest
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
-rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/heima.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/heima.qhc"
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/heima"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/heima"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
|
@ -0,0 +1 @@
|
|||
# Included so that Django's startproject comment runs against the docs directory
|
|
@ -0,0 +1,247 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Heima documentation build configuration file, created by
|
||||
# sphinx-quickstart.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
# sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration -----------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
# needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = []
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
# source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = 'Heima'
|
||||
copyright = """2017, Fred Pauchou"""
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.1'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '0.1'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
# language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
# today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
# today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ['_build']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all documents.
|
||||
# default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
# add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
# add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
# show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
# modindex_common_prefix = []
|
||||
|
||||
|
||||
# -- Options for HTML output ---------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = 'default'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
# html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
# html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
# html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
# html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
# html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
# html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
# html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
# html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
# html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
# html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
# html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
# html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
# html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
# html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
# html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
# html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
# html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
# html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'heimadoc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
# 'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
# 'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
# 'preamble': '',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
('index',
|
||||
'heima.tex',
|
||||
'Heima Documentation',
|
||||
"""Fred Pauchou""", 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
# latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
# latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
# latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
# latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
# latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
# latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output --------------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'heima', 'Heima Documentation',
|
||||
["""Fred Pauchou"""], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
# man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output ------------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
('index', 'heima', 'Heima Documentation',
|
||||
"""Fred Pauchou""", 'Heima',
|
||||
"""Heima a little project for home energy follow-up""", 'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
# texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
# texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
# texinfo_show_urls = 'footnote'
|
|
@ -0,0 +1,4 @@
|
|||
Deploy
|
||||
========
|
||||
|
||||
This is where you describe how the project is deployed in production.
|
|
@ -0,0 +1,186 @@
|
|||
Developing with Docker
|
||||
======================
|
||||
|
||||
You can develop your application in a `Docker`_ container for simpler deployment onto bare Linux machines later. This instruction assumes an `Amazon Web Services`_ EC2 instance, but it should work on any machine with Docker > 1.3 and `Docker compose`_ installed.
|
||||
|
||||
.. _Docker: https://www.docker.com/
|
||||
.. _Amazon Web Services: http://aws.amazon.com/
|
||||
.. _Docker compose: https://docs.docker.com/compose/
|
||||
|
||||
Setting up
|
||||
^^^^^^^^^^
|
||||
|
||||
Docker encourages running one container for each process. This might mean one container for your web server, one for Django application and a third for your database. Once you're happy composing containers in this way you can easily add more, such as a `Redis`_ cache.
|
||||
|
||||
.. _Redis: http://redis.io/
|
||||
|
||||
The Docker compose tool (previously known as `fig`_) makes linking these containers easy. An example set up for your Cookiecutter Django project might look like this:
|
||||
|
||||
.. _fig: http://www.fig.sh/
|
||||
|
||||
::
|
||||
|
||||
webapp/ # Your cookiecutter project would be in here
|
||||
Dockerfile
|
||||
...
|
||||
database/
|
||||
Dockerfile
|
||||
...
|
||||
webserver/
|
||||
Dockerfile
|
||||
...
|
||||
docker-compose.yml
|
||||
|
||||
Each component of your application would get its own `Dockerfile`_. The rest of this example assumes you are using the `base postgres image`_ for your database. Your database settings in `config/common.py` might then look something like:
|
||||
|
||||
.. _Dockerfile: https://docs.docker.com/reference/builder/
|
||||
.. _base postgres image: https://registry.hub.docker.com/_/postgres/
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'postgres',
|
||||
'USER': 'postgres',
|
||||
'HOST': 'database',
|
||||
'PORT': 5432,
|
||||
}
|
||||
}
|
||||
|
||||
The `Docker compose documentation`_ explains in detail what you can accomplish in the `docker-compose.yml` file, but an example configuration might look like this:
|
||||
|
||||
.. _Docker compose documentation: https://docs.docker.com/compose/#compose-documentation
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
database:
|
||||
build: database
|
||||
webapp:
|
||||
build: webapp:
|
||||
command: /usr/bin/python3.4 manage.py runserver 0.0.0.0:8000 # dev setting
|
||||
# command: gunicorn -b 0.0.0.0:8000 wsgi:application # production setting
|
||||
volumes:
|
||||
- webapp/your_project_name:/path/to/container/workdir/
|
||||
links:
|
||||
- database
|
||||
webserver:
|
||||
build: webserver
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
links:
|
||||
- webapp
|
||||
|
||||
We'll ignore the webserver for now (you'll want to comment that part out while we do). A working Dockerfile to run your cookiecutter application might look like this:
|
||||
|
||||
::
|
||||
|
||||
FROM ubuntu:14.04
|
||||
ENV REFRESHED_AT 2015-01-13
|
||||
|
||||
# update packages and prepare to build software
|
||||
RUN ["apt-get", "update"]
|
||||
RUN ["apt-get", "-y", "install", "build-essential", "vim", "git", "curl"]
|
||||
RUN ["locale-gen", "en_GB.UTF-8"]
|
||||
|
||||
# install latest python
|
||||
RUN ["apt-get", "-y", "build-dep", "python3-dev", "python3-imaging"]
|
||||
RUN ["apt-get", "-y", "install", "python3-dev", "python3-imaging", "python3-pip"]
|
||||
|
||||
# prepare postgreSQL support
|
||||
RUN ["apt-get", "-y", "build-dep", "python3-psycopg2"]
|
||||
|
||||
# move into our working directory
|
||||
# ADD must be after chown see http://stackoverflow.com/a/26145444/1281947
|
||||
RUN ["groupadd", "python"]
|
||||
RUN ["useradd", "python", "-s", "/bin/bash", "-m", "-g", "python", "-G", "python"]
|
||||
ENV HOME /home/python
|
||||
WORKDIR /home/python
|
||||
RUN ["chown", "-R", "python:python", "/home/python"]
|
||||
ADD ./ /home/python
|
||||
|
||||
# manage requirements
|
||||
ENV REQUIREMENTS_REFRESHED_AT 2015-02-25
|
||||
RUN ["pip3", "install", "-r", "requirements.txt"]
|
||||
|
||||
# uncomment the line below to use container as a non-root user
|
||||
USER python:python
|
||||
|
||||
Running `sudo docker-compose build` will follow the instructions in your `docker-compose.yml` file and build the database container, then your webapp, before mounting your cookiecutter project files as a volume in the webapp container and linking to the database. Our example yaml file runs in development mode but changing it to production mode is as simple as commenting out the line using `runserver` and uncommenting the line using `gunicorn`.
|
||||
|
||||
Both are set to run on port `0.0.0.0:8000`, which is where the Docker daemon will discover it. You can now run `sudo docker-compose up` and browse to `localhost:8000` to see your application running.
|
||||
|
||||
Deployment
|
||||
^^^^^^^^^^
|
||||
|
||||
You'll need a webserver container for deployment. An example setup for `Nginx`_ might look like this:
|
||||
|
||||
.. _Nginx: http://wiki.nginx.org/Main
|
||||
|
||||
::
|
||||
|
||||
FROM ubuntu:14.04
|
||||
ENV REFRESHED_AT 2015-02-11
|
||||
|
||||
# get the nginx package and set it up
|
||||
RUN ["apt-get", "update"]
|
||||
RUN ["apt-get", "-y", "install", "nginx"]
|
||||
|
||||
# forward request and error logs to docker log collector
|
||||
RUN ln -sf /dev/stdout /var/log/nginx/access.log
|
||||
RUN ln -sf /dev/stderr /var/log/nginx/error.log
|
||||
VOLUME ["/var/cache/nginx"]
|
||||
EXPOSE 80 443
|
||||
|
||||
# load nginx conf
|
||||
ADD ./site.conf /etc/nginx/sites-available/your_cookiecutter_project
|
||||
RUN ["ln", "-s", "/etc/nginx/sites-available/your_cookiecutter_project", "/etc/nginx/sites-enabled/your_cookiecutter_project"]
|
||||
RUN ["rm", "-rf", "/etc/nginx/sites-available/default"]
|
||||
|
||||
#start the server
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
That Dockerfile assumes you have an Nginx conf file named `site.conf` in the same directory as the webserver Dockerfile. A very basic example, which forwards traffic onto the development server or gunicorn for processing, would look like this:
|
||||
|
||||
::
|
||||
|
||||
# see http://serverfault.com/questions/577370/how-can-i-use-environment-variables-in-nginx-conf#comment730384_577370
|
||||
upstream localhost {
|
||||
server webapp_1:8000;
|
||||
}
|
||||
server {
|
||||
location / {
|
||||
proxy_pass http://localhost;
|
||||
}
|
||||
}
|
||||
|
||||
Running `sudo docker-compose build webserver` will build your server container. Running `sudo docker-compose up` will now expose your application directly on `localhost` (no need to specify the port number).
|
||||
|
||||
Building and running your app on EC2
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
All you now need to do to run your app in production is:
|
||||
|
||||
* Create an empty EC2 Linux instance (any Linux machine should do).
|
||||
|
||||
* Install your preferred source control solution, Docker and Docker compose on the news instance.
|
||||
|
||||
* Pull in your code from source control. The root directory should be the one with your `docker-compose.yml` file in it.
|
||||
|
||||
* Run `sudo docker-compose build` and `sudo docker-compose up`.
|
||||
|
||||
* Assign an `Elastic IP address`_ to your new machine.
|
||||
|
||||
.. _Elastic IP address: https://aws.amazon.com/articles/1346
|
||||
|
||||
* Point your domain name to the elastic IP.
|
||||
|
||||
**Be careful with Elastic IPs** because, on the AWS free tier, if you assign one and then stop the machine you will incur charges while the machine is down (presumably because you're preventing them allocating the IP to someone else).
|
||||
|
||||
Security advisory
|
||||
^^^^^^^^^^^^^^^^^
|
||||
|
||||
The setup described in this instruction will get you up-and-running but it hasn't been audited for security. If you are running your own setup like this it is always advisable to, at a minimum, examine your application with a tool like `OWASP ZAP`_ to see what security holes you might be leaving open.
|
||||
|
||||
.. _OWASP ZAP: https://www.owasp.org/index.php/OWASP_Zed_Attack_Proxy_Project
|
|
@ -0,0 +1,26 @@
|
|||
.. Heima documentation master file, created by
|
||||
sphinx-quickstart.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to Heima's documentation!
|
||||
====================================================================
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
install
|
||||
deploy
|
||||
docker_ec2
|
||||
tests
|
||||
|
||||
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
|
@ -0,0 +1,4 @@
|
|||
Install
|
||||
=========
|
||||
|
||||
This is where you write how to get a new laptop to run this project.
|
|
@ -0,0 +1,190 @@
|
|||
@ECHO OFF
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set BUILDDIR=_build
|
||||
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
|
||||
set I18NSPHINXOPTS=%SPHINXOPTS% .
|
||||
if NOT "%PAPER%" == "" (
|
||||
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
if "%1" == "help" (
|
||||
:help
|
||||
echo.Please use `make ^<target^>` where ^<target^> is one of
|
||||
echo. html to make standalone HTML files
|
||||
echo. dirhtml to make HTML files named index.html in directories
|
||||
echo. singlehtml to make a single large HTML file
|
||||
echo. pickle to make pickle files
|
||||
echo. json to make JSON files
|
||||
echo. htmlhelp to make HTML files and a HTML help project
|
||||
echo. qthelp to make HTML files and a qthelp project
|
||||
echo. devhelp to make HTML files and a Devhelp project
|
||||
echo. epub to make an epub
|
||||
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
|
||||
echo. text to make text files
|
||||
echo. man to make manual pages
|
||||
echo. texinfo to make Texinfo files
|
||||
echo. gettext to make PO message catalogs
|
||||
echo. changes to make an overview over all changed/added/deprecated items
|
||||
echo. linkcheck to check all external links for integrity
|
||||
echo. doctest to run all doctests embedded in the documentation if enabled
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "clean" (
|
||||
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
|
||||
del /q /s %BUILDDIR%\*
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "html" (
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "dirhtml" (
|
||||
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "singlehtml" (
|
||||
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pickle" (
|
||||
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the pickle files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "json" (
|
||||
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the JSON files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "htmlhelp" (
|
||||
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run HTML Help Workshop with the ^
|
||||
.hhp project file in %BUILDDIR%/htmlhelp.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "qthelp" (
|
||||
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\heima.qhcp
|
||||
echo.To view the help file:
|
||||
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\heima.ghc
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "devhelp" (
|
||||
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "epub" (
|
||||
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The epub file is in %BUILDDIR%/epub.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latex" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "text" (
|
||||
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The text files are in %BUILDDIR%/text.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "man" (
|
||||
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The manual pages are in %BUILDDIR%/man.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "texinfo" (
|
||||
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "gettext" (
|
||||
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "changes" (
|
||||
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.The overview file is in %BUILDDIR%/changes.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "linkcheck" (
|
||||
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Link check complete; look for any errors in the above output ^
|
||||
or in %BUILDDIR%/linkcheck/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "doctest" (
|
||||
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Testing of doctests in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/doctest/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
:end
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
# PostgreSQL
|
||||
POSTGRES_PASSWORD=mysecretpass
|
||||
POSTGRES_USER=postgresuser
|
||||
|
||||
# General settings
|
||||
# DJANGO_READ_DOT_ENV_FILE=True
|
||||
DJANGO_ADMIN_URL=
|
||||
DJANGO_SETTINGS_MODULE=config.settings.production
|
||||
DJANGO_SECRET_KEY=cc@lv^y0m4(m7&)0zmvv^@lp@v*=liv)s@wiy+1tf2s30bjng%
|
||||
DJANGO_ALLOWED_HOSTS=.heima.grimbox.be
|
||||
|
||||
# AWS Settings
|
||||
DJANGO_AWS_ACCESS_KEY_ID=
|
||||
DJANGO_AWS_SECRET_ACCESS_KEY=
|
||||
DJANGO_AWS_STORAGE_BUCKET_NAME=
|
||||
|
||||
# Used with email
|
||||
DJANGO_MAILGUN_API_KEY=
|
||||
DJANGO_SERVER_EMAIL=
|
||||
MAILGUN_SENDER_DOMAIN=
|
||||
|
||||
# Security! Better to use DNS for this task, but you can use redirect
|
||||
DJANGO_SECURE_SSL_REDIRECT=False
|
||||
|
||||
# django-allauth
|
||||
DJANGO_ACCOUNT_ALLOW_REGISTRATION=True
|
||||
# Sentry
|
||||
DJANGO_SENTRY_DSN=
|
||||
|
||||
DJANGO_OPBEAT_ORGANIZATION_ID
|
||||
DJANGO_OPBEAT_APP_ID
|
||||
DJANGO_OPBEAT_SECRET_TOKEN
|
||||
|
||||
COMPRESS_ENABLED=
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
|
||||
////////////////////////////////
|
||||
//Setup//
|
||||
////////////////////////////////
|
||||
|
||||
// Plugins
|
||||
var gulp = require('gulp'),
|
||||
pjson = require('./package.json'),
|
||||
gutil = require('gulp-util'),
|
||||
sass = require('gulp-sass'),
|
||||
autoprefixer = require('gulp-autoprefixer'),
|
||||
cssnano = require('gulp-cssnano'),
|
||||
rename = require('gulp-rename'),
|
||||
del = require('del'),
|
||||
plumber = require('gulp-plumber'),
|
||||
pixrem = require('gulp-pixrem'),
|
||||
uglify = require('gulp-uglify'),
|
||||
imagemin = require('gulp-imagemin'),
|
||||
exec = require('child_process').exec,
|
||||
runSequence = require('run-sequence'),
|
||||
browserSync = require('browser-sync').create(),
|
||||
reload = browserSync.reload;
|
||||
|
||||
|
||||
// Relative paths function
|
||||
var pathsConfig = function (appName) {
|
||||
this.app = "./" + (appName || pjson.name);
|
||||
|
||||
return {
|
||||
app: this.app,
|
||||
templates: this.app + '/templates',
|
||||
css: this.app + '/static/css',
|
||||
sass: this.app + '/static/sass',
|
||||
fonts: this.app + '/static/fonts',
|
||||
images: this.app + '/static/images',
|
||||
js: this.app + '/static/js',
|
||||
}
|
||||
};
|
||||
|
||||
var paths = pathsConfig();
|
||||
|
||||
////////////////////////////////
|
||||
//Tasks//
|
||||
////////////////////////////////
|
||||
|
||||
// Styles autoprefixing and minification
|
||||
gulp.task('styles', function() {
|
||||
return gulp.src(paths.sass + '/project.scss')
|
||||
.pipe(sass().on('error', sass.logError))
|
||||
.pipe(plumber()) // Checks for errors
|
||||
.pipe(autoprefixer({browsers: ['last 2 version']})) // Adds vendor prefixes
|
||||
.pipe(pixrem()) // add fallbacks for rem units
|
||||
.pipe(gulp.dest(paths.css))
|
||||
.pipe(rename({ suffix: '.min' }))
|
||||
.pipe(cssnano()) // Minifies the result
|
||||
.pipe(gulp.dest(paths.css));
|
||||
});
|
||||
|
||||
// Javascript minification
|
||||
gulp.task('scripts', function() {
|
||||
return gulp.src(paths.js + '/project.js')
|
||||
.pipe(plumber()) // Checks for errors
|
||||
.pipe(uglify()) // Minifies the js
|
||||
.pipe(rename({ suffix: '.min' }))
|
||||
.pipe(gulp.dest(paths.js));
|
||||
});
|
||||
|
||||
// Image compression
|
||||
gulp.task('imgCompression', function(){
|
||||
return gulp.src(paths.images + '/*')
|
||||
.pipe(imagemin()) // Compresses PNG, JPEG, GIF and SVG images
|
||||
.pipe(gulp.dest(paths.images))
|
||||
});
|
||||
|
||||
// Run django server
|
||||
gulp.task('runServer', function() {
|
||||
exec('python manage.py runserver', function (err, stdout, stderr) {
|
||||
console.log(stdout);
|
||||
console.log(stderr);
|
||||
});
|
||||
});
|
||||
|
||||
// Browser sync server for live reload
|
||||
gulp.task('browserSync', function() {
|
||||
browserSync.init(
|
||||
[paths.css + "/*.css", paths.js + "*.js", paths.templates + '*.html'], {
|
||||
proxy: "localhost:8000"
|
||||
});
|
||||
});
|
||||
|
||||
// Default task
|
||||
gulp.task('default', function() {
|
||||
runSequence(['styles', 'scripts', 'imgCompression'], 'runServer', 'browserSync');
|
||||
});
|
||||
|
||||
////////////////////////////////
|
||||
//Watch//
|
||||
////////////////////////////////
|
||||
|
||||
// Watch
|
||||
gulp.task('watch', ['default'], function() {
|
||||
|
||||
gulp.watch(paths.sass + '/*.scss', ['styles']);
|
||||
gulp.watch(paths.js + '/*.js', ['scripts']).on("change", reload);
|
||||
gulp.watch(paths.images + '/*', ['imgCompression']);
|
||||
gulp.watch(paths.templates + '/**/*.html').on("change", reload);
|
||||
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
__version__ = '0.1.0'
|
||||
__version_info__ = tuple([int(num) if num.isdigit() else num for num in __version__.replace('-', '.', 1).split('.')])
|
|
@ -0,0 +1,6 @@
|
|||
"""
|
||||
To understand why this file is here, please read:
|
||||
|
||||
http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
|
||||
"""
|
||||
# -*- coding: utf-8 -*-
|
|
@ -0,0 +1,6 @@
|
|||
"""
|
||||
To understand why this file is here, please read:
|
||||
|
||||
http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
|
||||
"""
|
||||
# -*- coding: utf-8 -*-
|
|
@ -0,0 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django.contrib.sites.models
|
||||
from django.contrib.sites.models import _simple_domain_name_validator
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Site',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('domain', models.CharField(
|
||||
max_length=100, verbose_name='domain name', validators=[_simple_domain_name_validator]
|
||||
)),
|
||||
('name', models.CharField(max_length=50, verbose_name='display name')),
|
||||
],
|
||||
options={
|
||||
'ordering': ('domain',),
|
||||
'db_table': 'django_site',
|
||||
'verbose_name': 'site',
|
||||
'verbose_name_plural': 'sites',
|
||||
},
|
||||
bases=(models.Model,),
|
||||
managers=[
|
||||
('objects', django.contrib.sites.models.SiteManager()),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -0,0 +1,23 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django.contrib.sites.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sites', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='site',
|
||||
name='domain',
|
||||
field=models.CharField(
|
||||
max_length=100, unique=True, validators=[django.contrib.sites.models._simple_domain_name_validator],
|
||||
verbose_name='domain name'
|
||||
),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,46 @@
|
|||
"""
|
||||
To understand why this file is here, please read:
|
||||
|
||||
http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
|
||||
"""
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def update_site_forward(apps, schema_editor):
|
||||
"""Set site domain and name."""
|
||||
Site = apps.get_model('sites', 'Site')
|
||||
Site.objects.update_or_create(
|
||||
id=settings.SITE_ID,
|
||||
defaults={
|
||||
'domain': 'heima.grimbox.be',
|
||||
'name': 'Heima'
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def update_site_backward(apps, schema_editor):
|
||||
"""Revert site domain and name to default."""
|
||||
Site = apps.get_model('sites', 'Site')
|
||||
Site.objects.update_or_create(
|
||||
id=settings.SITE_ID,
|
||||
defaults={
|
||||
'domain': 'example.com',
|
||||
'name': 'example.com'
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sites', '0002_alter_domain_unique'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(update_site_forward, update_site_backward),
|
||||
]
|
|
@ -0,0 +1,6 @@
|
|||
"""
|
||||
To understand why this file is here, please read:
|
||||
|
||||
http://cookiecutter-django.readthedocs.io/en/latest/faq.html#why-is-there-a-django-contrib-sites-directory-in-cookiecutter-django
|
||||
"""
|
||||
# -*- coding: utf-8 -*-
|
|
@ -0,0 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-02-09 19:44
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('sherlock', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='gauge',
|
||||
options={'ordering': ['category']},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name='mesure',
|
||||
options={'ordering': ('-moment',)},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='mesure',
|
||||
name='gauge',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='mesures', to='sherlock.Gauge'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,38 @@
|
|||
/* These styles are generated from project.scss. */
|
||||
|
||||
.alert-debug {
|
||||
color: black;
|
||||
background-color: white;
|
||||
border-color: #d6e9c6;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
color: #b94a48;
|
||||
background-color: #f2dede;
|
||||
border-color: #eed3d7;
|
||||
}
|
||||
|
||||
/* This is a fix for the bootstrap4 alpha release */
|
||||
@media (max-width: 47.9em) {
|
||||
.navbar-nav .nav-item {
|
||||
float: none;
|
||||
width: 100%;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.navbar-nav .nav-item + .nav-item {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.nav.navbar-nav.pull-xs-right {
|
||||
float: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* Display django-debug-toolbar.
|
||||
See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742
|
||||
and https://github.com/pydanny/cookiecutter-django/issues/317
|
||||
*/
|
||||
[hidden][style="display: block;"] {
|
||||
display: block !important;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
|
@ -0,0 +1,21 @@
|
|||
/* Project specific Javascript goes here. */
|
||||
|
||||
/*
|
||||
Formatting hack to get around crispy-forms unfortunate hardcoding
|
||||
in helpers.FormHelper:
|
||||
|
||||
if template_pack == 'bootstrap4':
|
||||
grid_colum_matcher = re.compile('\w*col-(xs|sm|md|lg|xl)-\d+\w*')
|
||||
using_grid_layout = (grid_colum_matcher.match(self.label_class) or
|
||||
grid_colum_matcher.match(self.field_class))
|
||||
if using_grid_layout:
|
||||
items['using_grid_layout'] = True
|
||||
|
||||
Issues with the above approach:
|
||||
|
||||
1. Fragile: Assumes Bootstrap 4's API doesn't change (it does)
|
||||
2. Unforgiving: Doesn't allow for any variation in template design
|
||||
3. Really Unforgiving: No way to override this behavior
|
||||
4. Undocumented: No mention in the documentation, or it's too hard for me to find
|
||||
*/
|
||||
$('.form-group').removeClass('row');
|
|
@ -0,0 +1,72 @@
|
|||
|
||||
// project specific CSS goes here
|
||||
|
||||
////////////////////////////////
|
||||
//Variables//
|
||||
////////////////////////////////
|
||||
|
||||
// Alert colors
|
||||
|
||||
$white: #fff;
|
||||
$mint-green: #d6e9c6;
|
||||
$black: #000;
|
||||
$pink: #f2dede;
|
||||
$dark-pink: #eed3d7;
|
||||
$red: #b94a48;
|
||||
|
||||
////////////////////////////////
|
||||
//Alerts//
|
||||
////////////////////////////////
|
||||
|
||||
// bootstrap alert CSS, translated to the django-standard levels of
|
||||
// debug, info, success, warning, error
|
||||
|
||||
.alert-debug {
|
||||
background-color: $white;
|
||||
border-color: $mint-green;
|
||||
color: $black;
|
||||
}
|
||||
|
||||
.alert-error {
|
||||
background-color: $pink;
|
||||
border-color: $dark-pink;
|
||||
color: $red;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//Navbar//
|
||||
////////////////////////////////
|
||||
|
||||
// This is a fix for the bootstrap4 alpha release
|
||||
|
||||
.navbar {
|
||||
border-radius: 0px;
|
||||
}
|
||||
|
||||
@media (max-width: 47.9em) {
|
||||
.navbar-nav .nav-item {
|
||||
display: inline-block;
|
||||
float: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.navbar-nav .nav-item + .nav-item {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.nav.navbar-nav.pull-xs-right {
|
||||
float: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//Django Toolbar//
|
||||
////////////////////////////////
|
||||
|
||||
// Display django-debug-toolbar.
|
||||
// See https://github.com/django-debug-toolbar/django-debug-toolbar/issues/742
|
||||
// and https://github.com/pydanny/cookiecutter-django/issues/317
|
||||
|
||||
[hidden][style="display: block;"] {
|
||||
display: block !important;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Forbidden (403){% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Forbidden (403)</h1>
|
||||
|
||||
<p>CSRF verification failed. Request aborted.</p>
|
||||
{% endblock content %}
|
|
@ -0,0 +1,9 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Page Not found{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Page Not found</h1>
|
||||
|
||||
<p>This is not the page you were looking for.</p>
|
||||
{% endblock content %}
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Server Error{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Ooops!!! 500</h1>
|
||||
|
||||
<h3>Looks like something went wrong!</h3>
|
||||
|
||||
<p>We track these errors automatically, but if the problem persists feel free to contact us. In the meantime, try refreshing.</p>
|
||||
{% endblock content %}
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block head_title %}{% trans "Account Inactive" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Account Inactive" %}</h1>
|
||||
|
||||
<p>{% trans "This account is inactive." %}</p>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}{% block head_title %}{% endblock head_title %}{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-md-6 offset-md-3">
|
||||
{% block inner %}{% endblock %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -0,0 +1,80 @@
|
|||
|
||||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block head_title %}{% trans "Account" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "E-mail Addresses" %}</h1>
|
||||
|
||||
{% if user.emailaddress_set.all %}
|
||||
<p>{% trans 'The following e-mail addresses are associated with your account:' %}</p>
|
||||
|
||||
<form action="{% url 'account_email' %}" class="email_list" method="post">
|
||||
{% csrf_token %}
|
||||
<fieldset class="blockLabels">
|
||||
|
||||
{% for emailaddress in user.emailaddress_set.all %}
|
||||
<div class="radio">
|
||||
<label for="email_radio_{{forloop.counter}}" class="{% if emailaddress.primary %}primary_email{%endif%}">
|
||||
|
||||
<input id="email_radio_{{forloop.counter}}" type="radio" name="email" {% if emailaddress.primary or user.emailaddress_set.count == 1 %}checked="checked"{%endif %} value="{{emailaddress.email}}"/>
|
||||
|
||||
{{ emailaddress.email }}
|
||||
{% if emailaddress.verified %}
|
||||
<span class="verified">{% trans "Verified" %}</span>
|
||||
{% else %}
|
||||
<span class="unverified">{% trans "Unverified" %}</span>
|
||||
{% endif %}
|
||||
{% if emailaddress.primary %}<span class="primary">{% trans "Primary" %}</span>{% endif %}
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="form-group">
|
||||
<button class="secondaryAction btn btn-primary" type="submit" name="action_primary" >{% trans 'Make Primary' %}</button>
|
||||
<button class="secondaryAction btn btn-primary" type="submit" name="action_send" >{% trans 'Re-send Verification' %}</button>
|
||||
<button class="primaryAction btn btn-primary" type="submit" name="action_remove" >{% trans 'Remove' %}</button>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
{% else %}
|
||||
<p><strong>{% trans 'Warning:'%}</strong> {% trans "You currently do not have any e-mail address set up. You should really add an e-mail address so you can receive notifications, reset your password, etc." %}</p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
<h2>{% trans "Add E-mail Address" %}</h2>
|
||||
|
||||
<form method="post" action="{% url 'account_email' %}" class="add_email">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<button class="btn btn-primary" name="action_add" type="submit">{% trans "Add E-mail" %}</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
{% block javascript %}
|
||||
{{ block.super }}
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var message = "{% trans 'Do you really want to remove the selected e-mail address?' %}";
|
||||
var actions = document.getElementsByName('action_remove');
|
||||
if (actions.length) {
|
||||
actions[0].addEventListener("click", function(e) {
|
||||
if (! confirm(message)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
$('.form-group').removeClass('row');
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load account %}
|
||||
|
||||
{% block head_title %}{% trans "Confirm E-mail Address" %}{% endblock %}
|
||||
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Confirm E-mail Address" %}</h1>
|
||||
|
||||
{% if confirmation %}
|
||||
|
||||
{% user_display confirmation.email_address.user as user_display %}
|
||||
|
||||
<p>{% blocktrans with confirmation.email_address.email as email %}Please confirm that <a href="mailto:{{ email }}">{{ email }}</a> is an e-mail address for user {{ user_display }}.{% endblocktrans %}</p>
|
||||
|
||||
<form method="post" action="{% url 'account_confirm_email' confirmation.key %}">
|
||||
{% csrf_token %}
|
||||
<button class="btn btn-primary" type="submit">{% trans 'Confirm' %}</button>
|
||||
</form>
|
||||
|
||||
{% else %}
|
||||
|
||||
{% url 'account_email' as email_url %}
|
||||
|
||||
<p>{% blocktrans %}This e-mail confirmation link expired or is invalid. Please <a href="{{ email_url }}">issue a new e-mail confirmation request</a>.{% endblocktrans %}</p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load account socialaccount %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block head_title %}{% trans "Sign In" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
|
||||
<h1>{% trans "Sign In" %}</h1>
|
||||
|
||||
{% get_providers as socialaccount_providers %}
|
||||
|
||||
{% if socialaccount_providers %}
|
||||
<p>{% blocktrans with site.name as site_name %}Please sign in with one
|
||||
of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
|
||||
for a {{ site_name }} account and sign in below:{% endblocktrans %}</p>
|
||||
|
||||
<div class="socialaccount_ballot">
|
||||
|
||||
<ul class="socialaccount_providers">
|
||||
{% include "socialaccount/snippets/provider_list.html" with process="login" %}
|
||||
</ul>
|
||||
|
||||
<div class="login-or">{% trans 'or' %}</div>
|
||||
|
||||
</div>
|
||||
|
||||
{% include "socialaccount/snippets/login_extra.html" %}
|
||||
|
||||
{% else %}
|
||||
<p>{% blocktrans %}If you have not created an account yet, then please
|
||||
<a href="{{ signup_url }}">sign up</a> first.{% endblocktrans %}</p>
|
||||
{% endif %}
|
||||
|
||||
<form class="login" method="POST" action="{% url 'account_login' %}">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
{% if redirect_field_value %}
|
||||
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
|
||||
{% endif %}
|
||||
<a class="button secondaryAction" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
|
||||
<button class="primaryAction btn btn-primary" type="submit">{% trans "Sign In" %}</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block head_title %}{% trans "Sign Out" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Sign Out" %}</h1>
|
||||
|
||||
<p>{% trans 'Are you sure you want to sign out?' %}</p>
|
||||
|
||||
<form method="post" action="{% url 'account_logout' %}">
|
||||
{% csrf_token %}
|
||||
{% if redirect_field_value %}
|
||||
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
|
||||
{% endif %}
|
||||
<button class="btn btn-danger" type="submit">{% trans 'Sign Out' %}</button>
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block head_title %}{% trans "Change Password" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Change Password" %}</h1>
|
||||
|
||||
<form method="POST" action="{% url 'account_change_password' %}" class="password_change">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<button class="btn btn-primary" type="submit" name="action">{% trans "Change Password" %}</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load account %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block head_title %}{% trans "Password Reset" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
|
||||
<h1>{% trans "Password Reset" %}</h1>
|
||||
{% if user.is_authenticated %}
|
||||
{% include "account/snippets/already_logged_in.html" %}
|
||||
{% endif %}
|
||||
|
||||
<p>{% trans "Forgotten your password? Enter your e-mail address below, and we'll send you an e-mail allowing you to reset it." %}</p>
|
||||
|
||||
<form method="POST" action="{% url 'account_reset_password' %}" class="password_reset">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="{% trans 'Reset My Password' %}" />
|
||||
</form>
|
||||
|
||||
<p>{% blocktrans %}Please contact us if you have any trouble resetting your password.{% endblocktrans %}</p>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load account %}
|
||||
|
||||
{% block head_title %}{% trans "Password Reset" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Password Reset" %}</h1>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
{% include "account/snippets/already_logged_in.html" %}
|
||||
{% endif %}
|
||||
|
||||
<p>{% blocktrans %}We have sent you an e-mail. Please contact us if you do not receive it within a few minutes.{% endblocktrans %}</p>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% block head_title %}{% trans "Change Password" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% if token_fail %}{% trans "Bad Token" %}{% else %}{% trans "Change Password" %}{% endif %}</h1>
|
||||
|
||||
{% if token_fail %}
|
||||
{% url 'account_reset_password' as passwd_reset_url %}
|
||||
<p>{% blocktrans %}The password reset link was invalid, possibly because it has already been used. Please request a <a href="{{ passwd_reset_url }}">new password reset</a>.{% endblocktrans %}</p>
|
||||
{% else %}
|
||||
{% if form %}
|
||||
<form method="POST" action=".">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" name="action" value="{% trans 'change password' %}"/>
|
||||
</form>
|
||||
{% else %}
|
||||
<p>{% trans 'Your password is now changed.' %}</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% block head_title %}{% trans "Change Password" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Change Password" %}</h1>
|
||||
<p>{% trans 'Your password is now changed.' %}</p>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block head_title %}{% trans "Set Password" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Set Password" %}</h1>
|
||||
|
||||
<form method="POST" action="{% url 'account_set_password' %}" class="password_set">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" name="action" value="{% trans 'Set Password' %}"/>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block head_title %}{% trans "Signup" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Sign Up" %}</h1>
|
||||
|
||||
<p>{% blocktrans %}Already have an account? Then please <a href="{{ login_url }}">sign in</a>.{% endblocktrans %}</p>
|
||||
|
||||
<form class="signup" id="signup_form" method="post" action="{% url 'account_signup' %}">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
{% if redirect_field_value %}
|
||||
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}" />
|
||||
{% endif %}
|
||||
<button class="btn btn-primary" type="submit">{% trans "Sign Up" %} »</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block head_title %}{% trans "Sign Up Closed" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Sign Up Closed" %}</h1>
|
||||
|
||||
<p>{% trans "We are sorry, but the sign up is currently closed." %}</p>
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block head_title %}{% trans "Verify Your E-mail Address" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Verify Your E-mail Address" %}</h1>
|
||||
|
||||
<p>{% blocktrans %}We have sent an e-mail to you for verification. Follow the link provided to finalize the signup process. Please contact us if you do not receive it within a few minutes.{% endblocktrans %}</p>
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
{% extends "account/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block head_title %}{% trans "Verify Your E-mail Address" %}{% endblock %}
|
||||
|
||||
{% block inner %}
|
||||
<h1>{% trans "Verify Your E-mail Address" %}</h1>
|
||||
|
||||
{% url 'account_email' as email_url %}
|
||||
|
||||
<p>{% blocktrans %}This part of the site requires us to verify that
|
||||
you are who you claim to be. For this purpose, we require that you
|
||||
verify ownership of your e-mail address. {% endblocktrans %}</p>
|
||||
|
||||
<p>{% blocktrans %}We have sent an e-mail to you for
|
||||
verification. Please click on the link inside this e-mail. Please
|
||||
contact us if you do not receive it within a few minutes.{% endblocktrans %}</p>
|
||||
|
||||
<p>{% blocktrans %}<strong>Note:</strong> you can still <a href="{{ email_url }}">change your e-mail address</a>.{% endblocktrans %}</p>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
{% load staticfiles i18n compress%}<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
<title>{% block title %}Heima{% endblock title %}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
||||
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
{% block css %}
|
||||
<!-- Latest compiled and minified Bootstrap 4 Alpha 4 CSS -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css" integrity="sha384-2hfp1SzUoho7/TsGGGDaFdsuuDL0LX2hnUp6VkX3CUQ2K4K+xjboZdsXyp4oUHZj" crossorigin="anonymous">
|
||||
|
||||
<!-- Your stuff: Third-party CSS libraries go here -->
|
||||
{% compress css %}
|
||||
<!-- This file stores project-specific CSS -->
|
||||
<link href="{% static 'css/project.css' %}" rel="stylesheet">
|
||||
{% endcompress %}
|
||||
{% endblock %}
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="m-b-1">
|
||||
<nav class="navbar navbar-dark navbar-static-top bg-inverse">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/">Heima</a>
|
||||
<button type="button" class="navbar-toggler hidden-sm-up pull-xs-right" data-toggle="collapse" data-target="#bs-navbar-collapse-1">
|
||||
☰
|
||||
</button>
|
||||
|
||||
<!-- Collect the nav links, forms, and other content for toggling -->
|
||||
<div class="collapse navbar-toggleable-xs" id="bs-navbar-collapse-1">
|
||||
<ul class="nav navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'home' %}">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'about' %}">About</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="nav navbar-nav pull-xs-right">
|
||||
{% if request.user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'users:detail' request.user.username %}">{% trans "My Profile" %}</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'account_logout' %}">{% trans "Sign Out" %}</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a id="sign-up-link" class="nav-link" href="{% url 'account_signup' %}">{% trans "Sign Up" %}</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a id="log-in-link" class="nav-link" href="{% url 'account_login' %}">{% trans "Sign In" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert {% if message.tags %}alert-{{ message.tags }}{% endif %}">{{ message }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% block content %}
|
||||
<p>Use this document as a way to quick start any new project.</p>
|
||||
{% endblock content %}
|
||||
|
||||
</div> <!-- /container -->
|
||||
|
||||
{% block modal %}{% endblock modal %}
|
||||
|
||||
<!-- Le javascript
|
||||
================================================== -->
|
||||
<!-- Placed at the end of the document so the pages load faster -->
|
||||
{% block javascript %}
|
||||
<!-- Required by Bootstrap v4 Alpha 4 -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/js/bootstrap.min.js" integrity="sha384-VjEeINv9OSwtWFLAtmc4JCtEJXXBub00gtSnszmspDLCtC0I4z4nqz7rEFbIZLLU" crossorigin="anonymous"></script>
|
||||
|
||||
<!-- Your stuff: Third-party javascript libraries go here -->
|
||||
|
||||
<!-- place project specific Javascript in this file -->
|
||||
{% compress js %}
|
||||
<script src="{% static 'js/project.js' %}"></script>
|
||||
{% endcompress %}
|
||||
|
||||
{% endblock javascript %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
{% load crispy_forms_field %}
|
||||
|
||||
{% if field.is_hidden %}
|
||||
{{ field }}
|
||||
{% else %}
|
||||
{% if field|is_checkbox %}
|
||||
<div class="form-group{% if using_grid_layout %} row{% endif %}">
|
||||
{% if label_class %}
|
||||
<div class="controls col-{{ bootstrap_device_type }}-offset-{{ label_size }} {{ field_class }}">
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" {% if not field|is_checkbox %}class="form-group{% if using_grid_layout %} row{% endif %}{% else %}class="checkbox{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if form_show_errors%}{% if field.errors %} has-danger{% endif %}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
|
||||
{% if field.label and not field|is_checkbox and form_show_labels %}
|
||||
<label for="{{ field.id_for_label }}" class="form-control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}">
|
||||
{{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %}
|
||||
</label>
|
||||
{% endif %}
|
||||
|
||||
{% if field|is_checkboxselectmultiple %}
|
||||
{% include 'bootstrap4/layout/checkboxselectmultiple.html' %}
|
||||
{% endif %}
|
||||
|
||||
{% if field|is_radioselect %}
|
||||
{% include 'bootstrap4/layout/radioselect.html' %}
|
||||
{% endif %}
|
||||
|
||||
{% if not field|is_checkboxselectmultiple and not field|is_radioselect %}
|
||||
{% if field|is_checkbox and form_show_labels %}
|
||||
<label for="{{ field.id_for_label }}" class="{% if field.field.required %} requiredField{% endif %}">
|
||||
{% crispy_field field %}
|
||||
{{ field.label|safe }}
|
||||
{% include 'bootstrap4/layout/help_text_and_errors.html' %}
|
||||
</label>
|
||||
{% else %}
|
||||
<div class="{{ field_class }}">
|
||||
{% crispy_field field %}
|
||||
</div>
|
||||
{% include 'bootstrap4/layout/help_text_and_errors.html' %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</{% if tag %}{{ tag }}{% else %}div{% endif %}>
|
||||
{% if field|is_checkbox %}
|
||||
{% if label_class %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
{% if form_show_errors and field.errors %}
|
||||
{% for error in field.errors %}
|
||||
<p id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="text-danger help-block">{{ error }}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{% extends "base.html" %}
|
|
@ -0,0 +1 @@
|
|||
{% extends "base.html" %}
|
|
@ -0,0 +1,36 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}User: {{ object.username }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
|
||||
<h2>{{ object.username }}</h2>
|
||||
{% if object.name %}
|
||||
<p>{{ object.name }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if object == request.user %}
|
||||
<!-- Action buttons -->
|
||||
<div class="row">
|
||||
|
||||
<div class="col-sm-12">
|
||||
<a class="btn btn-primary" href="{% url 'users:update' %}" role="button">My Info</a>
|
||||
<a class="btn btn-primary" href="{% url 'account_email' %}" role="button">E-Mail</a>
|
||||
<!-- Your Stuff: Custom user template urls -->
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<!-- End Action buttons -->
|
||||
{% endif %}
|
||||
|
||||
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{% extends "base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block title %}{{ user.username }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ user.username }}</h1>
|
||||
<form class="form-horizontal" method="post" action="{% url 'users:update' %}">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<button type="submit" class="btn">Update</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -0,0 +1,17 @@
|
|||
{% extends "base.html" %}
|
||||
{% load static i18n %}
|
||||
{% block title %}Members{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<h2>Users</h2>
|
||||
|
||||
<div class="list-group">
|
||||
{% for user in user_list %}
|
||||
<a href="{% url 'users:detail' user.username %}" class="list-group-item">
|
||||
<h4 class="list-group-item-heading">{{ user.username }}</h4>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
|
@ -0,0 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.conf import settings
|
||||
from allauth.account.adapter import DefaultAccountAdapter
|
||||
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
|
||||
|
||||
|
||||
class AccountAdapter(DefaultAccountAdapter):
|
||||
def is_open_for_signup(self, request):
|
||||
return getattr(settings, 'ACCOUNT_ALLOW_REGISTRATION', True)
|
||||
|
||||
|
||||
class SocialAccountAdapter(DefaultSocialAccountAdapter):
|
||||
def is_open_for_signup(self, request, sociallogin):
|
||||
return getattr(settings, 'ACCOUNT_ALLOW_REGISTRATION', True)
|
|
@ -0,0 +1,42 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
|
||||
from django.contrib.auth.forms import UserChangeForm, UserCreationForm
|
||||
from .models import User
|
||||
|
||||
|
||||
class MyUserChangeForm(UserChangeForm):
|
||||
class Meta(UserChangeForm.Meta):
|
||||
model = User
|
||||
|
||||
|
||||
class MyUserCreationForm(UserCreationForm):
|
||||
|
||||
error_message = UserCreationForm.error_messages.update({
|
||||
'duplicate_username': 'This username has already been taken.'
|
||||
})
|
||||
|
||||
class Meta(UserCreationForm.Meta):
|
||||
model = User
|
||||
|
||||
def clean_username(self):
|
||||
username = self.cleaned_data["username"]
|
||||
try:
|
||||
User.objects.get(username=username)
|
||||
except User.DoesNotExist:
|
||||
return username
|
||||
raise forms.ValidationError(self.error_messages['duplicate_username'])
|
||||
|
||||
|
||||
@admin.register(User)
|
||||
class MyUserAdmin(AuthUserAdmin):
|
||||
form = MyUserChangeForm
|
||||
add_form = MyUserCreationForm
|
||||
fieldsets = (
|
||||
('User Profile', {'fields': ('name',)}),
|
||||
) + AuthUserAdmin.fieldsets
|
||||
list_display = ('username', 'name', 'is_superuser')
|
||||
search_fields = ['name']
|
|
@ -0,0 +1,13 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UsersConfig(AppConfig):
|
||||
name = 'heima.users'
|
||||
verbose_name = "Users"
|
||||
|
||||
def ready(self):
|
||||
"""Override this to put in:
|
||||
Users system checks
|
||||
Users signal registration
|
||||
"""
|
||||
pass
|
|
@ -0,0 +1,47 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.1 on 2016-09-23 04:36
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django.contrib.auth.models
|
||||
import django.contrib.auth.validators
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('auth', '0008_alter_user_username_max_length'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='User',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('password', models.CharField(max_length=128, verbose_name='password')),
|
||||
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
|
||||
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
|
||||
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
|
||||
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
|
||||
('last_name', models.CharField(blank=True, max_length=30, verbose_name='last name')),
|
||||
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
|
||||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||
('name', models.CharField(blank=True, max_length=255, verbose_name='Name of User')),
|
||||
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
|
||||
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'users',
|
||||
'verbose_name': 'user',
|
||||
'abstract': False,
|
||||
},
|
||||
managers=[
|
||||
('objects', django.contrib.auth.models.UserManager()),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class User(AbstractUser):
|
||||
|
||||
# First Name and Last Name do not cover name patterns
|
||||
# around the globe.
|
||||
name = models.CharField(_('Name of User'), blank=True, max_length=255)
|
||||
|
||||
def __str__(self):
|
||||
return self.username
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('users:detail', kwargs={'username': self.username})
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue