From 50041ffc1cb471f82e025892a1c7a89f7785db47 Mon Sep 17 00:00:00 2001 From: Mara Karagianni Date: Tue, 9 Apr 2024 18:23:09 +0300 Subject: [PATCH] deps: django upgrade to 4.2 --- adhocracy-plus/config/settings/production.py | 9 +++++++- apps/activities/models.py | 6 +++-- .../0004_alter_customrendition_file.py | 23 +++++++++++++++++++ apps/documents/models.py | 10 ++++---- apps/ideas/models.py | 6 +++-- apps/interactiveevents/models.py | 6 +++-- apps/moderatorfeedback/models.py | 6 +++-- apps/newsletters/models.py | 7 +++--- apps/offlineevents/models.py | 14 ++++++----- apps/organisations/models.py | 6 +++-- apps/topicprio/models.py | 6 +++-- changelog/7637.md | 3 +++ package.json | 2 +- requirements/base.txt | 4 ++-- 14 files changed, 79 insertions(+), 29 deletions(-) create mode 100644 apps/cms/images/migrations/0004_alter_customrendition_file.py diff --git a/adhocracy-plus/config/settings/production.py b/adhocracy-plus/config/settings/production.py index 776eaccd7c..222288b43f 100644 --- a/adhocracy-plus/config/settings/production.py +++ b/adhocracy-plus/config/settings/production.py @@ -2,7 +2,14 @@ DEBUG = False -STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" +STORAGES = { + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, + "staticfiles": { + "BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage", + }, +} try: from .local import * diff --git a/apps/activities/models.py b/apps/activities/models.py index 84c52cdc71..614f7a0582 100644 --- a/apps/activities/models.py +++ b/apps/activities/models.py @@ -25,8 +25,10 @@ class Activity(module_models.Item): def get_absolute_url(self): return self.project.get_absolute_url() - def save(self, *args, **kwargs): + def save(self, update_fields=None, *args, **kwargs): self.description = html_transforms.clean_html_field( self.description, "collapsible-image-editor" ) - super().save(*args, **kwargs) + if update_fields: + update_fields = {"description"}.union(update_fields) + super().save(update_fields=update_fields, *args, **kwargs) diff --git a/apps/cms/images/migrations/0004_alter_customrendition_file.py b/apps/cms/images/migrations/0004_alter_customrendition_file.py new file mode 100644 index 0000000000..fd55ca924b --- /dev/null +++ b/apps/cms/images/migrations/0004_alter_customrendition_file.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2 on 2024-04-09 15:17 + +from django.db import migrations +import wagtail.images.models + + +class Migration(migrations.Migration): + dependencies = [ + ("a4_candy_cms_images", "0003_auto_20240208_1216"), + ] + + operations = [ + migrations.AlterField( + model_name="customrendition", + name="file", + field=wagtail.images.models.WagtailImageField( + height_field="height", + storage=wagtail.images.models.get_rendition_storage, + upload_to=wagtail.images.models.get_rendition_upload_to, + width_field="width", + ), + ), + ] diff --git a/apps/documents/models.py b/apps/documents/models.py index f273728a84..94f6ea336a 100644 --- a/apps/documents/models.py +++ b/apps/documents/models.py @@ -59,8 +59,8 @@ def next(self): class Paragraph(base.TimeStampedModel): name = models.CharField(max_length=120, blank=True) text = CKEditor5Field( - config_name="image-editor", validators=[ImageAltTextValidator()] -) + config_name="image-editor", validators=[ImageAltTextValidator()] + ) weight = models.PositiveIntegerField() chapter = models.ForeignKey( @@ -78,9 +78,11 @@ class Meta: def __str__(self): return "{}_paragraph_{}".format(str(self.chapter), self.weight) - def save(self, *args, **kwargs): + def save(self, update_fields=None, *args, **kwargs): self.text = transforms.clean_html_field(self.text, "image-editor") - super().save(*args, **kwargs) + if update_fields: + update_fields = {"text"}.union(update_fields) + super().save(update_fields=update_fields, *args, **kwargs) def get_absolute_url(self): return reverse( diff --git a/apps/ideas/models.py b/apps/ideas/models.py index 18ea486806..d51600fd8a 100644 --- a/apps/ideas/models.py +++ b/apps/ideas/models.py @@ -66,9 +66,11 @@ class Meta: def __str__(self): return self.name - def save(self, *args, **kwargs): + def save(self, update_fields=None, *args, **kwargs): self.description = transforms.clean_html_field(self.description) - super().save(*args, **kwargs) + if update_fields: + update_fields = {"description"}.union(update_fields) + super().save(update_fields=update_fields, *args, **kwargs) class Idea(AbstractIdea): diff --git a/apps/interactiveevents/models.py b/apps/interactiveevents/models.py index 4d848ac16e..79d8f39d07 100644 --- a/apps/interactiveevents/models.py +++ b/apps/interactiveevents/models.py @@ -82,6 +82,8 @@ class ExtraFieldsInteractiveEvent(module_models.Item): blank=True, ) - def save(self, *args, **kwargs): + def save(self, update_fields=None, *args, **kwargs): self.live_stream = transforms.clean_html_field(self.live_stream, "video-editor") - super().save(*args, **kwargs) + if update_fields: + update_fields = {"live_stream"}.union(update_fields) + super().save(update_fields=update_fields, *args, **kwargs) diff --git a/apps/moderatorfeedback/models.py b/apps/moderatorfeedback/models.py index bc1115a548..83d0f086d3 100644 --- a/apps/moderatorfeedback/models.py +++ b/apps/moderatorfeedback/models.py @@ -21,9 +21,11 @@ class ModeratorFeedback(UserGeneratedContentModel): verbose_name=_("Official feedback"), ) - def save(self, *args, **kwargs): + def save(self, update_fields=None, *args, **kwargs): self.feedback_text = transforms.clean_html_field(self.feedback_text) - super().save(*args, **kwargs) + if update_fields: + update_fields = {"feedback_text"}.union(update_fields) + super().save(update_fields=update_fields, *args, **kwargs) class Moderateable(models.Model): diff --git a/apps/newsletters/models.py b/apps/newsletters/models.py index 861035d2e1..4e09b8deec 100644 --- a/apps/newsletters/models.py +++ b/apps/newsletters/models.py @@ -25,7 +25,6 @@ class Newsletter(UserGeneratedContentModel): - sender_name = models.CharField(max_length=254, verbose_name=_("Name")) sender = models.EmailField(blank=True, verbose_name=_("Sender")) subject = models.CharField(max_length=254, verbose_name=_("Subject")) @@ -74,6 +73,8 @@ def replace_relative_media_urls(text): text = re.sub(pattern, r"\1%s\2" % settings.WAGTAILADMIN_BASE_URL, text) return text - def save(self, *args, **kwargs): + def save(self, update_fields=None, *args, **kwargs): self.body = transforms.clean_html_field(self.body, "image-editor") - super().save(*args, **kwargs) + if update_fields: + update_fields = {"body"}.union(update_fields) + super().save(update_fields=update_fields, *args, **kwargs) diff --git a/apps/offlineevents/models.py b/apps/offlineevents/models.py index 2d45870778..77381d6f1c 100644 --- a/apps/offlineevents/models.py +++ b/apps/offlineevents/models.py @@ -29,10 +29,10 @@ class OfflineEvent(UserGeneratedContentModel): ) date = models.DateTimeField(verbose_name=_("Date")) description = CKEditor5Field( - config_name="collapsible-image-editor", - verbose_name=_("Description"), - validators=[ImageAltTextValidator()], - ) + config_name="collapsible-image-editor", + verbose_name=_("Description"), + validators=[ImageAltTextValidator()], + ) project = models.ForeignKey(project_models.Project, on_delete=models.CASCADE) objects = OfflineEventsQuerySet.as_manager() @@ -43,9 +43,11 @@ class Meta: def __str__(self): return self.name - def save(self, *args, **kwargs): + def save(self, update_fields=None, *args, **kwargs): self.description = transforms.clean_html_field(self.description, "image-editor") - super().save(*args, **kwargs) + if update_fields: + update_fields = {"description"}.union(update_fields) + super().save(update_fields=update_fields, *args, **kwargs) @cached_property def get_timeline_index(self): diff --git a/apps/organisations/models.py b/apps/organisations/models.py index 515f7df994..295ae8b674 100644 --- a/apps/organisations/models.py +++ b/apps/organisations/models.py @@ -232,9 +232,11 @@ def get_absolute_url(self): def has_social_share(self): return self.twitter_handle or self.facebook_handle or self.instagram_handle - def save(self, *args, **kwargs): + def save(self, update_fields=None, *args, **kwargs): self.imprint = transforms.clean_html_field(self.imprint) - super().save(*args, **kwargs) + if update_fields: + update_fields = {"imprint"}.union(update_fields) + super().save(update_fields=update_fields, *args, **kwargs) class Member(models.Model): diff --git a/apps/topicprio/models.py b/apps/topicprio/models.py index ad17125ba0..9adeadf60a 100644 --- a/apps/topicprio/models.py +++ b/apps/topicprio/models.py @@ -66,9 +66,11 @@ def reference_number(self): def __str__(self): return self.name - def save(self, *args, **kwargs): + def save(self, update_fields=None, *args, **kwargs): self.description = transforms.clean_html_field(self.description, "image-editor") - super().save(*args, **kwargs) + if update_fields: + update_fields = {"description"}.union(update_fields) + super().save(update_fields=update_fields, *args, **kwargs) def get_absolute_url(self): return reverse( diff --git a/changelog/7637.md b/changelog/7637.md index b10dcaba5c..74c14f9e4e 100644 --- a/changelog/7637.md +++ b/changelog/7637.md @@ -11,3 +11,6 @@ - replace deprecated custom `delete()` method with `form_valid()` in relevant `apps//views.py` - replace deprecated session LANGUAGE_SESSION_KEY with LANGUAGE_COOKIE_NAME cookie - generate migrations for related name labels + +- Django from 4.0 to 4.2 + custom model save() methods should the update_fields keyword argument before calling super() diff --git a/package.json b/package.json index 994a394c6d..11f8e9816f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "dependencies": { "@fortawesome/fontawesome-free": "5.15.4", "@maplibre/maplibre-gl-leaflet": "0.0.19", - "adhocracy4": "git+https://github.com/liqd/adhocracy4#ckeditor5-transition-a4", + "adhocracy4": "git+https://github.com/liqd/adhocracy4#30bf7363253d48ad39f0580e5b8a25b9a7eca1a4", "autoprefixer": "10.4.14", "bootstrap": "5.2.3", "css-loader": "6.8.1", diff --git a/requirements/base.txt b/requirements/base.txt index 9f546b3a0d..1e792a3530 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,5 +1,5 @@ # A4 -git+https://github.com/liqd/adhocracy4.git@ckeditor5-transition-a4#egg=adhocracy4 +git+https://github.com/liqd/adhocracy4.git@30bf7363253d48ad39f0580e5b8a25b9a7eca1a4#egg=adhocracy4 # Additional requirements brotli==1.0.9 @@ -15,7 +15,7 @@ urllib3==2.0.3 redis==5.0.0 # Inherited a4-core requirements -Django== 4.0 +Django== 4.2 django-allauth==0.54.0 git+https://github.com/liqd/django-autoslug.git@liqd2212#egg=django-autoslug django-ckeditor==6.5.1