Skip to content

Commit ed4aba0

Browse files
authored
Merge pull request #405 from DemocracyClub/django5-20251015
Django 5 upgrade
2 parents 2e91be6 + 4e5f138 commit ed4aba0

File tree

14 files changed

+171
-285
lines changed

14 files changed

+171
-285
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ jobs:
137137
command: |
138138
pip install --upgrade uv"==0.8.*" --quiet --no-input
139139
- run: uv sync --only-group deploy --no-python-downloads
140+
- setup_remote_docker
140141
- run: printenv DC_DEPLOY_NAME DJANGO_SETTINGS_MODULE SAM_CONFIG_FILE DC_ENVIRONMENT SAM_PUBLIC_CONFIG_ENV
141142
- run: printenv SECRET_KEY | md5sum
142143
- run: printenv AWS_ACCESS_KEY_ID | md5sum
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 4.2.25 on 2025-10-15 15:01
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("core", "0001_initial"),
9+
]
10+
11+
operations = [
12+
migrations.DeleteModel(
13+
name="Country",
14+
),
15+
migrations.DeleteModel(
16+
name="EmailAlert",
17+
),
18+
migrations.DeleteModel(
19+
name="EmailQue",
20+
),
21+
migrations.DeleteModel(
22+
name="ImageQue",
23+
),
24+
migrations.DeleteModel(
25+
name="ImageQueSeq",
26+
),
27+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.contrib.auth.mixins import AccessMixin
2+
3+
4+
class StaffuserRequiredMixin(AccessMixin):
5+
"""Require that the user is a staff member."""
6+
7+
permission_denied_message = "You must be a staff user to access this page."
8+
9+
def dispatch(self, request, *args, **kwargs):
10+
if not request.user.is_staff:
11+
return self.handle_no_permission()
12+
return super().dispatch(request, *args, **kwargs)

electionleaflets/apps/leaflets/tests/test_models.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
from copy import deepcopy
12
from pathlib import Path
23

34
import pytest
5+
from django.conf import settings
6+
from django.test import override_settings
47
from leaflets.models import Leaflet, LeafletImage
58
from leaflets.tests.conftest import TEST_IMAGE_LOCATION
69

10+
TEST_STORAGES = deepcopy(settings.STORAGES)
11+
TEST_STORAGES["default"]["BACKEND"] = (
12+
"electionleaflets.storages.TempUploadS3MediaStorage"
13+
)
14+
715

816
@pytest.fixture
917
def leaflet():
@@ -95,12 +103,8 @@ def test_image_moved_from_temp_upload(db, uploaded_temp_file):
95103
assert str(path) == leaflet_image.image.path
96104

97105

98-
def test_image_moved_from_temp_upload_s3_backend(
99-
db, settings, s3_bucket, s3_client
100-
):
101-
settings.DEFAULT_FILE_STORAGE = (
102-
"electionleaflets.storages.TempUploadS3MediaStorage"
103-
)
106+
@override_settings(STORAGES=TEST_STORAGES)
107+
def test_image_moved_from_temp_upload_s3_backend(db, s3_bucket, s3_client):
104108
leaflet = Leaflet()
105109
leaflet.save()
106110
leaflet.refresh_from_db()

electionleaflets/apps/leaflets/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import json
33
import random
44

5-
from braces.views import LoginRequiredMixin, StaffuserRequiredMixin
65
from core.helpers import CacheControlMixin
76
from django.conf import settings
87
from django.contrib import messages
8+
from django.contrib.auth.mixins import LoginRequiredMixin
99
from django.core.signing import Signer
1010
from django.db import transaction
1111
from django.db.models import Q
@@ -24,6 +24,7 @@
2424
SingleLeafletImageForm,
2525
UpdatePublisherDetails,
2626
)
27+
from .mixins import StaffuserRequiredMixin
2728
from .models import Leaflet, LeafletImage
2829

2930

electionleaflets/settings/base.py

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from os.path import abspath, dirname, join
77

88
import dc_design_system
9+
from dc_utils.settings.pipeline import * # noqa
10+
from dc_utils.settings.pipeline import get_pipeline_settings
911

1012

1113
def here(x):
@@ -51,7 +53,10 @@ def root(x):
5153
STATIC_URL = "/static/"
5254
STATICFILES_DIRS = (root("assets"),)
5355

