From 2d0f8eeaa35b33969071ce15f4b25f735913d7a2 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 16:44:26 +0100 Subject: [PATCH 01/13] Setup ready for Heroku --- Procfile | 1 + PyRIGS/settings.py | 28 +++++++--------------------- PyRIGS/wsgi.py | 8 +++----- 3 files changed, 11 insertions(+), 26 deletions(-) create mode 100644 Procfile diff --git a/Procfile b/Procfile new file mode 100644 index 00000000..e6088524 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn PyRIGS.wsgi --log-file - diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 8c6d78b6..415dfb91 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -10,7 +10,9 @@ https://docs.djangoproject.com/en/1.7/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + +SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ @@ -19,13 +21,13 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__)) SECRET_KEY = 'gxhy(a#5mhp289_=6xx$7jh=eh$ymxg^ymc+di*0c*geiu3p_e' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False TEMPLATE_DEBUG = True ALLOWED_HOSTS = ['*'] -INTERNAL_IPS = ['127.0.0.1', '10.20.30.20'] +INTERNAL_IPS = ['127.0.0.1'] # Application definition @@ -63,24 +65,8 @@ WSGI_APPLICATION = 'PyRIGS.wsgi.application' # Database # https://docs.djangoproject.com/en/1.7/ref/settings/#databases -try: - import pymysql - pymysql.install_as_MySQLdb() -except ImportError: - pass -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - }, - 'legacy': { - 'ENGINE': 'django.db.backends.mysql', - 'HOST': 'alfie.codedinternet.com', - 'NAME': 'tec_rigs', - 'USER': 'tec_rigs', - 'PASSWORD': 'xMNb(b+Giu]&', - } -} +import dj_database_url +DATABASES['default'] = dj_database_url.config() # User system AUTH_USER_MODEL = 'RIGS.Profile' diff --git a/PyRIGS/wsgi.py b/PyRIGS/wsgi.py index ae436d87..7fa79ab0 100644 --- a/PyRIGS/wsgi.py +++ b/PyRIGS/wsgi.py @@ -6,9 +6,7 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ """ - -import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PyRIGS.settings") - from django.core.wsgi import get_wsgi_application -application = get_wsgi_application() +from dj_static import Cling + +application = Cling(get_wsgi_application()) From 70138111451a3485f1600c42aeee6465e716f692 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 16:59:50 +0100 Subject: [PATCH 02/13] Readd settings line --- PyRIGS/wsgi.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/PyRIGS/wsgi.py b/PyRIGS/wsgi.py index 7fa79ab0..482f3921 100644 --- a/PyRIGS/wsgi.py +++ b/PyRIGS/wsgi.py @@ -6,6 +6,10 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ """ +import os +Add a comment to this line +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PyRIGS.settings") + from django.core.wsgi import get_wsgi_application from dj_static import Cling From 3f29520496a8a840bffbab43b3036b65017b294d Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 17:06:22 +0100 Subject: [PATCH 03/13] Fix typo --- PyRIGS/wsgi.py | 1 - 1 file changed, 1 deletion(-) diff --git a/PyRIGS/wsgi.py b/PyRIGS/wsgi.py index 482f3921..07f922a1 100644 --- a/PyRIGS/wsgi.py +++ b/PyRIGS/wsgi.py @@ -7,7 +7,6 @@ For more information on this file, see https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ """ import os -Add a comment to this line os.environ.setdefault("DJANGO_SETTINGS_MODULE", "PyRIGS.settings") from django.core.wsgi import get_wsgi_application From ece7ff45781b5c838da68a98368c026432c595f1 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 17:07:37 +0100 Subject: [PATCH 04/13] Readd definition for databases --- PyRIGS/settings.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 415dfb91..26b89031 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -65,6 +65,25 @@ WSGI_APPLICATION = 'PyRIGS.wsgi.application' # Database # https://docs.djangoproject.com/en/1.7/ref/settings/#databases +try: + import pymysql + pymysql.install_as_MySQLdb() +except ImportError: + pass +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + }, + 'legacy': { + 'ENGINE': 'django.db.backends.mysql', + 'HOST': 'alfie.codedinternet.com', + 'NAME': 'tec_rigs', + 'USER': 'tec_rigs', + 'PASSWORD': 'xMNb(b+Giu]&', + } +} + import dj_database_url DATABASES['default'] = dj_database_url.config() From 9e84588d92527c48c6431d30aafb29c81ece8cca Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 18:06:00 +0100 Subject: [PATCH 05/13] Enable debug to get everything up and running --- PyRIGS/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 26b89031..a1ca5af4 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -21,7 +21,7 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECRET_KEY = 'gxhy(a#5mhp289_=6xx$7jh=eh$ymxg^ymc+di*0c*geiu3p_e' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True TEMPLATE_DEBUG = True From d6a92d8574238947332d2101050ed783d72c20cd Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 18:09:26 +0100 Subject: [PATCH 06/13] Fix for incorrect base_dir --- PyRIGS/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index a1ca5af4..5b08b96b 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -10,7 +10,7 @@ https://docs.djangoproject.com/en/1.7/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +BASE_DIR = os.path.dirname(os.path.dirname(__file__)) SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') From 9ae4a05e365e4d6f7ced827e5a422fe070011bfe Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 18:11:07 +0100 Subject: [PATCH 07/13] Disable debug again --- PyRIGS/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 5b08b96b..b54ce340 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -21,7 +21,7 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECRET_KEY = 'gxhy(a#5mhp289_=6xx$7jh=eh$ymxg^ymc+di*0c*geiu3p_e' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False TEMPLATE_DEBUG = True From 7067853674611c15c572edcb5b7b634182044255 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 22:07:21 +0100 Subject: [PATCH 08/13] Add missing migration --- RIGS/migrations/0022_auto_20150424_2104.py | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 RIGS/migrations/0022_auto_20150424_2104.py diff --git a/RIGS/migrations/0022_auto_20150424_2104.py b/RIGS/migrations/0022_auto_20150424_2104.py new file mode 100644 index 00000000..cdc3abe0 --- /dev/null +++ b/RIGS/migrations/0022_auto_20150424_2104.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('RIGS', '0021_auto_20150420_1155'), + ] + + operations = [ + migrations.AlterField( + model_name='event', + name='collector', + field=models.CharField(max_length=255, null=True, verbose_name=b'Collected by', blank=True), + preserve_default=True, + ), + migrations.AlterField( + model_name='event', + name='purchase_order', + field=models.CharField(max_length=255, null=True, verbose_name=b'PO', blank=True), + preserve_default=True, + ), + ] From 2b53efc60cd35b7cb525f2a7eea227258c676360 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 22:36:19 +0100 Subject: [PATCH 09/13] Add updating sequences to importer. --- importer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/importer.py b/importer.py index 4362e203..c7f3c9e0 100644 --- a/importer.py +++ b/importer.py @@ -345,6 +345,7 @@ def main(): # [x.start() for x in processs] # # Wait for all processs to finish # [x.join() for x in processs] + import_users() import_people(True) import_organisations(True) @@ -354,8 +355,18 @@ def main(): import_rigs(True) import_eventitem(True) import_invoices(True) + + # Do this before doing non rigs else it gets ugly + sql = "SELECT setval(\'\"RIGS_%s_id_seq\"\', (SELECT MAX(id) FROM \"RIGS_%s\"));" % ('event', 'event') + cursor = connections['default'].cursor() + cursor.execute(sql) import_nonrigs(False) + sequences = ['profile', 'person', 'organisation', 'vatrate', 'venue', 'event', 'eventitem', 'invoice', 'payment'] + for seq in sequences: + sql = "SELECT setval(\'\"RIGS_%s_id_seq\"\', (SELECT MAX(id) FROM \"RIGS_%s\"));" % (seq, seq) + cursor = connections['default'].cursor() + cursor.execute(sql) if __name__ == "__main__": main() From 920608f6ce76a8167824466bc760ddf9e8a092ee Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 24 Apr 2015 23:07:11 +0100 Subject: [PATCH 10/13] Added login requirement to view the rigboard. --- RIGS/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RIGS/urls.py b/RIGS/urls.py index 9862ee72..dfe725c2 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -57,7 +57,7 @@ urlpatterns = patterns('', name='venue_update'), # Rigboard - url(r'^rigboard/$', rigboard.RigboardIndex.as_view(), name='rigboard'), + url(r'^rigboard/$', login_required(rigboard.RigboardIndex.as_view()), name='rigboard'), url(r'^rigboard/calendar/$', login_required()(rigboard.WebCalendar.as_view()), name='web_calendar'), url(r'^rigboard/archive/$', RedirectView.as_view(pattern_name='event_archive')), From 7711cc59b2f9e1d22eac72f35af390e2c279f445 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sat, 25 Apr 2015 00:07:22 +0100 Subject: [PATCH 11/13] Enable logging --- PyRIGS/settings.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index b54ce340..13e64dab 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -84,8 +84,43 @@ DATABASES = { } } -import dj_database_url -DATABASES['default'] = dj_database_url.config() +if not DEBUG: + import dj_database_url + DATABASES['default'] = dj_database_url.config() + +# Logging +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'verbose': { + 'format': ('%(asctime)s [%(process)d] [%(levelname)s] ' + + 'pathname=%(pathname)s lineno=%(lineno)s ' + + 'funcname=%(funcName)s %(message)s'), + 'datefmt': '%Y-%m-%d %H:%M:%S' + }, + 'simple': { + 'format': '%(levelname)s %(message)s' + } + }, + 'handlers': { + 'null': { + 'level': 'DEBUG', + 'class': 'logging.NullHandler', + }, + 'console': { + 'level': 'DEBUG', + 'class': 'logging.StreamHandler', + 'formatter': 'verbose' + } + }, + 'loggers': { + 'RIGS': { + 'handlers': ['console'], + 'level': 'INFO', + } + } +} # User system AUTH_USER_MODEL = 'RIGS.Profile' From bff95d49553121747b29dffa20348fbb3e72d750 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sat, 25 Apr 2015 00:15:36 +0100 Subject: [PATCH 12/13] Enable TLS on emails --- PyRIGS/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 13e64dab..981839ea 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -137,6 +137,7 @@ if not DEBUG or EMAILER_TEST: EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'server.techost.co.uk' EMAIL_PORT = 465 + EMAIL_USE_TLS = True EMAIL_HOST_USER = 'tec' EMAIL_HOST_PASSWORD = 's7m4R3X' DEFAULT_FROM_EMAIL = 'rigs@nottinghamtec.co.uk' From 871f5076988c48005020a371edcb9943aee9e55b Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sat, 25 Apr 2015 00:19:21 +0100 Subject: [PATCH 13/13] Actually correct SMTP settings --- PyRIGS/settings.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 981839ea..1f0c8cad 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -135,12 +135,13 @@ ACCOUNT_ACTIVATION_DAYS = 7 EMAILER_TEST = False if not DEBUG or EMAILER_TEST: EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' - EMAIL_HOST = 'server.techost.co.uk' + EMAIL_HOST = 'mail.nottinghamtec.co.uk' EMAIL_PORT = 465 - EMAIL_USE_TLS = True - EMAIL_HOST_USER = 'tec' - EMAIL_HOST_PASSWORD = 's7m4R3X' - DEFAULT_FROM_EMAIL = 'rigs@nottinghamtec.co.uk' + EMAIL_HOST_USER = 'pyrigs@nottinghamtec.co.uk' + EMAIL_HOST_PASSWORD = 'N_dF9T&dD(Th' + EMAIL_USE_TLS = False + EMAIL_USE_SSL = True + DEFAULT_FROM_EMAIL = 'pyrigs@nottinghamtec.co.uk' else: EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'