Skip to content

Commit

Permalink
deps, models, views: django upgrade to 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
m4ra committed Nov 27, 2023
1 parent 7c0eed1 commit 0ee1c03
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
11 changes: 9 additions & 2 deletions adhocracy4/comments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,24 @@ def __str__(self):
else:
return "{}".format(self.comment)

def save(self, *args, **kwargs):
def save(self, update_fields=None, *args, **kwargs):
"""Change comment.comment if comment was marked removed or censored."""
self.comment = transforms.clean_html_all(self.comment)
update_project = False
if not self.project:
self.project = self.content_object.module.project
update_project = True

if self.is_removed or self.is_censored:
self.comment = self._former_comment = ""
self.comment_categories = ""

super(Comment, self).save(*args, **kwargs)
if update_fields:
update_fields = {"comment"}.union(update_fields)
if update_project:
update_fields = {"project"}.union(update_fields)

super().save(update_fields=update_fields, *args, **kwargs)

def get_absolute_url(self):
if hasattr(self.content_object, "get_absolute_url"):
Expand Down
2 changes: 1 addition & 1 deletion adhocracy4/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def post(self, request, *args, **kwargs):
def get_next(self):
if "referrer" in self.request.POST:
return self.request.POST["referrer"]
elif "HTTP_REFERER" in self.request.META:
elif "referer" in self.request.headers:
return self.request.headers["Referer"]

return reverse(
Expand Down
6 changes: 4 additions & 2 deletions adhocracy4/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ class TimeStampedModel(models.Model):
class Meta:
abstract = True

def save(self, ignore_modified=False, *args, **kwargs):
def save(self, ignore_modified=False, update_fields=None, *args, **kwargs):
if self.pk is not None and not ignore_modified:
self.modified = timezone.now()
super(TimeStampedModel, self).save(*args, **kwargs)
if update_fields:
update_fields = {"modified"}.union(update_fields)
super().save(update_fields=update_fields, *args, **kwargs)


class UserGeneratedContentModel(TimeStampedModel):
Expand Down
10 changes: 8 additions & 2 deletions adhocracy4/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def __str__(self):
def get_absolute_url(self):
return reverse("project-detail", kwargs=dict(slug=self.slug))

def save(self, *args, **kwargs):
def save(self, update_fields=None, *args, **kwargs):
self.information = html_transforms.clean_html_field(
self.information, "collapsible-image-editor"
)
Expand All @@ -289,7 +289,13 @@ def save(self, *args, **kwargs):
if self.pk is None:
project_type = "{}.{}".format(self._meta.app_label, self.__class__.__name__)
self.project_type = project_type
super(Project, self).save(*args, **kwargs)

if update_fields:
update_fields = {"information", "result"}.union(update_fields)
if self.pk is None:
update_fields = {"project_type"}.union(update_fields)

super().save(update_fields=update_fields, *args, **kwargs)

# functions needed to determine permissions
def has_member(self, user):
Expand Down
4 changes: 4 additions & 0 deletions changelog/7776.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@

- Django from 4.0 to 4.1
Reverse relations need to be saved before being called from the object they relate

- Django from 4.1 to 4.2
any fields modified in the custom save() methods should be added to the update_fields keyword argument before calling super()
retrieve referer in requests from headers instead of META
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
beautifulsoup4==4.12.2
bleach[css]==6.0.0
Django==4.1
Django==4.2
django-allauth==0.55.0
git+https://github.com/liqd/django-autoslug.git@liqd2212#egg=django-autoslug
https://github.com/liqd/django-ckeditor-5/releases/download/v0.2.11-liqd/django_ckeditor_5-0.2.11-py3-none-any.whl
Expand Down

0 comments on commit 0ee1c03

Please sign in to comment.