Improve the dev commands and add SQLite support

This commit is contained in:
Benjamin Bach 2016-08-29 20:43:50 +02:00
parent c9803b22c2
commit ef29e038b5
5 changed files with 61 additions and 42 deletions

21
.env_template Executable file
View file

@ -0,0 +1,21 @@
MEDIA_ROOT="$DEV_DIR/media/"
EPAY_MERCHANT_NUMBER="123"
EPAY_MD5_SECRET="123"
COINIFY_API_KEY="123"
COINIFY_API_SECRET="123"
COINIFY_IPN_SECRET="123"
PDF_LETTERHEAD_FILENAME="bornhax.pdf"
BANKACCOUNT_IBAN="femfladeflødeboller"
BANKACCOUNT_SWIFTBIC="goldmansachs"
BANKACCOUNT_REG="1234"
BANKACCOUNT_ACCOUNT="56789"
TICKET_CATEGORY_ID="1"
SECRET_KEY="muchsecret"
ALLOWED_HOSTS="127.0.0.1"
EMAIL_HOST="localhost"
EMAIL_PORT="22"
EMAIL_HOST_USER="$USER"
EMAIL_HOST_PASSWORD=""
EMAIL_USE_TLS=""
DEFAULT_FROM_EMAIL="bornhax@localhost"
ARCHIVE_EMAIL=""

View file

@ -3,15 +3,15 @@ SETTINGS = bornhack.settings.development
all: migrate superuser run all: migrate superuser run
migrations: migrations:
./manage.py makemigrations --settings=$(SETTINGS) ./dev.sh makemigrations --settings=$(SETTINGS)
migrate: migrate:
./manage.py migrate --settings=$(SETTINGS) ./dev.sh migrate --settings=$(SETTINGS)
superuser: superuser:
./manage.py createsuperuser --settings=$(SETTINGS) ./dev.sh createsuperuser --settings=$(SETTINGS)
run: run:
./manage.py runserver --settings=$(SETTINGS) ./dev.sh runserver --settings=$(SETTINGS)
.PHONY = all migrations migrate superuser run .PHONY = all migrations migrate superuser run

View file

@ -23,12 +23,18 @@ Copy environment file and change settings like DATABASE_URL:
(venv) $ cp bornhack/settings/env.dist bornhack/settings/.env (venv) $ cp bornhack/settings/env.dist bornhack/settings/.env
Run `make` Run `make` (removing USE_SQLITE=1 if you want to use postgres)
(venv) $ make (venv) $ SQLITE=1 make
Which is equivalent with this: Which is equivalent with this:
(venv) $ ./manage.py migrate --settings=bornhack.settings.development (venv) $ ./manage.py migrate --settings=bornhack.settings.development
(venv) $ ./manage.py createsuperuser --settings=bornhack.settings.development (venv) $ ./manage.py createsuperuser --settings=bornhack.settings.development
(venv) $ ./manage.py runserver --settings=bornhack.settings.development (venv) $ ./manage.py runserver --settings=bornhack.settings.development
### Setting up Postgres
Using Postgres is only necessary for purposes og using Postgis for a few maps on the site.
To use default settings and make commands, create a user `bornhack`, password `bornhack`
and database `bornhack_dev` to use default setttings.

View file

@ -1,3 +1,4 @@
import os
from .base import * from .base import *
# INSTALLED_APPS += ['debug_toolbar', ] # INSTALLED_APPS += ['debug_toolbar', ]
@ -5,15 +6,23 @@ from .base import *
SECRET_KEY = 'bornhack_development' SECRET_KEY = 'bornhack_development'
DEBUG = True DEBUG = True
DATABASES = { if os.environ.get('USE_SQLITE'):
'default': { DATABASES = {
'ENGINE': 'django.db.backends.postgresql_psycopg2', 'default': {
'NAME': 'bornhack_dev', 'ENGINE': 'django.db.backends.sqlite3',
'USER': 'bornhack', 'NAME': local_dir('../.dev/dev.db'),
'PASSWORD': 'bornhack', }
'HOST': 'localhost', }
'PORT': 5432, else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'bornhack_dev',
'USER': 'bornhack',
'PASSWORD': 'bornhack',
'HOST': 'localhost',
'PORT': 5432,
}
} }
}
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

37
dev.sh
View file

@ -3,34 +3,17 @@
# Directory of this script # Directory of this script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DEV_DIR="$DIR/.dev" if ! [ -f "$DIR/.env" ]
if [ ! -d "$DEV_DIR"]
then then
mkdir -p "$DEV_DIR" echo "Creating .env file from template..."
echo "MEDIA_ROOT=\"$DIR/.dev/media\"" > "$DIR/bornhack/settings/.env"
cat "$DIR/.env_template" >> "$DIR/bornhack/settings/.env"
fi fi
export MEDIA_ROOT="$DEV_DIR/media/" if ! [ -d "$DIR/.dev" ]
export EPAY_MERCHANT_NUMBER="123" then
export EPAY_MD5_SECRET="123" echo "Creating .dev dir for development stuff"
export COINIFY_API_KEY="123" mkdir -p "$DIR/.dev/media"
export COINIFY_API_SECRET="123" fi
export COINIFY_IPN_SECRET="123"
export PDF_LETTERHEAD_FILENAME="bornhax.pdf"
export BANKACCOUNT_IBAN="femfladeflødeboller"
export BANKACCOUNT_SWIFTBIC="goldmansachs"
export BANKACCOUNT_REG="1234"
export BANKACCOUNT_ACCOUNT="56789"
export TICKET_CATEGORY_ID="1"
export SECRET_KEY="muchsecret"
export ALLOWED_HOSTS="127.0.0.1"
export DATABASE_URL="sqlite:///$DEV_DIR/dev.db"
export EMAIL_HOST="localhost"
export EMAIL_PORT="22"
export EMAIL_HOST_USER="$USER"
export EMAIL_HOST_PASSWORD=""
export EMAIL_USE_TLS=""
export DEFAULT_FROM_EMAIL="bornhax@localhost"
export ARCHIVE_EMAIL=""
python manage.py $@ --settings=bornhack.settings.development python "$DIR/manage.py" $@ --settings=bornhack.settings.development