54-
DEFAULT_FILE_STORAGE = "electionleaflets.storages.TempUploadLocalMediaStorage"
56+
STORAGES["default"] = { # noqa F405
57+
"BACKEND": "electionleaflets.storages.TempUploadLocalMediaStorage"
58+
}
59+
5560
AWS_S3_FILE_OVERWRITE = False
5661
STATICFILES_MANIFEST_NAME = environ.get(
5762
"STATICFILES_MANIFEST_NAME", "staticfiles.json"
@@ -61,61 +66,33 @@ def root(x):
6166
# AWS_S3_HOST = "s3-eu-west-1.amazonaws.com"
6267
# AWS_S3_CUSTOM_DOMAIN = "data.electionleaflets.org"
6368

64-
PIPELINE = {
65-
"COMPILERS": ("pipeline.compilers.sass.SASSCompiler",),
66-
"SASS_BINARY": "pysassc",
67-
"CSS_COMPRESSOR": "pipeline.compressors.NoopCompressor",
68-
"STYLESHEETS": {
69-
"styles": {
70-
"source_filenames": [
71-
"scss/styles.scss",
72-
"scss/vendor/filepond.css",
73-
"scss/vendor/filepond-plugin-image-preview.css",
74-
],
75-
"output_filename": "scss/styles.css",
76-
"extra_context": {
77-
"media": "screen,projection",
78-
},
79-
},
80-
},
81-
"JAVASCRIPT": {
82-
"scripts": {
83-
"source_filenames": [
84-
"javascript/app.js",
85-
"javascript/vendor/filepond.js",
86-
"javascript/vendor/filepond-plugin-image-exif-orientation.js",
87-
"javascript/vendor/filepond-plugin-image-preview.js",
88-
"javascript/image_uploader.js",
89-
# "javascript/vendor/ImageEditor.js",
90-
],
91-
"output_filename": "app.js",
92-
}
93-
},
94-
}
95-
69+
PIPELINE = get_pipeline_settings(
70+
extra_css=[
71+
"scss/styles.scss",
72+
"scss/vendor/filepond.css",
73+
"scss/vendor/filepond-plugin-image-preview.css",
74+
],
75+
extra_js=[
76+
"javascript/app.js",
77+
"javascript/vendor/filepond.js",
78+
"javascript/vendor/filepond-plugin-image-exif-orientation.js",
79+
"javascript/vendor/filepond-plugin-image-preview.js",
80+
"javascript/image_uploader.js",
81+
# "javascript/vendor/ImageEditor.js",
82+
],
83+
)
9684

97-
PIPELINE["CSS_COMPRESSOR"] = "pipeline.compressors.NoopCompressor"
9885
PIPELINE["JS_COMPRESSOR"] = "pipeline.compressors.NoopCompressor"
9986

100-
10187
PIPELINE["SASS_ARGUMENTS"] = (
10288
" -I " + dc_design_system.DC_SYSTEM_PATH + "/system"
10389
)
10490

105-
STATICFILES_FINDERS = (
106-
"django.contrib.staticfiles.finders.FileSystemFinder",
107-
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
108-
"pipeline.finders.CachedFileFinder",
109-
"pipeline.finders.PipelineFinder",
110-
"pipeline.finders.ManifestFinder",
111-
)
112-
11391
WHITENOISE_STATIC_PREFIX = "/static/"
11492

11593
SITE_ID = 1
11694
SITE_LOGO = "images/logo.png"
11795
USE_I18N = False
118-
USE_L10N = True
11996
LOGIN_URL = "/"
12097

12198
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
@@ -173,7 +150,6 @@ def root(x):
173150
"s3file",
174151
"django_filters",
175152
"dc_utils",
176-
"querystring_tag",
177153
] + LEAFLET_APPS
178154

179155

electionleaflets/settings/base_lambda.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
WHITENOISE_STATIC_PREFIX = "/static/"
3131

3232
STATIC_URL = WHITENOISE_STATIC_PREFIX
33-
STATICFILES_STORAGE = "electionleaflets.storages.StaticStorage"
33+
STORAGES["staticfiles"] = {"BACKEND": "electionleaflets.storages.StaticStorage"} # noqa F405
3434
STATICFILES_DIRS = (root("assets"),) # noqa: F405
3535
STATIC_ROOT = root("static") # noqa: F405
3636
MEDIA_ROOT = root( # noqa: F405
@@ -41,7 +41,9 @@
4141

4242
AWS_DEFAULT_ACL = "public-read"
4343

44-
DEFAULT_FILE_STORAGE = "electionleaflets.storages.TempUploadS3MediaStorage"
44+
STORAGES["default"] = { # noqa F405
45+
"BACKEND": "electionleaflets.storages.TempUploadS3MediaStorage"
46+
}
4547

4648
AWS_STORAGE_BUCKET_NAME = os.environ.get("LEAFLET_IMAGES_BUCKET_NAME")
4749
AWS_S3_SECURE_URLS = True

electionleaflets/settings/local.py.example

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ DATABASES = {
1414
}
1515
}
1616

17-
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
18-
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
17+
STORAGES = {
18+
"default": { "BACKEND": "django.core.files.storage.FileSystemStorage"},
19+
"staticfiles": { "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"},
20+
}
21+
1922
CACHES = {
2023
'default': {
2124
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
@@ -25,3 +28,8 @@ CACHES = {
2528

2629
#THUMBNAIL_DEBUG = True
2730
THUMBNAIL_KVSTORE ='sorl.thumbnail.kvstores.cached_db_kvstore.KVStore'
31+
32+
# Debug Toolbar Setup
33+
if DEBUG:
34+
INSTALLED_APPS += ("debug_toolbar",)
35+
MIDDLEWARE = ("debug_toolbar.middleware.DebugToolbarMiddleware",) + MIDDLEWARE # noqa: F405

electionleaflets/settings/testing.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55

66
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
77

8-
DEFAULT_FILE_STORAGE = "electionleaflets.storages.TempUploadLocalMediaStorage"
9-
STATICFILES_STORAGE = "electionleaflets.storages.StaticStorage"
8+
STORAGES = {
9+
"default": {
10+
"BACKEND": "electionleaflets.storages.TempUploadLocalMediaStorage"
11+
},
12+
"staticfiles": {"BACKEND": "electionleaflets.storages.StaticStorage"},
13+
}
1014

1115
# This is cleaned up in core/conftest.py
1216
MEDIA_ROOT = mkdtemp()

electionleaflets/templates/core/pager.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{% load querystring_tag %}
21
{% if page_obj.paginator.num_pages > 1 %}
32
<nav class="ds-pagination">
43

0 commit comments

Comments
 (0)