feat: Flatten status and use django form

This commit is contained in:
2025-11-29 11:27:30 +01:00
parent f9f35f9104
commit ad3511c086
7 changed files with 78 additions and 34 deletions

View File

@@ -10,7 +10,7 @@ from django.utils.translation import gettext_lazy as _
from notfellchen.settings import MEDIA_URL from notfellchen.settings import MEDIA_URL
from crispy_forms.layout import Div from crispy_forms.layout import Div
from .tools.model_helpers import reason_for_signup_label, reason_for_signup_help_text from .tools.model_helpers import reason_for_signup_label, reason_for_signup_help_text, AdoptionNoticeStatusChoices
def animal_validator(value: str): def animal_validator(value: str):
@@ -184,3 +184,15 @@ class RescueOrgSearchForm(forms.Form):
location_string = forms.CharField(max_length=100, label=_("Stadt"), required=False) location_string = forms.CharField(max_length=100, label=_("Stadt"), required=False)
max_distance = forms.ChoiceField(choices=DistanceChoices, initial=DistanceChoices.TWENTY, max_distance = forms.ChoiceField(choices=DistanceChoices, initial=DistanceChoices.TWENTY,
label=_("Suchradius")) label=_("Suchradius"))
class CloseAdoptionNoticeForm(forms.ModelForm):
template_name = "fellchensammlung/forms/form_snippets.html"
adoption_notice_status = forms.ChoiceField(choices=AdoptionNoticeStatusChoices.Closed,
label=_("Status"),
help_text=_("Gib den neuen Status der Vermittlung an"))
class Meta:
model = AdoptionNotice
fields = ('adoption_notice_status',)

View File

@@ -0,0 +1,23 @@
# Generated by Django 5.2.8 on 2025-11-29 09:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fellchensammlung', '0071_historicaladoptionnotice_historicalanimal_and_more'),
]
operations = [
migrations.AlterField(
model_name='adoptionnotice',
name='adoption_notice_status',
field=models.TextField(choices=[('active_searching', 'Searching'), ('active_interested', 'Interested'), ('awaiting_action_waiting_for_review', 'Waiting for review'), ('awaiting_action_needs_additional_info', 'Needs additional info'), ('awaiting_action_unchecked', 'Unchecked'), ('closed_successfully', 'Erfolgreich vermittelt'), ('closed_animal_died', 'Tier gestorben'), ('closed_for_other_adoption_notice', 'Vermittlung wurde zugunsten einer anderen geschlossen.'), ('closed_not_open_for_adoption_anymore', 'Tier(e) stehen nicht mehr zur Vermittlung bereit.'), ('closed_link_to_more_info_not_reachable', 'Der Link zu weiteren Informationen ist nicht mehr erreichbar.'), ('closed_other', 'Anderes'), ('disabled_against_the_rules', 'Against the rules'), ('disabled_other', 'Other (disabled)')], max_length=64, verbose_name='Status'),
),
migrations.AlterField(
model_name='historicaladoptionnotice',
name='adoption_notice_status',
field=models.TextField(choices=[('active_searching', 'Searching'), ('active_interested', 'Interested'), ('awaiting_action_waiting_for_review', 'Waiting for review'), ('awaiting_action_needs_additional_info', 'Needs additional info'), ('awaiting_action_unchecked', 'Unchecked'), ('closed_successfully', 'Erfolgreich vermittelt'), ('closed_animal_died', 'Tier gestorben'), ('closed_for_other_adoption_notice', 'Vermittlung wurde zugunsten einer anderen geschlossen.'), ('closed_not_open_for_adoption_anymore', 'Tier(e) stehen nicht mehr zur Vermittlung bereit.'), ('closed_link_to_more_info_not_reachable', 'Der Link zu weiteren Informationen ist nicht mehr erreichbar.'), ('closed_other', 'Anderes'), ('disabled_against_the_rules', 'Against the rules'), ('disabled_other', 'Other (disabled)')], max_length=64, verbose_name='Status'),
),
]

View File

@@ -0,0 +1,23 @@
import logging
from django.db import migrations
def migrate_status(apps, schema_editor):
# We can't import the model directly as it may be a newer
# version than this migration expects. We use the historical version.
AdoptionNotice = apps.get_model("fellchensammlung", "AdoptionNotice")
for adoption_notice in AdoptionNotice.objects.filter(
adoption_notice_status__in=("closed_successful_without_notfellchen", "closed_successful_with_notfellchen")):
adoption_notice.adoption_notice_status = "closed_successful"
adoption_notice.save()
class Migration(migrations.Migration):
dependencies = [
('fellchensammlung', '0072_alter_adoptionnotice_adoption_notice_status_and_more'),
]
operations = [
migrations.RunPython(migrate_status),
]

