feat: Create notifications for 404 deactivation

This commit is contained in:
moanos [he/him] 2024-12-14 09:31:06 +01:00
parent e858f61b3f
commit ec9f5b305c
3 changed files with 41 additions and 1 deletions

View File

@ -0,0 +1,27 @@
# Generated by Django 5.1.1 on 2024-12-14 07:57
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fellchensammlung', '0026_alter_animal_sex'),
]
operations = [
migrations.AlterField(
model_name='animal',
name='species',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fellchensammlung.species', verbose_name='Tierart'),
),
migrations.CreateModel(
name='AndoptionNoticeNotification',
fields=[
('basenotification_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='fellchensammlung.basenotification')),
('adoption_notice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fellchensammlung.adoptionnotice', verbose_name='Vermittlung')),
],
bases=('fellchensammlung.basenotification',),
),
]

View File

@ -753,6 +753,12 @@ class CommentNotification(BaseNotification):
def url(self):
return self.comment.get_absolute_url
class AndoptionNoticeNotification(BaseNotification):
adoption_notice = models.ForeignKey(AdoptionNotice, on_delete=models.CASCADE, verbose_name=_('Vermittlung'))
@property
def url(self):
return self.adoption_notice.get_absolute_url
class Subscriptions(models.Model):
owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('Nutzer*in'))

View File

@ -3,7 +3,8 @@ import logging
from django.utils import timezone
from datetime import timedelta
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus, Log
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus, Log, \
AndoptionNoticeNotification
from fellchensammlung.tools.misc import is_404
@ -82,3 +83,9 @@ def deactivate_404_adoption_notices():
logging_msg = f"Automatically set Adoption Notice {adoption_notice.id} closed as link to more information returened 404"
logging.info(logging_msg)
Log.objects.create(action="automated", text=logging_msg)
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.'
AndoptionNoticeNotification.objects.create(user=adoption_notice.owner,
title="Vermittlung deaktiviert",
adoption_notice=adoption_notice,
text=deactivation_message)