From d9232a109595fb0d65789634a41bf819ae8b8b88 Mon Sep 17 00:00:00 2001 From: moanos Date: Mon, 30 Sep 2024 15:22:19 +0200 Subject: [PATCH] feat: Add last checked to ANs and add updatequeue --- src/fellchensammlung/forms.py | 2 +- src/fellchensammlung/models.py | 14 ++++++++++++++ src/fellchensammlung/urls.py | 8 +++++--- src/fellchensammlung/views.py | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/fellchensammlung/forms.py b/src/fellchensammlung/forms.py index 02b963c..bbb1a03 100644 --- a/src/fellchensammlung/forms.py +++ b/src/fellchensammlung/forms.py @@ -32,7 +32,7 @@ class AdoptionNoticeForm(forms.ModelForm): submit = Submit('save-and-add-another-animal', _('Speichern')) else: - submit = Submit('submit', _('Sepichern')) + submit = Submit('submit', _('Speichern')) self.helper.layout = Layout( Fieldset( diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 32f644d..f40d03e 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -174,6 +174,7 @@ class AdoptionNotice(models.Model): return f"{self.name}" 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')) name = models.CharField(max_length=200) description = models.TextField(null=True, blank=True, verbose_name=_('Beschreibung')) @@ -273,6 +274,14 @@ class AdoptionNotice(models.Model): if not hasattr(self, 'adoptionnoticestatus'): return False 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): @@ -335,6 +344,11 @@ class AdoptionNoticeStatus(models.Model): def get_minor_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): MALE_NEUTERED = "M_N" diff --git a/src/fellchensammlung/urls.py b/src/fellchensammlung/urls.py index 64fc74e..1c580da 100644 --- a/src/fellchensammlung/urls.py +++ b/src/fellchensammlung/urls.py @@ -34,15 +34,17 @@ urlpatterns = [ path("ueber-uns/", views.about, name="about"), - ############# - ## Reports ## - ############# + ################ + ## Moderation ## + ################ path("vermittlung//report", views.report_adoption, name="report-adoption-notice"), path("kommentar//report", views.report_comment, name="report-comment"), path("meldung//", views.report_detail, name="report-detail"), path("meldung//sucess", views.report_detail_success, name="report-detail-success"), path("modqueue/", views.modqueue, name="modqueue"), + + path("updatequeue/", views.updatequeue, name="updatequeue"), ########### ## USERS ## diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 39cfa5e..ab2020b 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -423,6 +423,28 @@ def modqueue(request): context = {"reports": open_reports} 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): adoption_notices = AdoptionNotice.objects.all() #TODO: Filter to active