feat: Add last checked to ANs and add updatequeue

This commit is contained in:
moanos [he/him] 2024-09-30 15:22:19 +02:00
parent 022bf577d4
commit d9232a1095
4 changed files with 42 additions and 4 deletions

View File

@ -32,7 +32,7 @@ class AdoptionNoticeForm(forms.ModelForm):
submit = Submit('save-and-add-another-animal', _('Speichern')) submit = Submit('save-and-add-another-animal', _('Speichern'))
else: else:
submit = Submit('submit', _('Sepichern')) submit = Submit('submit', _('Speichern'))
self.helper.layout = Layout( self.helper.layout = Layout(
Fieldset( Fieldset(

View File

@ -174,6 +174,7 @@ class AdoptionNotice(models.Model):
return f"{self.name}" return f"{self.name}"
created_at = models.DateField(verbose_name=_('Erstellt am'), default=datetime.now) created_at = models.DateField(verbose_name=_('Erstellt am'), default=datetime.now)
last_checked = models.DateTimeField(verbose_name=_('Zuletzt überprüft am'), default=datetime.now)
searching_since = models.DateField(verbose_name=_('Sucht nach einem Zuhause seit')) searching_since = models.DateField(verbose_name=_('Sucht nach einem Zuhause seit'))
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
description = models.TextField(null=True, blank=True, verbose_name=_('Beschreibung')) description = models.TextField(null=True, blank=True, verbose_name=_('Beschreibung'))
@ -274,6 +275,14 @@ class AdoptionNotice(models.Model):
return False return False
return self.adoptionnoticestatus.is_active return self.adoptionnoticestatus.is_active
def set_checked(self):
self.last_checked = datetime.now()
self.save()
def set_closed(self):
self.last_checked = datetime.now()
self.adoptionnoticestatus.set_closed()
class AdoptionNoticeStatus(models.Model): class AdoptionNoticeStatus(models.Model):
""" """
@ -335,6 +344,11 @@ class AdoptionNoticeStatus(models.Model):
def get_minor_choices(major_status): def get_minor_choices(major_status):
return AdoptionNoticeStatus.MINOR_STATUS_CHOICES[major_status] return AdoptionNoticeStatus.MINOR_STATUS_CHOICES[major_status]
def set_closed(self):
self.major_status = self.MAJOR_STATUS_CHOICES[self.CLOSED]
self.minor_status = self.MINOR_STATUS_CHOICES[self.CLOSED]["other"]
self.save()
class Animal(models.Model): class Animal(models.Model):
MALE_NEUTERED = "M_N" MALE_NEUTERED = "M_N"

View File

@ -34,9 +34,9 @@ urlpatterns = [
path("ueber-uns/", views.about, name="about"), path("ueber-uns/", views.about, name="about"),
############# ################
## Reports ## ## Moderation ##
############# ################
path("vermittlung/<int:adoption_notice_id>/report", views.report_adoption, name="report-adoption-notice"), path("vermittlung/<int:adoption_notice_id>/report", views.report_adoption, name="report-adoption-notice"),
path("kommentar/<int:comment_id>/report", views.report_comment, name="report-comment"), path("kommentar/<int:comment_id>/report", views.report_comment, name="report-comment"),
@ -44,6 +44,8 @@ urlpatterns = [
path("meldung/<uuid:report_id>/sucess", views.report_detail_success, name="report-detail-success"), path("meldung/<uuid:report_id>/sucess", views.report_detail_success, name="report-detail-success"),
path("modqueue/", views.modqueue, name="modqueue"), path("modqueue/", views.modqueue, name="modqueue"),
path("updatequeue/", views.updatequeue, name="updatequeue"),
########### ###########
## USERS ## ## USERS ##
########### ###########

View File

@ -423,6 +423,28 @@ def modqueue(request):
context = {"reports": open_reports} context = {"reports": open_reports}
return render(request, 'fellchensammlung/modqueue.html', context=context) return render(request, 'fellchensammlung/modqueue.html', context=context)
@login_required
def updatequeue(request):
if request.method == "POST":
print(request.POST.get("adoption_notice_id"))
adoption_notice = AdoptionNotice.objects.get(id=request.POST.get("adoption_notice_id"))
action = request.POST.get("action")
print(f"Action: {action}")
if action == "checked_inactive":
adoption_notice.set_closed()
elif action == "checked_active":
print("set checked")
adoption_notice.set_checked()
if user_is_trust_level_or_above(request.user, User.MODERATOR):
last_checked_adoption_list = AdoptionNotice.objects.order_by("last_checked")
else:
last_checked_adoption_list = AdoptionNotice.objects.filter(owner=request.user).order_by("last_checked")
adoption_notices = [adoption for adoption in last_checked_adoption_list if adoption.is_active]
context = {"adoption_notices": adoption_notices}
return render(request, 'fellchensammlung/updatequeue.html', context=context)
def map(request): def map(request):
adoption_notices = AdoptionNotice.objects.all() #TODO: Filter to active adoption_notices = AdoptionNotice.objects.all() #TODO: Filter to active