Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): upgrade to django 4.2 LTS #670

Merged
merged 13 commits into from
Oct 19, 2023
3 changes: 1 addition & 2 deletions django/core/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from hcaptcha_field import hCaptchaField
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from .models import ComsesGroups

Expand Down Expand Up @@ -57,5 +57,4 @@ def signup(self, request, user):
full_member = data.get("full_member")
if full_member:
user.groups.add(ComsesGroups.FULL_MEMBER.get_group())
logger.debug("adding user: %s", user)
user.save()
2 changes: 1 addition & 1 deletion django/core/jinja2/core/member_profiles/retrieve.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
<a href="{{ profile.get_edit_url() }}" class='btn btn-primary w-100 my-1'>
Edit Profile</a>
<a href="{{ url('library:codebase-add') }}" class="btn btn-secondary w-100 my-1">
Archive a model
Publish a model
</a>
{% endif %}
{# FIXME: set up JS logic for message / follow #}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Generated by Django 4.2.5 on 2023-09-05 04:38

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("taggit", "0005_auto_20220424_2025"),
("core", "0019_cascade_delete_memberprofile_user"),
]

operations = [
migrations.AlterField(
model_name="eventtag",
name="tag",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(app_label)s_%(class)s_items",
to="taggit.tag",
),
),
migrations.AlterField(
model_name="jobtag",
name="tag",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(app_label)s_%(class)s_items",
to="taggit.tag",
),
),
migrations.AlterField(
model_name="memberprofiletag",
name="tag",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(app_label)s_%(class)s_items",
to="taggit.tag",
),
),
migrations.AlterField(
model_name="platformtag",
name="tag",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(app_label)s_%(class)s_items",
to="taggit.tag",
),
),
]
16 changes: 10 additions & 6 deletions django/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from modelcluster.contrib.taggit import ClusterTaggableManager
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel
Expand Down Expand Up @@ -73,6 +73,7 @@ class SiteSettings(BaseSiteSetting):
banner_destination_url = models.URLField(
help_text=_("URL to redirect to when this banner is clicked"), blank=True
)
# expired_event_days_threshold = models.PositiveIntegerField(default=3, help_text=_("Number of days after an event's start date for which an event will be considered expired.")
last_modified = models.DateTimeField(auto_now=True)
mailchimp_digest_archive_url = models.URLField(
help_text=_("Mailchimp Digest Campaign Archive URL"), blank=True
Expand Down Expand Up @@ -534,10 +535,12 @@ def upcoming(self, **kwargs):
def get_expired_q(self):
"""
returns a Q object for all events with that have not yet ended or
started less than 7 days ago if the event has no end date
started less than 2 days ago
"""
now = timezone.now().date()
start_date_threshold = now - timedelta(days=7)
start_date_threshold = now - timedelta(
days=settings.EXPIRED_EVENT_DAYS_THRESHOLD
)
return models.Q(start_date__lt=start_date_threshold) | models.Q(
end_date__lt=now, end_date__isnull=False
)
Expand Down Expand Up @@ -654,11 +657,12 @@ def upcoming(self, **kwargs):
def get_expired_q(self):
"""
returns a Q object for all Jobs with a non-null application deadline before today or
posted/modified in the last [POST_DATE_DAYS_AGO_TRESHOLD] days if application deadline is null
posted/modified in the last [settings.EXPIRED_JOB_DAYS_THRESHOLD] days if
application deadline is null
"""
today = timezone.now()
post_date_days_ago_threshold = settings.POST_DATE_DAYS_AGO_THRESHOLD
post_date_threshold = today - timedelta(days=post_date_days_ago_threshold)
threshold = settings.EXPIRED_JOB_DAYS_THRESHOLD
post_date_threshold = today - timedelta(days=threshold)
return models.Q(
application_deadline__isnull=False, application_deadline__lt=today
) | models.Q(
Expand Down
2 changes: 1 addition & 1 deletion django/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.core.validators import validate_email
from django.db import transaction
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from markupfield.fields import Markup
from rest_framework import serializers
from rest_framework.exceptions import ValidationError as DrfValidationError
Expand Down
33 changes: 19 additions & 14 deletions django/core/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Django and Wagtail settings for the comses.net CMS

Django settings reference:
https://docs.djangoproject.com/en/3.2/topics/settings/
https://docs.djangoproject.com/en/4.2/topics/settings/

Wagtail settings reference:
https://docs.wagtail.org/en/stable/reference/contrib/settings.html
Expand Down Expand Up @@ -126,11 +126,14 @@ def is_test(self):
INSTALLED_APPS = DJANGO_APPS + WAGTAIL_APPS + COMSES_APPS + THIRD_PARTY_APPS

MIDDLEWARE = [
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
# allauth account middleware
"allauth.account.middleware.AccountMiddleware",

"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.middleware.security.SecurityMiddleware",
"csp.middleware.CSPMiddleware",
Expand Down Expand Up @@ -266,12 +269,16 @@ def is_test(self):

# regular settings

POST_DATE_DAYS_AGO_THRESHOLD = config.getint(
"default", "POST_DATE_DAYS_AGO_THRESHOLD", fallback=180
EXPIRED_JOB_DAYS_THRESHOLD = config.getint(
"default", "EXPIRED_JOB_DAYS_THRESHOLD", fallback=180
)

EXPIRED_EVENT_DAYS_THRESHOLD = config.getint(
"default", "EXPIRED_EVENT_DAYS_THRESHOLD", fallback=2
)

# Database configuration
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

Expand Down Expand Up @@ -301,8 +308,11 @@ def is_test(self):
BACKUP_ROOT = "/shared/backups"
EXTRACT_ROOT = "/shared/extract"

FILE_UPLOAD_MAX_MEMORY_SIZE = 104857600
FILE_UPLOAD_PERMISSIONS = 0o644
FILE_UPLOAD_TEMP_DIR = "/shared/uploads/"

for d in (LOG_DIRECTORY, LIBRARY_ROOT, REPOSITORY_ROOT):
for d in (LOG_DIRECTORY, LIBRARY_ROOT, REPOSITORY_ROOT, FILE_UPLOAD_TEMP_DIR):
try:
if not os.path.isdir(d):
os.mkdir(d)
Expand Down Expand Up @@ -387,7 +397,7 @@ def is_test(self):
}

# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = "en-us"

Expand All @@ -400,7 +410,7 @@ def is_test(self):
USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
Expand Down Expand Up @@ -453,7 +463,6 @@ def is_test(self):
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.BasicAuthentication",
"rest_framework_jwt.authentication.JSONWebTokenAuthentication",
),
"EXCEPTION_HANDLER": "core.views.rest_exception_handler",
"PAGE_SIZE": 10,
Expand Down Expand Up @@ -528,7 +537,7 @@ def is_test(self):
"discourse", "DISCOURSE_API_USERNAME", fallback="unconfigured"
)

# https://docs.djangoproject.com/en/3.2/ref/settings/#templates
# https://docs.djangoproject.com/en/4.2/ref/settings/#templates
TEMPLATES = [
{
"BACKEND": "django.template.backends.jinja2.Jinja2",
Expand Down Expand Up @@ -573,8 +582,4 @@ def is_test(self):
messages.ERROR: "alert alert-danger",
}

FILE_UPLOAD_MAX_MEMORY_SIZE = 104857600
FILE_UPLOAD_PERMISSIONS = 0o644
FILE_UPLOAD_TEMP_DIR = "/shared/uploads/"

ACCEPTED_IMAGE_TYPES = ["gif", "jpeg", "png"]
42 changes: 27 additions & 15 deletions django/core/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import random
from datetime import timedelta

from django.conf import settings
Expand All @@ -16,7 +17,7 @@ def setUp(self):
self.job_factory = JobFactory(submitter=self.user)
today = timezone.now()

self.threshold = settings.POST_DATE_DAYS_AGO_THRESHOLD
self.threshold = settings.EXPIRED_JOB_DAYS_THRESHOLD

# active jobs
self.active_job = self.job_factory.create(
Expand Down Expand Up @@ -116,28 +117,41 @@ def setUp(self):
end_date=now + timedelta(days=1),
title="Current Event",
)
self.no_end_date_current_event = self.event_factory.create(
start_date=now - timedelta(days=6),
end_date=None,
title="No End Date Current Event",
)
self.no_end_date_current_events = [
self.event_factory.create(
start_date=now - timedelta(days=threshold),
end_date=None,
title="No End Date Current Event",
)
for threshold in range(settings.EXPIRED_EVENT_DAYS_THRESHOLD)
]

# expired events
self.expired_event = self.event_factory.create(
start_date=now - timedelta(days=14),
end_date=now - timedelta(days=7),
title="Expired Event",
)
self.no_end_date_expired_event = self.event_factory.create(
start_date=now - timedelta(days=10),
end_date=None,
title="No End Date Expired Event",
)
expired_days_threshold = settings.EXPIRED_EVENT_DAYS_THRESHOLD + 1
sample_expired_event_thresholds = set(
random.sample(range(expired_days_threshold, 365), 10)
)
sample_expired_event_thresholds.add(
expired_days_threshold
) # always test the edge
self.no_end_date_expired_events = [
self.event_factory.create(
start_date=now - timedelta(days=threshold),
end_date=None,
title="No End Date Expired Event",
)
for threshold in sample_expired_event_thresholds
]

def test_with_expired(self):
events = Event.objects.all().with_expired()
for event in events:
if event in [self.expired_event, self.no_end_date_expired_event]:
if event in [self.expired_event] + self.no_end_date_expired_events:
self.assertTrue(event.is_expired)
else:
self.assertFalse(event.is_expired)
Expand All @@ -146,8 +160,6 @@ def test_upcoming(self):
events = Event.objects.upcoming()
for upcoming_event in [
self.upcoming_event,
self.no_end_date_upcoming_event,
self.current_event,
self.no_end_date_current_event,
]:
] + self.no_end_date_current_events:
self.assertIn(upcoming_event, events)
2 changes: 0 additions & 2 deletions django/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.contrib import admin
from django.urls import include, path
from rest_framework.routers import SimpleRouter
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework_swagger.views import get_swagger_view
from wagtail.admin import urls as wagtailadmin_urls
from wagtail import urls as wagtail_urls
Expand Down Expand Up @@ -82,7 +81,6 @@ def get_core_urls():
# path('wagtail/admin/', view=wagtail_hooks.DashboardView.as_view(), name='wagtailadmin_home'),
path("wagtail/admin/", include(wagtailadmin_urls)),
path("api/schema/", schema_view),
path("api/token/", obtain_jwt_token),
path("api-auth/", include("rest_framework.urls")),
# configure sitemaps and robots.txt, see https://django-robots.readthedocs.io/en/latest/
# https://docs.wagtail.io/en/v2.9.2/reference/contrib/sitemaps.html
Expand Down
2 changes: 1 addition & 1 deletion django/home/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.template import loader
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from urllib.parse import urlparse
from wagtail.models import Site

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.2.5 on 2023-09-05 04:38

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("taggit", "0005_auto_20220424_2025"),
("home", "0017_comsesdigest"),
]

operations = [
migrations.AlterField(
model_name="journaltag",
name="tag",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(app_label)s_%(class)s_items",
to="taggit.tag",
),
),
migrations.AlterField(
model_name="tutorialtag",
name="tag",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(app_label)s_%(class)s_items",
to="taggit.tag",
),
),
]
Loading