Skip to content

Commit

Permalink
Add workaround for deleting polymorphic feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
david-venhoff committed Mar 21, 2022
1 parent 13aec24 commit 44a1dde
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
34 changes: 34 additions & 0 deletions integreat_cms/cms/models/feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.utils.translation import ugettext_lazy as _

from polymorphic.models import PolymorphicModel
from polymorphic.managers import PolymorphicQuerySet, PolymorphicManager

from ...constants import feedback_ratings
from ...utils.translation_utils import ugettext_many_lazy as __
Expand All @@ -13,12 +14,45 @@
from ..regions.region import Region


class CascadeDeletePolymorphicQuerySet(PolymorphicQuerySet):
"""
Patch the QuerySet to call delete on the non_polymorphic QuerySet, avoiding models.deletion.Collector typing problem
Based on workarounds proposed in: https://github.com/django-polymorphic/django-polymorphic/issues/229
See also: https://github.com/django-polymorphic/django-polymorphic/issues/34, https://github.com/django-polymorphic/django-polymorphic/issues/84
Related Django ticket: https://code.djangoproject.com/ticket/23076
"""

def delete(self):
"""
This method deletes all objects in this QuerySet.
:return: A tuple of the number of objects delete and the delete objects grouped by their type
:rtype: tuple
"""
if not self.polymorphic_disabled:
return self.non_polymorphic().delete()

return super().delete()


class CascadeDeletePolymorphicManager(PolymorphicManager):
"""
This class is used as a workaround for a bug in django-polymorphic.
For more information, see :class:`~integreat_cms.cms.models.feedback.feedback.CascadeDeletePolymorphicQuerySet`.
"""

queryset_class = CascadeDeletePolymorphicQuerySet


class Feedback(PolymorphicModel, AbstractBaseModel):
"""
Database model representing feedback from app-users.
Do not directly create instances of this base model, but of the submodels (e.g. PageFeedback) instead.
"""

objects = CascadeDeletePolymorphicManager()

region = models.ForeignKey(
Region,
on_delete=models.CASCADE,
Expand Down
2 changes: 1 addition & 1 deletion integreat_cms/cms/views/feedback/admin_feedback_actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
This module contains action methods for feedack items (archive, restore, ...)
This module contains action methods for feedback items (archive, restore, ...)
"""
import logging

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
This module contains action methods for feedack items (archive, restore, ...)
This module contains action methods for feedback items (archive, restore, ...)
"""
import logging

Expand Down
26 changes: 13 additions & 13 deletions integreat_cms/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-03-20 18:58+0000\n"
"POT-Creation-Date: 2022-03-21 13:18+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Integreat <[email protected]>\n"
"Language-Team: Integreat <[email protected]>\n"
Expand Down Expand Up @@ -1840,14 +1840,14 @@ msgid "The new passwords do not match."
msgstr "Die Passwörter stimmen nicht überein."

#: cms/models/abstract_content_model.py:96 cms/models/abstract_tree_node.py:35
#: cms/models/feedback/feedback.py:26 cms/models/media/directory.py:24
#: cms/models/feedback/feedback.py:60 cms/models/media/directory.py:24
#: cms/models/media/media_file.py:138
#: cms/models/push_notifications/push_notification.py:21
#: cms/models/regions/region.py:613
msgid "region"
msgstr "Region"

#: cms/models/abstract_content_model.py:99 cms/models/feedback/feedback.py:62
#: cms/models/abstract_content_model.py:99 cms/models/feedback/feedback.py:96
#: cms/models/languages/language.py:85
#: cms/models/languages/language_tree_node.py:37
#: cms/models/media/directory.py:36 cms/models/offers/offer_template.py:56
Expand Down Expand Up @@ -1894,7 +1894,7 @@ msgid "content"
msgstr "Inhalt"

#: cms/models/abstract_content_translation.py:44
#: cms/models/feedback/feedback.py:32 cms/models/languages/language.py:135
#: cms/models/feedback/feedback.py:66 cms/models/languages/language.py:135
#: cms/models/languages/language_tree_node.py:23
#: cms/models/push_notifications/push_notification_translation.py:27
msgid "language"
Expand Down Expand Up @@ -2120,39 +2120,39 @@ msgstr "Veranstaltungen"
msgid "event list feedback"
msgstr "Veranstaltungslisten-Feedback"

#: cms/models/feedback/feedback.py:40
#: cms/models/feedback/feedback.py:74
msgid "rating"
msgstr "Bewertung"

#: cms/models/feedback/feedback.py:41
#: cms/models/feedback/feedback.py:75
msgid "Whether the feedback is positive or negative"
msgstr "Ob das Feedback positiv oder negativ ist"

#: cms/models/feedback/feedback.py:43
#: cms/models/feedback/feedback.py:77
msgid "comment"
msgstr "Kommentar"

#: cms/models/feedback/feedback.py:45
#: cms/models/feedback/feedback.py:79
msgid "technical"
msgstr "technisch"

#: cms/models/feedback/feedback.py:46
#: cms/models/feedback/feedback.py:80
msgid "Whether or not the feedback is targeted at the developers"
msgstr "Ob das Feedback an die Entwickler gerichtet ist oder nicht"

#: cms/models/feedback/feedback.py:54
#: cms/models/feedback/feedback.py:88
msgid "marked as read by"
msgstr "als gelesen markiert von"

#: cms/models/feedback/feedback.py:56
#: cms/models/feedback/feedback.py:90
msgid "The user who marked this feedback as read."
msgstr "Der Benutzer, der dieses Feedback als gelesen markiert hat."

#: cms/models/feedback/feedback.py:57
#: cms/models/feedback/feedback.py:91
msgid "If the feedback is unread, this field is empty."
msgstr "Wenn das Feedback ungelesen ist, ist dieses Feld leer."

#: cms/models/feedback/feedback.py:150 cms/models/feedback/feedback.py:152
#: cms/models/feedback/feedback.py:184 cms/models/feedback/feedback.py:186
msgid "feedback"
msgstr "Feedback"

Expand Down

0 comments on commit 44a1dde

Please sign in to comment.