feat: rework status and add correct one to adoption notices
This commit is contained in:
parent
d14b88e99d
commit
bbb2d33840
@ -101,10 +101,10 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
User.objects.create_user('test', password='foobar')
|
User.objects.create_user('test', password='foobar')
|
||||||
admin1 = User.objects.create_superuser(username="admin", password="admin", email="admin1@example.org",
|
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",
|
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)
|
comment1 = baker.make(Comment, user=admin1, text="This is a comment", adoption_notice=adoption1)
|
||||||
comment2 = baker.make(Comment,
|
comment2 = baker.make(Comment,
|
||||||
|
@ -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 datetime
|
||||||
import django.contrib.auth.models
|
import django.contrib.auth.models
|
||||||
@ -254,15 +254,14 @@ class Migration(migrations.Migration):
|
|||||||
),
|
),
|
||||||
(
|
(
|
||||||
"trust_level",
|
"trust_level",
|
||||||
models.CharField(
|
models.IntegerField(
|
||||||
choices=[
|
choices=[
|
||||||
("admin", "Administrator*in"),
|
("admin", 4),
|
||||||
("Moderator", "Moderator*in"),
|
("Moderator", 3),
|
||||||
("Koordinator*in", "Koordinator*in"),
|
("Koordinator*in", 2),
|
||||||
("Mitglied", "Mitglied"),
|
("Mitglied", 1),
|
||||||
],
|
],
|
||||||
default="Mitglied",
|
default=1,
|
||||||
max_length=100,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
@ -399,7 +398,7 @@ class Migration(migrations.Migration):
|
|||||||
models.CharField(
|
models.CharField(
|
||||||
choices=[
|
choices=[
|
||||||
("active", "active"),
|
("active", "active"),
|
||||||
("in_review", "in review"),
|
("awaiting_action", "in review"),
|
||||||
("closed", "closed"),
|
("closed", "closed"),
|
||||||
("disabled", "disabled"),
|
("disabled", "disabled"),
|
||||||
],
|
],
|
||||||
@ -413,6 +412,7 @@ class Migration(migrations.Migration):
|
|||||||
("searching", "searching"),
|
("searching", "searching"),
|
||||||
("interested", "interested"),
|
("interested", "interested"),
|
||||||
("waiting_for_review", "waiting_for_review"),
|
("waiting_for_review", "waiting_for_review"),
|
||||||
|
("needs_additional_info", "needs_additional_info"),
|
||||||
(
|
(
|
||||||
"successful_with_notfellchen",
|
"successful_with_notfellchen",
|
||||||
"successful_with_notfellchen",
|
"successful_with_notfellchen",
|
||||||
|
@ -50,16 +50,16 @@ class User(AbstractUser):
|
|||||||
MODERATOR = "Moderator"
|
MODERATOR = "Moderator"
|
||||||
COORDINATOR = "Koordinator*in"
|
COORDINATOR = "Koordinator*in"
|
||||||
MEMBER = "Mitglied"
|
MEMBER = "Mitglied"
|
||||||
TRUES_LEVEL = {
|
TRUST_LEVEL = {
|
||||||
ADMIN: "Administrator*in",
|
ADMIN: 4,
|
||||||
MODERATOR: "Moderator*in",
|
MODERATOR: 3,
|
||||||
COORDINATOR: "Koordinator*in",
|
COORDINATOR: 2,
|
||||||
MEMBER: "Mitglied",
|
MEMBER: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
preferred_language = models.ForeignKey(Language, on_delete=models.PROTECT, null=True, blank=True,
|
preferred_language = models.ForeignKey(Language, on_delete=models.PROTECT, null=True, blank=True,
|
||||||
verbose_name=_('Bevorzugte Sprache'))
|
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:
|
class Meta:
|
||||||
verbose_name = _('Nutzer*in')
|
verbose_name = _('Nutzer*in')
|
||||||
@ -246,12 +246,12 @@ class AdoptionNoticeStatus(models.Model):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
ACTIVE = "active"
|
ACTIVE = "active"
|
||||||
IN_REVIEW = "in_review"
|
AWAITING_ACTION = "awaiting_action"
|
||||||
CLOSED = "closed"
|
CLOSED = "closed"
|
||||||
DISABLED = "disabled"
|
DISABLED = "disabled"
|
||||||
MAJOR_STATUS_CHOICES = {
|
MAJOR_STATUS_CHOICES = {
|
||||||
ACTIVE: "active",
|
ACTIVE: "active",
|
||||||
IN_REVIEW: "in review",
|
AWAITING_ACTION: "in review",
|
||||||
CLOSED: "closed",
|
CLOSED: "closed",
|
||||||
DISABLED: "disabled",
|
DISABLED: "disabled",
|
||||||
}
|
}
|
||||||
@ -261,8 +261,9 @@ class AdoptionNoticeStatus(models.Model):
|
|||||||
"searching": "searching",
|
"searching": "searching",
|
||||||
"interested": "interested",
|
"interested": "interested",
|
||||||
},
|
},
|
||||||
IN_REVIEW: {
|
AWAITING_ACTION: {
|
||||||
"waiting_for_review": "waiting_for_review",
|
"waiting_for_review": "waiting_for_review",
|
||||||
|
"needs_additional_info": "needs_additional_info",
|
||||||
},
|
},
|
||||||
CLOSED: {
|
CLOSED: {
|
||||||
"successful_with_notfellchen": "successful_with_notfellchen",
|
"successful_with_notfellchen": "successful_with_notfellchen",
|
||||||
|
@ -116,7 +116,7 @@ def search(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def add_adoption_notice(request):
|
def add_adoption_notice(request):
|
||||||
if request.method == 'POST':
|
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():
|
if form.is_valid():
|
||||||
instance = form.save(commit=False)
|
instance = form.save(commit=False)
|
||||||
@ -126,6 +126,19 @@ def add_adoption_notice(request):
|
|||||||
instance.location = location
|
instance.location = location
|
||||||
instance.save()
|
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]))
|
return redirect(reverse("adoption-notice-add-animal", args=[instance.pk]))
|
||||||
else:
|
else:
|
||||||
form = AdoptionNoticeFormWithDateWidget(in_adoption_notice_creation_flow=True)
|
form = AdoptionNoticeFormWithDateWidget(in_adoption_notice_creation_flow=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user