diff --git a/config/__pycache__/settings.cpython-311.pyc b/config/__pycache__/settings.cpython-311.pyc
index 96bce55..6b3afbe 100644
Binary files a/config/__pycache__/settings.cpython-311.pyc and b/config/__pycache__/settings.cpython-311.pyc differ
diff --git a/config/settings.py b/config/settings.py
index 291d043..7f18fe3 100644
--- a/config/settings.py
+++ b/config/settings.py
@@ -26,6 +26,12 @@ ALLOWED_HOSTS = [
os.getenv("HOST_FQDN", ""),
]
+# Ensure Django knows it's behind a reverse proxy and using HTTPS
+SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
+USE_X_FORWARDED_HOST = True
+USE_X_FORWARDED_PORT = True
+SECURE_SSL_REDIRECT = True
+
CSRF_TRUSTED_ORIGINS = [
origin for origin in [
os.getenv("HOST_FQDN", ""),
@@ -37,14 +43,12 @@ CSRF_TRUSTED_ORIGINS = [
for host in CSRF_TRUSTED_ORIGINS
]
-# Cookies must always be HTTPS-only; SameSite=Lax keeps CSRF working behind the proxy.
+# Cookies must always be HTTPS-only
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
-SESSION_COOKIE_SAMESITE = "None"
-CSRF_COOKIE_SAMESITE = "None"
-
-# Quick-start development settings - unsuitable for production
-# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
+SESSION_COOKIE_SAMESITE = "Lax"
+CSRF_COOKIE_SAMESITE = "Lax"
+CSRF_USE_SESSIONS = True
# Application definition
@@ -65,11 +69,10 @@ MIDDLEWARE = [
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
- # Disable X-Frame-Options middleware to allow Flatlogic preview iframes.
- # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
-X_FRAME_OPTIONS = 'ALLOWALL'
+X_FRAME_OPTIONS = 'SAMEORIGIN'
ROOT_URLCONF = 'config.urls'
@@ -151,8 +154,6 @@ STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_DIRS = [
BASE_DIR / 'static',
- BASE_DIR / 'assets',
- BASE_DIR / 'node_modules',
]
# Email
@@ -180,3 +181,6 @@ if EMAIL_USE_SSL:
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
+
+LOGIN_REDIRECT_URL = 'home'
+LOGOUT_REDIRECT_URL = 'home'
\ No newline at end of file
diff --git a/core/__pycache__/context_processors.cpython-311.pyc b/core/__pycache__/context_processors.cpython-311.pyc
index 75bf223..47f7529 100644
Binary files a/core/__pycache__/context_processors.cpython-311.pyc and b/core/__pycache__/context_processors.cpython-311.pyc differ
diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc
index 5a69659..1f7e70b 100644
Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ
diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc
index 59da7bc..ad9201f 100644
Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ
diff --git a/core/context_processors.py b/core/context_processors.py
index 0bf87c3..170aeb1 100644
--- a/core/context_processors.py
+++ b/core/context_processors.py
@@ -1,6 +1,9 @@
import os
import time
+# Calculate once when the module is loaded (e.g. at server start)
+DEPLOYMENT_TIMESTAMP = int(time.time())
+
def project_context(request):
"""
Adds project-specific environment variables to the template context globally.
@@ -8,6 +11,6 @@ def project_context(request):
return {
"project_description": os.getenv("PROJECT_DESCRIPTION", ""),
"project_image_url": os.getenv("PROJECT_IMAGE_URL", ""),
- # Used for cache-busting static assets
- "deployment_timestamp": int(time.time()),
- }
+ # Used for cache-busting static assets - stable until server restart
+ "deployment_timestamp": DEPLOYMENT_TIMESTAMP,
+ }
\ No newline at end of file
diff --git a/core/management/__init__.py b/core/management/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/core/management/__pycache__/__init__.cpython-311.pyc b/core/management/__pycache__/__init__.cpython-311.pyc
new file mode 100644
index 0000000..d33437e
Binary files /dev/null and b/core/management/__pycache__/__init__.cpython-311.pyc differ
diff --git a/core/management/commands/__init__.py b/core/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/core/management/commands/__pycache__/__init__.cpython-311.pyc b/core/management/commands/__pycache__/__init__.cpython-311.pyc
new file mode 100644
index 0000000..f82327d
Binary files /dev/null and b/core/management/commands/__pycache__/__init__.cpython-311.pyc differ
diff --git a/core/management/commands/__pycache__/import_mps.cpython-311.pyc b/core/management/commands/__pycache__/import_mps.cpython-311.pyc
new file mode 100644
index 0000000..4ad4842
Binary files /dev/null and b/core/management/commands/__pycache__/import_mps.cpython-311.pyc differ
diff --git a/core/management/commands/import_mps.py b/core/management/commands/import_mps.py
new file mode 100644
index 0000000..01a1574
--- /dev/null
+++ b/core/management/commands/import_mps.py
@@ -0,0 +1,33 @@
+import csv
+from django.core.management.base import BaseCommand
+from core.models import MemberOfParliament
+
+class Command(BaseCommand):
+ help = 'Import MPs from CSV'
+
+ def handle(self, *args, **options):
+ file_path = 'mps.csv'
+ try:
+ with open(file_path, mode='r', encoding='utf-8') as file:
+ reader = csv.DictReader(file)
+ count = 0
+ for row in reader:
+ name = f"{row['First Name']} {row['Last Name']}"
+ party = row['Political Affiliation']
+ constituency = row['Constituency']
+ province = row['Province / Territory']
+
+ MemberOfParliament.objects.update_or_create(
+ name=name,
+ defaults={
+ 'party': party,
+ 'constituency': constituency,
+ 'province': province,
+ }
+ )
+ count += 1
+ self.stdout.write(self.style.SUCCESS(f'Successfully imported {count} MPs'))
+ except FileNotFoundError:
+ self.stdout.write(self.style.ERROR(f'File {file_path} not found'))
+ except Exception as e:
+ self.stdout.write(self.style.ERROR(f'Error: {str(e)}'))
diff --git a/core/templates/base.html b/core/templates/base.html
index 023dcd6..c815bce 100644
--- a/core/templates/base.html
+++ b/core/templates/base.html
@@ -14,7 +14,7 @@
{% load static %}
-
+
{% block head %}{% endblock %}
@@ -83,7 +86,7 @@