feat: Completely rework notification framework
This change is needed as a) there are many different types of notifications. A notification about a new comment does not only relate the comment but also adoption notice and a user that made the comment. Therefore, I introduce a new general notification that has optional links to other objects. b) this change allows to define a different representation of e-mails vs. display on the website. The new notification type is in charge of representation from now on. Title and text will be deprecated and eventually removed
This commit is contained in:
@@ -10,7 +10,7 @@ from django.core import mail
|
||||
from django.utils.html import strip_tags
|
||||
|
||||
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus, Log, \
|
||||
AdoptionNoticeNotification
|
||||
Notification, NotificationTypeChoices
|
||||
from fellchensammlung.tools.misc import is_404
|
||||
|
||||
|
||||
@@ -92,10 +92,11 @@ def deactivate_404_adoption_notices():
|
||||
|
||||
deactivation_message = f'Die Vermittlung [{adoption_notice.name}]({adoption_notice.get_absolute_url()}) wurde automatisch deaktiviert, da die Website unter "Mehr Informationen" nicht mehr online ist.'
|
||||
for subscription in adoption_notice.get_subscriptions():
|
||||
AdoptionNoticeNotification.objects.create(user=subscription.owner,
|
||||
title="Vermittlung deaktiviert",
|
||||
adoption_notice=adoption_notice,
|
||||
text=deactivation_message)
|
||||
Notification.objects.create(user_to_notify=subscription.owner,
|
||||
notification_type=NotificationTypeChoices.AN_WAS_DEACTIVATED,
|
||||
title="Vermittlung deaktiviert",
|
||||
adoption_notice=adoption_notice,
|
||||
text=deactivation_message)
|
||||
|
||||
|
||||
def dedup_location(location: Location, destructive=False):
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from fellchensammlung.models import User, AdoptionNoticeNotification, TrustLevel
|
||||
from fellchensammlung.models import User, Notification, TrustLevel, NotificationTypeChoices
|
||||
|
||||
|
||||
def notify_of_AN_to_be_checked(adoption_notice):
|
||||
@@ -6,8 +6,9 @@ def notify_of_AN_to_be_checked(adoption_notice):
|
||||
users_to_notify = set(User.objects.filter(trust_level__gt=TrustLevel.MODERATOR))
|
||||
users_to_notify.add(adoption_notice.owner)
|
||||
for user in users_to_notify:
|
||||
AdoptionNoticeNotification.objects.create(adoption_notice=adoption_notice,
|
||||
user=user,
|
||||
title=f" Prüfe Vermittlung {adoption_notice}",
|
||||
text=f"{adoption_notice} muss geprüft werden bevor sie veröffentlicht wird.",
|
||||
)
|
||||
Notification.objects.create(adoption_notice=adoption_notice,
|
||||
user_to_notify=user,
|
||||
notification_type=NotificationTypeChoices.AN_IS_TO_BE_CHECKED,
|
||||
title=f" Prüfe Vermittlung {adoption_notice}",
|
||||
text=f"{adoption_notice} muss geprüft werden bevor sie veröffentlicht wird.",
|
||||
)
|
||||
|
@@ -3,7 +3,8 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .geo import LocationProxy, Position
|
||||
from ..forms import AdoptionNoticeSearchForm
|
||||
from ..models import SearchSubscription, AdoptionNotice, AdoptionNoticeNotification, SexChoicesWithAll, Location
|
||||
from ..models import SearchSubscription, AdoptionNotice, SexChoicesWithAll, Location, \
|
||||
Notification, NotificationTypeChoices
|
||||
|
||||
|
||||
def notify_search_subscribers(adoption_notice: AdoptionNotice, only_if_active: bool = True):
|
||||
@@ -20,10 +21,11 @@ def notify_search_subscribers(adoption_notice: AdoptionNotice, only_if_active: b
|
||||
search = Search(search_subscription=search_subscription)
|
||||
if search.adoption_notice_fits_search(adoption_notice):
|
||||
notification_text = f"{_('Zu deiner Suche')} {search_subscription} wurde eine neue Vermittlung gefunden"
|
||||
AdoptionNoticeNotification.objects.create(user=search_subscription.owner,
|
||||
title=f"{_('Neue Vermittlung')}: {adoption_notice}",
|
||||
adoption_notice=adoption_notice,
|
||||
text=notification_text)
|
||||
Notification.objects.create(user_to_notify=search_subscription.owner,
|
||||
notification_type=NotificationTypeChoices.AN_FOR_SEARCH_FOUND,
|
||||
title=f"{_('Neue Vermittlung')}: {adoption_notice}",
|
||||
adoption_notice=adoption_notice,
|
||||
text=notification_text)
|
||||
logging.debug(f"Notification for search subscription {search_subscription} was sent.")
|
||||
else:
|
||||
logging.debug(f"Adoption notice {adoption_notice} was not fitting the search subscription.")
|
||||
|
Reference in New Issue
Block a user