Skip to content

Commit

Permalink
Upgrade Django 3.2 -> 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbaptista committed Nov 20, 2024
1 parent 7a136df commit 2ea3634
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
40 changes: 20 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package-mode = false

[tool.poetry.dependencies]
python = ">=3.9,<3.10"
django = "<3.3"
django = "4.2"
django-widget-tweaks = "1.4.3"
django-environ = "0.11.2"
django-storages = {extras = ["s3"], version = "^1.14.4"}
Expand All @@ -29,7 +29,8 @@ pytest-django = "^4.9.0"
pre-commit = "^3.8.0"

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "web.settings"
DJANGO_SETTINGS_MODULE = "web.settings_test"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
6 changes: 6 additions & 0 deletions web/foi_requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,22 @@ def status(self):

@property
def moderation_message(self):
if not self.pk:
return None
first_message = self.first_message
if first_message:
return first_message.moderation_message

@property
def first_message(self):
if not self.pk:
return None
return self.message_set.order_by("created_at").first()

@property
def last_message(self):
if not self.pk:
return None
return self.message_set.order_by("created_at").last()


Expand Down
18 changes: 10 additions & 8 deletions web/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
SESSION_COOKIE_SECURE=(bool, False),
CSRF_COOKIE_SECURE=(bool, False),
CSRF_COOKIE_DOMAIN=(str, None),
CSRF_TRUSTED_ORIGINS=(list, ["queremossaber.org.br"]),
CSRF_TRUSTED_ORIGINS=(list, ["https://queremossaber.org.br"]),
ENV=(str, "dev"),
)
env.read_env(env.str("ENV_PATH"))
Expand Down Expand Up @@ -165,8 +165,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand All @@ -178,7 +176,15 @@
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "web", "static"),
]
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}

# Uploaded files variables. Will only be used if ENABLE_S3 is False.
MEDIA_URL = "/upload/"
Expand All @@ -201,10 +207,6 @@
"CacheControl": "public, max-age=31556926",
}

# FIXME: This is a workaround because WhiteNoise's files storage raises error 500.
# http://whitenoise.evans.io/en/stable/django.html#troubleshooting-the-whitenoise-storage-backend
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"

DJANGO_LIVESYNC = {
"HOST": "localhost",
"PORT": 9001,
Expand Down
10 changes: 10 additions & 0 deletions web/settings_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .settings import * # noqa: F403

STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}

0 comments on commit 2ea3634

Please sign in to comment.