View File

@@ -6,21 +6,7 @@
<h1 class="title is-1">{% translate 'Vermittlung deaktivieren' %}</h1> <h1 class="title is-1">{% translate 'Vermittlung deaktivieren' %}</h1>
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
<div class="field"> {{ form }}
<label class="label" for="reason_for_closing">{% translate 'Warum schließt du die Vermittlung?' %}</label>
<div class="control">
<div class="select">
<select id="reason_for_closing" name="reason_for_closing">
<option value="closed_successful_with_notfellchen">{% translate 'Vermittelt mit Hilfe von Notfellchen' %}</option>
<option value="closed_successful_without_notfellchen">{% translate 'Vermittelt ohne Hilfe von Notfellchen' %}</option>
<option value="closed_for_other_adoption_notice">{% translate 'Vermittlung zugunsten einer anderen geschlossen' %}</option>
<option value="closed_not_open_for_adoption_anymore">{% translate 'Nicht mehr zu vermitteln (z.B. aufgrund von Krankheit)' %}</option>
<option value="closed_animal_died">{% translate 'Tod des Tiers' %}</option>
<option value="closed_other">{% translate 'Anderer Grund' %}</option>
</select>
</div>
</div>
</div>
<input class="button is-warning" type="submit" value="{% translate "Vermittlung deaktivieren" %}"> <input class="button is-warning" type="submit" value="{% translate "Vermittlung deaktivieren" %}">
</form> </form>
{% endblock %} {% endblock %}

View File

