From efecfc910d12ddbe1fbcf873bd97d38c9a790424 Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 29 Oct 2024 06:52:43 +0100 Subject: [PATCH] feat: Add shortcut for setting status --- src/fellchensammlung/models.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index c3ceaea..eff78ed 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -301,6 +301,18 @@ class AdoptionNotice(models.Model): self.last_checked = datetime.now() self.adoptionnoticestatus.set_closed() + def set_active(self): + self.last_checked = datetime.now() + if not hasattr(self, 'adoptionnoticestatus'): + AdoptionNoticeStatus.create_other(self) + self.adoptionnoticestatus.set_active() + + def set_to_review(self): + self.last_checked = datetime.now() + if not hasattr(self, 'adoptionnoticestatus'): + AdoptionNoticeStatus.create_other(self) + self.adoptionnoticestatus.set_to_review() + class AdoptionNoticeStatus(models.Model): """ @@ -367,6 +379,15 @@ class AdoptionNoticeStatus(models.Model): def get_minor_choices(major_status): return AdoptionNoticeStatus.MINOR_STATUS_CHOICES[major_status] + @staticmethod + def create_other(an_instance): + # Used as empty status to be changed immediately + major_status = AdoptionNoticeStatus.DISABLED + minor_status = AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.DISABLED]["other"] + AdoptionNoticeStatus.objects.create(major_status=major_status, + minor_status=minor_status, + adoption_notice=an_instance) + def set_closed(self): self.major_status = self.MAJOR_STATUS_CHOICES[self.CLOSED] self.minor_status = self.MINOR_STATUS_CHOICES[self.CLOSED]["other"] @@ -377,6 +398,17 @@ class AdoptionNoticeStatus(models.Model): self.minor_status = self.MINOR_STATUS_CHOICES[self.DISABLED]["unchecked"] self.save() + def set_active(self): + self.major_status = self.MAJOR_STATUS_CHOICES[self.ACTIVE] + self.minor_status = self.MINOR_STATUS_CHOICES[self.ACTIVE]["searching"] + self.save() + + def set_to_review(self): + self.major_status = AdoptionNoticeStatus.AWAITING_ACTION + self.minor_status = AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.AWAITING_ACTION][ + "waiting_for_review"] + self.save() + class Animal(models.Model): MALE_NEUTERED = "M_N"