From 8d329eb71691e5e1a9969cdd56118678a424a2a9 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 20 Jun 2016 14:45:38 +0200 Subject: [PATCH 1/6] Fix migrations and create a developer script that sets necessary minimal env --- .gitignore | 1 + README.md | 3 +- dev.sh | 36 ++++++++++++++++++++++ shop/migrations/0016_auto_20160529_1122.py | 2 +- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100755 dev.sh diff --git a/.gitignore b/.gitignore index f6170ce7..eb2b9aa2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.dev .idea/ __pycache__/ db.sqlite3 diff --git a/README.md b/README.md index e81afc2e..7b218af5 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,7 @@ Features do not include: ## Quickstart - -Create a virtual environment and activate it: +Create a Python 2.7 virtual environment and activate it: $ virtualenv venv $ source venv/bin/activate diff --git a/dev.sh b/dev.sh new file mode 100755 index 00000000..67fe103a --- /dev/null +++ b/dev.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Directory of this script +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +DEV_DIR="$DIR/.dev" + +if [ ! -d "$DEV_DIR"] +then + mkdir -p "$DEV_DIR" +fi + +export MEDIA_ROOT="$DEV_DIR/media/" +export EPAY_MERCHANT_NUMBER="123" +export EPAY_MD5_SECRET="123" +export COINIFY_API_KEY="123" +export COINIFY_API_SECRET="123" +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 $@ diff --git a/shop/migrations/0016_auto_20160529_1122.py b/shop/migrations/0016_auto_20160529_1122.py index a77054ec..90d0efdb 100644 --- a/shop/migrations/0016_auto_20160529_1122.py +++ b/shop/migrations/0016_auto_20160529_1122.py @@ -16,7 +16,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='coinifycallback', name='headers', - field=django.contrib.postgres.fields.jsonb.JSONField(default=''), + field=django.contrib.postgres.fields.jsonb.JSONField(default=None), preserve_default=False, ), migrations.AddField( From c9803b22c2714497f8e51f0bbb3ca2cb5bb70a3f Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Sun, 28 Aug 2016 17:21:44 +0200 Subject: [PATCH 2/6] use development settings in dev.sh --- dev.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev.sh b/dev.sh index 67fe103a..8759c114 100755 --- a/dev.sh +++ b/dev.sh @@ -33,4 +33,4 @@ export EMAIL_USE_TLS="" export DEFAULT_FROM_EMAIL="bornhax@localhost" export ARCHIVE_EMAIL="" -python manage.py $@ +python manage.py $@ --settings=bornhack.settings.development From ef29e038b5ab6fb9464d12b3e42faabceafe0221 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 29 Aug 2016 20:43:50 +0200 Subject: [PATCH 3/6] Improve the dev commands and add SQLite support --- .env_template | 21 ++++++++++++++++++ Makefile | 8 +++---- README.md | 10 +++++++-- bornhack/settings/development.py | 27 +++++++++++++++-------- dev.sh | 37 +++++++++----------------------- 5 files changed, 61 insertions(+), 42 deletions(-) create mode 100755 .env_template diff --git a/.env_template b/.env_template new file mode 100755 index 00000000..69e16be9 --- /dev/null +++ b/.env_template @@ -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="" diff --git a/Makefile b/Makefile index 8cdba381..b1f6a9fa 100644 --- a/Makefile +++ b/Makefile @@ -3,15 +3,15 @@ SETTINGS = bornhack.settings.development all: migrate superuser run migrations: - ./manage.py makemigrations --settings=$(SETTINGS) + ./dev.sh makemigrations --settings=$(SETTINGS) migrate: - ./manage.py migrate --settings=$(SETTINGS) + ./dev.sh migrate --settings=$(SETTINGS) superuser: - ./manage.py createsuperuser --settings=$(SETTINGS) + ./dev.sh createsuperuser --settings=$(SETTINGS) run: - ./manage.py runserver --settings=$(SETTINGS) + ./dev.sh runserver --settings=$(SETTINGS) .PHONY = all migrations migrate superuser run diff --git a/README.md b/README.md index 7b218af5..5b134080 100644 --- a/README.md +++ b/README.md @@ -23,12 +23,18 @@ Copy environment file and change settings like DATABASE_URL: (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: (venv) $ ./manage.py migrate --settings=bornhack.settings.development (venv) $ ./manage.py createsuperuser --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. diff --git a/bornhack/settings/development.py b/bornhack/settings/development.py index a58764ff..3ceec81f 100644 --- a/bornhack/settings/development.py +++ b/bornhack/settings/development.py @@ -1,3 +1,4 @@ +import os from .base import * # INSTALLED_APPS += ['debug_toolbar', ] @@ -5,15 +6,23 @@ from .base import * SECRET_KEY = 'bornhack_development' DEBUG = True -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'bornhack_dev', - 'USER': 'bornhack', - 'PASSWORD': 'bornhack', - 'HOST': 'localhost', - 'PORT': 5432, +if os.environ.get('USE_SQLITE'): + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': local_dir('../.dev/dev.db'), + } + } +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' diff --git a/dev.sh b/dev.sh index 8759c114..5a89e956 100755 --- a/dev.sh +++ b/dev.sh @@ -3,34 +3,17 @@ # Directory of this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DEV_DIR="$DIR/.dev" - -if [ ! -d "$DEV_DIR"] +if ! [ -f "$DIR/.env" ] 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 -export MEDIA_ROOT="$DEV_DIR/media/" -export EPAY_MERCHANT_NUMBER="123" -export EPAY_MD5_SECRET="123" -export COINIFY_API_KEY="123" -export COINIFY_API_SECRET="123" -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="" +if ! [ -d "$DIR/.dev" ] +then + echo "Creating .dev dir for development stuff" + mkdir -p "$DIR/.dev/media" +fi -python manage.py $@ --settings=bornhack.settings.development +python "$DIR/manage.py" $@ --settings=bornhack.settings.development From e0e5d646f67646d22db463385ed6047727e84164 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Mon, 29 Aug 2016 20:59:28 +0200 Subject: [PATCH 4/6] Fix illegal TICKET_CATEGORY_ID uuid in dev settings --- .env_template | 2 +- dev.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env_template b/.env_template index 69e16be9..15174ce8 100755 --- a/.env_template +++ b/.env_template @@ -9,7 +9,7 @@ BANKACCOUNT_IBAN="femfladeflødeboller" BANKACCOUNT_SWIFTBIC="goldmansachs" BANKACCOUNT_REG="1234" BANKACCOUNT_ACCOUNT="56789" -TICKET_CATEGORY_ID="1" +TICKET_CATEGORY_ID="304e9b44-0b48-472d-a05b-963e52614a69" SECRET_KEY="muchsecret" ALLOWED_HOSTS="127.0.0.1" EMAIL_HOST="localhost" diff --git a/dev.sh b/dev.sh index 5a89e956..7ebde8ce 100755 --- a/dev.sh +++ b/dev.sh @@ -3,7 +3,7 @@ # Directory of this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -if ! [ -f "$DIR/.env" ] +if ! [ -f "$DIR/bornhack/settings/.env" ] then echo "Creating .env file from template..." echo "MEDIA_ROOT=\"$DIR/.dev/media\"" > "$DIR/bornhack/settings/.env" From e5963cc2e6399687169f267a53901c99af1e6bfb Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Tue, 30 Aug 2016 11:33:13 +0200 Subject: [PATCH 5/6] Remove out-dated env template --- bornhack/settings/env.dist | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 bornhack/settings/env.dist diff --git a/bornhack/settings/env.dist b/bornhack/settings/env.dist deleted file mode 100644 index 81fcbba8..00000000 --- a/bornhack/settings/env.dist +++ /dev/null @@ -1,23 +0,0 @@ -DATABASE_URL=postgres://username:password@host:port/database -SECRET_KEY=somethingverysecretandunique -ALLOWED_HOSTS=localhost,127.0.0.1 -EMAIL_HOST='mailhost.example.com' -EMAIL_PORT=587 -EMAIL_HOST_USER='mymailuser' -EMAIL_HOST_PASSWORD='mymailpassword' -EMAIL_USE_TLS=True -DEFAULT_FROM_EMAIL='noreply@example.com' -ARCHIVE_EMAIL='archive@example.com' -EPAY_MERCHANT_NUMBER=something -EPAY_MD5_SECRET=something -TICKET_CATEGORY_ID='' -COINIFY_API_KEY='' -COINIFY_API_SECRET='' -COINIFY_IPN_SECRET='' -PDF_LETTERHEAD_FILENAME='' -MEDIA_ROOT='' -BANKACCOUNT_IBAN='' -BANKACCOUNT_SWIFTBIC='' -BANKACCOUNT_REG='' -BANKACCOUNT_ACCOUNT='' - From 3800b7daa4e0d9572a3acbc9215c7828c3531781 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Tue, 30 Aug 2016 11:37:38 +0200 Subject: [PATCH 6/6] Note to self: Don't assume you know, know that you know, then inform others --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5b134080..44caa25a 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ Which is equivalent with this: ### 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. +Using Postgres is only necessary for purposes of the special +[JSONField](https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/fields/). +The field is active on our shop mainly, so you can still develop things for most +parts of the site without installing Postgres. + +To use default settings and make commands, create a user `bornhack`, password +`bornhack` and database `bornhack_dev` to use default setttings.