@@ -69,14 +69,14 @@ class AdoptionNoticeStatusChoices:
UNCHECKED = "awaiting_action_unchecked", _("Unchecked") UNCHECKED = "awaiting_action_unchecked", _("Unchecked")
class Closed(TextChoices): class Closed(TextChoices):
SUCCESSFUL_WITH_NOTFELLCHEN = "closed_successful_with_notfellchen", _("Successful (with Notfellchen)") SUCCESSFUL = "closed_successfully", _("Erfolgreich vermittelt")
SUCCESSFUL_WITHOUT_NOTFELLCHEN = "closed_successful_without_notfellchen", _("Successful (without Notfellchen)") ANIMAL_DIED = "closed_animal_died", _("Tier gestorben")
ANIMAL_DIED = "closed_animal_died", _("Animal died") FOR_OTHER_ADOPTION_NOTICE = ("closed_for_other_adoption_notice",
FOR_OTHER_ADOPTION_NOTICE = "closed_for_other_adoption_notice", _("Closed for other adoption notice") _("Vermittlung wurde zugunsten einer anderen geschlossen."))
NOT_OPEN_ANYMORE = "closed_not_open_for_adoption_anymore", _("Not open for adoption anymore") NOT_OPEN_ANYMORE = "closed_not_open_for_adoption_anymore", _("Tier(e) stehen nicht mehr zur Vermittlung bereit.")
LINK_TO_MORE_INFO_NOT_REACHABLE = "closed_link_to_more_info_not_reachable", _( LINK_TO_MORE_INFO_NOT_REACHABLE = "closed_link_to_more_info_not_reachable", _(
"Der Link zu weiteren Informationen ist nicht mehr erreichbar.") "Der Link zu weiteren Informationen ist nicht mehr erreichbar.")
OTHER = "closed_other", _("Other (closed)") OTHER = "closed_other", _("Anderes")
class Disabled(TextChoices): class Disabled(TextChoices):
AGAINST_RULES = "disabled_against_the_rules", _("Against the rules") AGAINST_RULES = "disabled_against_the_rules", _("Against the rules")
@@ -97,8 +97,7 @@ class AdoptionNoticeStatusChoicesDescriptions:
_ansc = AdoptionNoticeStatusChoices # Mapping for readability _ansc = AdoptionNoticeStatusChoices # Mapping for readability
mapping = {_ansc.Active.SEARCHING.value: "", mapping = {_ansc.Active.SEARCHING.value: "",
_ansc.Active.INTERESTED: _("Jemand hat bereits Interesse an den Tieren."), _ansc.Active.INTERESTED: _("Jemand hat bereits Interesse an den Tieren."),
_ansc.Closed.SUCCESSFUL_WITH_NOTFELLCHEN: _("Vermittlung erfolgreich abgeschlossen."), _ansc.Closed.SUCCESSFUL: _("Vermittlung erfolgreich abgeschlossen."),
_ansc.Closed.SUCCESSFUL_WITHOUT_NOTFELLCHEN: _("Vermittlung erfolgreich abgeschlossen."),
_ansc.Closed.ANIMAL_DIED: _("Die zu vermittelnden Tiere sind über die Regenbrücke gegangen."), _ansc.Closed.ANIMAL_DIED: _("Die zu vermittelnden Tiere sind über die Regenbrücke gegangen."),
_ansc.Closed.FOR_OTHER_ADOPTION_NOTICE: _("Vermittlung wurde zugunsten einer anderen geschlossen."), _ansc.Closed.FOR_OTHER_ADOPTION_NOTICE: _("Vermittlung wurde zugunsten einer anderen geschlossen."),
_ansc.Closed.NOT_OPEN_ANYMORE: _("Tier(e) stehen nicht mehr zur Vermittlung bereit."), _ansc.Closed.NOT_OPEN_ANYMORE: _("Tier(e) stehen nicht mehr zur Vermittlung bereit."),

View File

@@ -41,7 +41,7 @@ urlpatterns = [
# ex: /adoption_notice/2/add-animal # ex: /adoption_notice/2/add-animal
path("vermittlung/<int:adoption_notice_id>/add-animal", views.adoption_notice_add_animal, path("vermittlung/<int:adoption_notice_id>/add-animal", views.adoption_notice_add_animal,
name="adoption-notice-add-animal"), name="adoption-notice-add-animal"),
path("vermittlung/<int:adoption_notice_id>/close", views.deactivate_an, path("vermittlung/<int:adoption_notice_id>/close", views.close_adoption_notice,
name="adoption-notice-close"), name="adoption-notice-close"),
path("tierschutzorganisationen/", views.list_rescue_organizations, name="rescue-organizations"), path("tierschutzorganisationen/", views.list_rescue_organizations, name="rescue-organizations"),

View File

@@ -25,7 +25,7 @@ from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, Moderatio
ImportantLocation, SpeciesSpecificURL, NotificationTypeChoices, SocialMediaPost ImportantLocation, SpeciesSpecificURL, NotificationTypeChoices, SocialMediaPost
from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, \ from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, \
CommentForm, ReportCommentForm, AnimalForm, AdoptionNoticeFormAutoAnimal, SpeciesURLForm, RescueOrgInternalComment, \ CommentForm, ReportCommentForm, AnimalForm, AdoptionNoticeFormAutoAnimal, SpeciesURLForm, RescueOrgInternalComment, \
UpdateRescueOrgRegularCheckStatus, UserModCommentForm UpdateRescueOrgRegularCheckStatus, UserModCommentForm, CloseAdoptionNoticeForm
from .models import Language, Announcement from .models import Language, Announcement
from .tools import i18n, img from .tools import i18n, img
from .tools.fedi import post_an_to_fedi from .tools.fedi import post_an_to_fedi
@@ -1026,16 +1026,17 @@ def moderation_tools_overview(request):
return render(request, 'fellchensammlung/mod-tool-overview.html', context=context) return render(request, 'fellchensammlung/mod-tool-overview.html', context=context)
def deactivate_an(request, adoption_notice_id): def close_adoption_notice(request, adoption_notice_id):
adoption_notice = get_object_or_404(AdoptionNotice, pk=adoption_notice_id) adoption_notice = get_object_or_404(AdoptionNotice, pk=adoption_notice_id)
if request.method == "POST": if request.method == "POST":
reason_for_closing = request.POST.get("reason_for_closing") form = CloseAdoptionNoticeForm(request.POST, instance=adoption_notice)
if reason_for_closing not in AdoptionNoticeStatusChoices.Closed.values: if form.is_valid():
return render(request, "fellchensammlung/errors/403.html", status=403) form.save()
adoption_notice.adoption_notice_status = reason_for_closing return redirect(reverse("adoption-notice-detail", args=[adoption_notice.pk], ))
adoption_notice.save() else:
return redirect(reverse("adoption-notice-detail", args=[adoption_notice.pk], )) form = CloseAdoptionNoticeForm(instance=adoption_notice)
context = {"adoption_notice": adoption_notice, } context = {"adoption_notice": adoption_notice, "form": form}
return render(request, 'fellchensammlung/misc/deactivate-an.html', context=context) return render(request, 'fellchensammlung/misc/deactivate-an.html', context=context)