feat: rework status and add correct one to adoption notices

This commit is contained in:
moanos [he/him] 2024-06-08 12:32:57 +02:00
parent d14b88e99d
commit bbb2d33840
4 changed files with 35 additions and 21 deletions

View File

@ -101,10 +101,10 @@ class Command(BaseCommand):
User.objects.create_user('test', password='foobar')
admin1 = User.objects.create_superuser(username="admin", password="admin", email="admin1@example.org",
trust_level=User.ADMIN)
trust_level=User.TRUST_LEVEL[User.ADMIN])
mod1 = User.objects.create_user(username="mod1", password="mod", email="mod1@example.org",
trust_level=User.MODERATOR)
trust_level=User.TRUST_LEVEL[User.MODERATOR])
comment1 = baker.make(Comment, user=admin1, text="This is a comment", adoption_notice=adoption1)
comment2 = baker.make(Comment,

View File

@ -1,4 +1,4 @@
# Generated by Django 5.0.6 on 2024-06-08 07:08
# Generated by Django 5.0.6 on 2024-06-08 10:13
import datetime
import django.contrib.auth.models
@ -254,15 +254,14 @@ class Migration(migrations.Migration):
),
(
"trust_level",
models.CharField(
models.IntegerField(
choices=[
("admin", "Administrator*in"),
("Moderator", "Moderator*in"),
("Koordinator*in", "Koordinator*in"),
("Mitglied", "Mitglied"),
("admin", 4),
("Moderator", 3),
("Koordinator*in", 2),
("Mitglied", 1),
],
default="Mitglied",
max_length=100,
default=1,
),
),
(
@ -399,7 +398,7 @@ class Migration(migrations.Migration):
models.CharField(
choices=[
("active", "active"),
("in_review", "in review"),
("awaiting_action", "in review"),
("closed", "closed"),
("disabled", "disabled"),
],
@ -413,6 +412,7 @@ class Migration(migrations.Migration):
("searching", "searching"),
("interested", "interested"),
("waiting_for_review", "waiting_for_review"),
("needs_additional_info", "needs_additional_info"),
(
"successful_with_notfellchen",
"successful_with_notfellchen",

View File

@ -50,16 +50,16 @@ class User(AbstractUser):
MODERATOR = "Moderator"
COORDINATOR = "Koordinator*in"
MEMBER = "Mitglied"
TRUES_LEVEL = {
ADMIN: "Administrator*in",
MODERATOR: "Moderator*in",
COORDINATOR: "Koordinator*in",
MEMBER: "Mitglied",
TRUST_LEVEL = {
ADMIN: 4,
MODERATOR: 3,
COORDINATOR: 2,
MEMBER: 1,
}
preferred_language = models.ForeignKey(Language, on_delete=models.PROTECT, null=True, blank=True,
verbose_name=_('Bevorzugte Sprache'))
trust_level = models.CharField(choices=TRUES_LEVEL, max_length=100, default=MEMBER)
trust_level = models.IntegerField(choices=TRUST_LEVEL, default=TRUST_LEVEL[MEMBER])
class Meta:
verbose_name = _('Nutzer*in')
@ -246,12 +246,12 @@ class AdoptionNoticeStatus(models.Model):
"""
ACTIVE = "active"
IN_REVIEW = "in_review"
AWAITING_ACTION = "awaiting_action"
CLOSED = "closed"
DISABLED = "disabled"
MAJOR_STATUS_CHOICES = {
ACTIVE: "active",
IN_REVIEW: "in review",
AWAITING_ACTION: "in review",
CLOSED: "closed",
DISABLED: "disabled",
}
@ -261,8 +261,9 @@ class AdoptionNoticeStatus(models.Model):
"searching": "searching",
"interested": "interested",
},
IN_REVIEW: {
AWAITING_ACTION: {
"waiting_for_review": "waiting_for_review",
"needs_additional_info": "needs_additional_info",
},
CLOSED: {
"successful_with_notfellchen": "successful_with_notfellchen",

View File

@ -116,7 +116,7 @@ def search(request):
@login_required
def add_adoption_notice(request):
if request.method == 'POST':
form = AdoptionNoticeForm(request.POST, request.FILES, in_adoption_notice_creation_flow=True)
form = AdoptionNoticeFormWithDateWidget(request.POST, request.FILES, in_adoption_notice_creation_flow=True)
if form.is_valid():
instance = form.save(commit=False)
@ -126,6 +126,19 @@ def add_adoption_notice(request):
instance.location = location
instance.save()
# Set correct status
if request.user.trust_level >= User.TRUST_LEVEL[User.COORDINATOR]:
status = AdoptionNoticeStatus.objects.create(major_status=AdoptionNoticeStatus.ACTIVE,
minor_status=AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.ACTIVE]["searching"],
adoption_notice=instance)
status.save()
else:
status = AdoptionNoticeStatus.objects.create(major_status=AdoptionNoticeStatus.AWAITING_ACTION,
minor_status=AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.AWAITING_ACTION][
"waiting_for_review"],
adoption_notice=instance)
status.save()
return redirect(reverse("adoption-notice-add-animal", args=[instance.pk]))
else:
form = AdoptionNoticeFormWithDateWidget(in_adoption_notice_creation_flow=True)