diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index fa992c5a..45866eff 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -26,21 +26,23 @@ DEBUG = env('DEBUG', cast=bool, default=True) STAGING = env('STAGING', cast=bool, default=False) CI = env('CI', cast=bool, default=False) -ALLOWED_HOSTS = ['pyrigs.nottinghamtec.co.uk', 'rigs.nottinghamtec.co.uk', 'pyrigs.herokuapp.com'] - -if STAGING: - ALLOWED_HOSTS.append('.herokuapp.com') +ALLOWED_HOSTS = ['https://pyrigs.nottinghamtec.co.uk', 'https://rigs.nottinghamtec.co.uk'] if DEBUG: - ALLOWED_HOSTS.append('localhost') - ALLOWED_HOSTS.append('example.com') - ALLOWED_HOSTS.append('127.0.0.1') - ALLOWED_HOSTS.append('.app.github.dev') - CSRF_TRUSTED_ORIGINS = ALLOWED_HOSTS + CRSF_TRUSTED_ORIGINS = ALLOWED_HOSTS.copy() + CRSF_TRUSTED_ORIGINS.append("http://localhost:8000") + CRSF_TRUSTED_ORIGINS.append("http://localhost:8001") + ALLOWED_HOSTS = ['*'] SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') if not DEBUG: SECURE_SSL_REDIRECT = True # Redirect all http requests to https + SECURE_HSTS_SECONDS = 3600 + SECURE_HSTS_INCLUDE_SUBDOMAINS = True + SECURE_CONTENT_TYPE_NOSNIFF = True + SESSION_COOKIE_SECURE = env('SESSION_COOKIE_SECURE_ENABLED', True) + CSRF_COOKIE_SECURE = env('CSRF_COOKIE_SECURE_ENABLED', True) + SECURE_HSTS_PRELOAD = True INTERNAL_IPS = ['127.0.0.1'] @@ -257,6 +259,7 @@ TEMPLATES = [ "django.template.context_processors.tz", "django.template.context_processors.request", "django.contrib.messages.context_processors.messages", + "RIGS.views.is_ajax", ], 'debug': DEBUG }, @@ -269,10 +272,3 @@ TERMS_OF_HIRE_URL = "http://www.nottinghamtec.co.uk/terms.pdf" AUTHORISATION_NOTIFICATION_ADDRESS = 'productions@nottinghamtec.co.uk' DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' - -SECURE_HSTS_SECONDS = 3600 -SECURE_HSTS_INCLUDE_SUBDOMAINS = True -SECURE_CONTENT_TYPE_NOSNIFF = True -SESSION_COOKIE_SECURE = env('SESSION_COOKIE_SECURE_ENABLED', True) -CSRF_COOKIE_SECURE = env('CSRF_COOKIE_SECURE_ENABLED', True) -SECURE_HSTS_PRELOAD = True diff --git a/PyRIGS/urls.py b/PyRIGS/urls.py index 03d42b50..a64cbab2 100644 --- a/PyRIGS/urls.py +++ b/PyRIGS/urls.py @@ -36,8 +36,8 @@ urlpatterns = [ if settings.DEBUG: urlpatterns += staticfiles_urlpatterns() - import debug_toolbar + # import debug_toolbar urlpatterns += [ - path('__debug__/', include(debug_toolbar.urls)), + # path('__debug__/', include(debug_toolbar.urls)), path('bootstrap/', TemplateView.as_view(template_name="bootstrap.html")), ] diff --git a/PyRIGS/views.py b/PyRIGS/views.py index f02da3d2..69d07f23 100644 --- a/PyRIGS/views.py +++ b/PyRIGS/views.py @@ -9,7 +9,7 @@ from functools import reduce from itertools import chain from io import BytesIO -from PyPDF2 import PdfFileMerger, PdfFileReader +from PyPDF2 import PdfMerger, PdfReader from z3c.rml import rml2pdf from django.conf import settings @@ -32,7 +32,7 @@ from training import models as training_models def is_ajax(request): - return request.headers.get('x-requested-with') == 'XMLHttpRequest' + return {"is_ajax": request.headers.get('x-requested-with') == 'XMLHttpRequest'} def get_related(form, context): # Get some other objects to include in the form. Used when there are errors but also nice and quick. @@ -333,10 +333,10 @@ def get_info_string(user): def render_pdf_response(template, context, append_terms): - merger = PdfFileMerger() + merger = PdfMerger() rml = template.render(context) buffer = rml2pdf.parseString(rml) - merger.append(PdfFileReader(buffer)) + merger.append(PdfReader(buffer)) buffer.close() if append_terms: diff --git a/RIGS/forms.py b/RIGS/forms.py index e2e62fca..5ecc3095 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -39,6 +39,8 @@ class EventForm(forms.ModelForm): @property def _get_items_json(self): items = {} + if self.instance.pk is None: + return items for item in self.instance.items.all(): data = serializers.serialize('json', [item]) struct = simplejson.loads(data) diff --git a/RIGS/signals.py b/RIGS/signals.py index b17e751c..e3642838 100644 --- a/RIGS/signals.py +++ b/RIGS/signals.py @@ -5,7 +5,7 @@ import urllib.request from io import BytesIO import datetime -from PyPDF2 import PdfFileReader, PdfFileMerger +from PyPDF2 import PdfReader, PdfMerger from django.conf import settings from django.contrib.staticfiles import finders from django.core.cache import cache @@ -31,12 +31,12 @@ def send_eventauthorisation_success_email(instance): } template = get_template('event_print.xml') - merger = PdfFileMerger() + merger = PdfMerger() rml = template.render(context) buffer = rml2pdf.parseString(rml) - merger.append(PdfFileReader(buffer)) + merger.append(PdfReader(buffer)) buffer.close() terms = urllib.request.urlopen(settings.TERMS_OF_HIRE_URL) diff --git a/RIGS/templates/email/eventauthorisation_mic_success.txt b/RIGS/templates/email/eventauthorisation_mic_success.txt index b4309dd4..43ddd5e1 100644 --- a/RIGS/templates/email/eventauthorisation_mic_success.txt +++ b/RIGS/templates/email/eventauthorisation_mic_success.txt @@ -1,5 +1,5 @@ Hi {{object.event.mic.get_full_name|default_if_none:"somebody"}}, -Just to let you know your event N{{object.eventdisplay_id}} has been successfully authorised for £{{object.amount}} by {{object.name}} as of {{object.event.last_edited_at}}. +Just to let you know your event N{{object.event.pk|stringformat:"05d"}} has been successfully authorised for £{{object.amount}} by {{object.name}} as of {{object.event.last_edited_at}}. The TEC Rig Information Gathering System diff --git a/RIGS/templates/event_detail.html b/RIGS/templates/event_detail.html index 816dee1e..4013df65 100644 --- a/RIGS/templates/event_detail.html +++ b/RIGS/templates/event_detail.html @@ -1,4 +1,4 @@ -{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %} +{% extends is_ajax|yesno:"base_ajax.html,base_rigs.html" %} {% load markdown_tags %} {% load static %} @@ -18,7 +18,7 @@ {% block content %}