refactor: Adjust status changes
This commit is contained in:
parent
64024be833
commit
d59cc0034a
@ -292,11 +292,6 @@ class AdoptionNotice(models.Model):
|
||||
return False
|
||||
return self.adoptionnoticestatus.is_to_be_checked or (include_active and self.adoptionnoticestatus.is_active)
|
||||
|
||||
def set_checked(self):
|
||||
self.last_checked = timezone.now()
|
||||
self.set_active()
|
||||
self.save()
|
||||
|
||||
def set_closed(self):
|
||||
self.last_checked = timezone.now()
|
||||
self.adoptionnoticestatus.set_closed()
|
||||
@ -307,11 +302,11 @@ class AdoptionNotice(models.Model):
|
||||
AdoptionNoticeStatus.create_other(self)
|
||||
self.adoptionnoticestatus.set_active()
|
||||
|
||||
def set_to_review(self):
|
||||
def set_unchecked(self):
|
||||
self.last_checked = timezone.now()
|
||||
if not hasattr(self, 'adoptionnoticestatus'):
|
||||
AdoptionNoticeStatus.create_other(self)
|
||||
self.adoptionnoticestatus.set_to_review()
|
||||
self.adoptionnoticestatus.set_unchecked()
|
||||
|
||||
|
||||
class AdoptionNoticeStatus(models.Model):
|
||||
@ -393,7 +388,7 @@ class AdoptionNoticeStatus(models.Model):
|
||||
self.minor_status = self.MINOR_STATUS_CHOICES[self.CLOSED]["other"]
|
||||
self.save()
|
||||
|
||||
def deactivate_unchecked(self):
|
||||
def set_unchecked(self):
|
||||
self.major_status = self.MAJOR_STATUS_CHOICES[self.DISABLED]
|
||||
self.minor_status = self.MINOR_STATUS_CHOICES[self.DISABLED]["unchecked"]
|
||||
self.save()
|
||||
@ -403,11 +398,6 @@ class AdoptionNoticeStatus(models.Model):
|
||||
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):
|
||||
|
@ -62,4 +62,4 @@ def get_unchecked_adoption_notices(weeks=3):
|
||||
|
||||
def deactivate_unchecked_adoption_notices():
|
||||
for adoption_notice in get_unchecked_adoption_notices(weeks=3):
|
||||
AdoptionNoticeStatus.objects.get(adoption_notice=adoption_notice).deactivate_unchecked()
|
||||
AdoptionNoticeStatus.objects.get(adoption_notice=adoption_notice).set_unchecked()
|
||||
|
@ -207,7 +207,7 @@ def add_adoption_notice(request):
|
||||
if request.user.trust_level >= User.TRUST_LEVEL[User.COORDINATOR]:
|
||||
instance.set_active()
|
||||
else:
|
||||
instance.set_to_review()
|
||||
instance.set_unchecked()
|
||||
|
||||
# Get the species and number of animals from the form
|
||||
species = form.cleaned_data["species"]
|
||||
@ -449,22 +449,18 @@ def modqueue(request):
|
||||
def updatequeue(request):
|
||||
#TODO: Make sure update can only be done for instances with permission
|
||||
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 action == "checked_active":
|
||||
adoption_notice.set_active()
|
||||
|
||||
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 or adoption.is_to_be_checked]
|
||||
|
||||
context = {"adoption_notices": adoption_notices}
|
||||
return render(request, 'fellchensammlung/updatequeue.html', context=context)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user