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