feat: Add function to deactivate AN when link returns 404
This commit is contained in:
parent
ab3437e61d
commit
70154abd37
@ -707,7 +707,7 @@ class Log(models.Model):
|
|||||||
"""
|
"""
|
||||||
Basic class that allows logging random entries for later inspection
|
Basic class that allows logging random entries for later inspection
|
||||||
"""
|
"""
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_("Nutzer*in"))
|
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_("Nutzer*in"), blank=True, null=True)
|
||||||
action = models.CharField(max_length=255, verbose_name=_("Aktion"))
|
action = models.CharField(max_length=255, verbose_name=_("Aktion"))
|
||||||
text = models.CharField(max_length=1000, verbose_name=_("Log text"))
|
text = models.CharField(max_length=1000, verbose_name=_("Log text"))
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus
|
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus, Log
|
||||||
|
from fellchensammlung.tools.misc import is_404
|
||||||
|
|
||||||
|
|
||||||
def clean_locations(quiet=True):
|
def clean_locations(quiet=True):
|
||||||
@ -60,6 +63,22 @@ def get_unchecked_adoption_notices(weeks=3):
|
|||||||
return active_unchecked_adoptions
|
return active_unchecked_adoptions
|
||||||
|
|
||||||
|
|
||||||
|
def get_active_adoption_notices():
|
||||||
|
ans = AdoptionNotice.objects.all()
|
||||||
|
active_adoptions = [adoption for adoption in ans if adoption.is_active]
|
||||||
|
return active_adoptions
|
||||||
|
|
||||||
|
|
||||||
def deactivate_unchecked_adoption_notices():
|
def deactivate_unchecked_adoption_notices():
|
||||||
for adoption_notice in get_unchecked_adoption_notices(weeks=3):
|
for adoption_notice in get_unchecked_adoption_notices(weeks=3):
|
||||||
AdoptionNoticeStatus.objects.get(adoption_notice=adoption_notice).set_unchecked()
|
AdoptionNoticeStatus.objects.get(adoption_notice=adoption_notice).set_unchecked()
|
||||||
|
|
||||||
|
|
||||||
|
def deactivate_404_adoption_notices():
|
||||||
|
for adoption_notice in get_active_adoption_notices():
|
||||||
|
if adoption_notice.link_to_more_information != "":
|
||||||
|
if is_404(adoption_notice.link_to_more_information):
|
||||||
|
adoption_notice.set_closed()
|
||||||
|
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)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
__version__ = "0.3.0"
|
__version__ = "0.3.1"
|
||||||
|
|
||||||
# This will make sure the app is always imported when
|
# This will make sure the app is always imported when
|
||||||
# Django starts so that shared_task will use this app.
|
# Django starts so that shared_task will use this app.
|
||||||
|
Loading…
Reference in New Issue
Block a user