diff --git a/src/fellchensammlung/forms.py b/src/fellchensammlung/forms.py index 3e59f1d..8038c90 100644 --- a/src/fellchensammlung/forms.py +++ b/src/fellchensammlung/forms.py @@ -10,7 +10,7 @@ from django.utils.translation import gettext_lazy as _ from notfellchen.settings import MEDIA_URL 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): @@ -184,3 +184,15 @@ class RescueOrgSearchForm(forms.Form): location_string = forms.CharField(max_length=100, label=_("Stadt"), required=False) max_distance = forms.ChoiceField(choices=DistanceChoices, initial=DistanceChoices.TWENTY, 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',) diff --git a/src/fellchensammlung/migrations/0072_alter_adoptionnotice_adoption_notice_status_and_more.py b/src/fellchensammlung/migrations/0072_alter_adoptionnotice_adoption_notice_status_and_more.py new file mode 100644 index 0000000..4a87593 --- /dev/null +++ b/src/fellchensammlung/migrations/0072_alter_adoptionnotice_adoption_notice_status_and_more.py @@ -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'), + ), + ] diff --git a/src/fellchensammlung/migrations/0073_adoption_notice_status_successful.py b/src/fellchensammlung/migrations/0073_adoption_notice_status_successful.py new file mode 100644 index 0000000..77fd31d --- /dev/null +++ b/src/fellchensammlung/migrations/0073_adoption_notice_status_successful.py @@ -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), + ] diff --git a/src/fellchensammlung/templates/fellchensammlung/misc/deactivate-an.html b/src/fellchensammlung/templates/fellchensammlung/misc/deactivate-an.html index feeb03a..45268c0 100644 --- a/src/fellchensammlung/templates/fellchensammlung/misc/deactivate-an.html +++ b/src/fellchensammlung/templates/fellchensammlung/misc/deactivate-an.html @@ -6,21 +6,7 @@

{% translate 'Vermittlung deaktivieren' %}

{% csrf_token %} -
- -
-
- -
-
-
+ {{ form }}
{% endblock %} \ No newline at end of file diff --git a/src/fellchensammlung/tools/model_helpers.py b/src/fellchensammlung/tools/model_helpers.py index d5509fd..aa661b2 100644 --- a/src/fellchensammlung/tools/model_helpers.py +++ b/src/fellchensammlung/tools/model_helpers.py @@ -69,14 +69,14 @@ class AdoptionNoticeStatusChoices: UNCHECKED = "awaiting_action_unchecked", _("Unchecked") class Closed(TextChoices): - SUCCESSFUL_WITH_NOTFELLCHEN = "closed_successful_with_notfellchen", _("Successful (with Notfellchen)") - SUCCESSFUL_WITHOUT_NOTFELLCHEN = "closed_successful_without_notfellchen", _("Successful (without Notfellchen)") - ANIMAL_DIED = "closed_animal_died", _("Animal died") - FOR_OTHER_ADOPTION_NOTICE = "closed_for_other_adoption_notice", _("Closed for other adoption notice") - NOT_OPEN_ANYMORE = "closed_not_open_for_adoption_anymore", _("Not open for adoption anymore") + SUCCESSFUL = "closed_successfully", _("Erfolgreich vermittelt") + ANIMAL_DIED = "closed_animal_died", _("Tier gestorben") + FOR_OTHER_ADOPTION_NOTICE = ("closed_for_other_adoption_notice", + _("Vermittlung wurde zugunsten einer anderen geschlossen.")) + 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", _( "Der Link zu weiteren Informationen ist nicht mehr erreichbar.") - OTHER = "closed_other", _("Other (closed)") + OTHER = "closed_other", _("Anderes") class Disabled(TextChoices): AGAINST_RULES = "disabled_against_the_rules", _("Against the rules") @@ -97,8 +97,7 @@ class AdoptionNoticeStatusChoicesDescriptions: _ansc = AdoptionNoticeStatusChoices # Mapping for readability mapping = {_ansc.Active.SEARCHING.value: "", _ansc.Active.INTERESTED: _("Jemand hat bereits Interesse an den Tieren."), - _ansc.Closed.SUCCESSFUL_WITH_NOTFELLCHEN: _("Vermittlung erfolgreich abgeschlossen."), - _ansc.Closed.SUCCESSFUL_WITHOUT_NOTFELLCHEN: _("Vermittlung erfolgreich abgeschlossen."), + _ansc.Closed.SUCCESSFUL: _("Vermittlung erfolgreich abgeschlossen."), _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.NOT_OPEN_ANYMORE: _("Tier(e) stehen nicht mehr zur Vermittlung bereit."), diff --git a/src/fellchensammlung/urls.py b/src/fellchensammlung/urls.py index cf24cc4..ca391f3 100644 --- a/src/fellchensammlung/urls.py +++ b/src/fellchensammlung/urls.py @@ -41,7 +41,7 @@ urlpatterns = [ # ex: /adoption_notice/2/add-animal path("vermittlung//add-animal", views.adoption_notice_add_animal, name="adoption-notice-add-animal"), - path("vermittlung//close", views.deactivate_an, + path("vermittlung//close", views.close_adoption_notice, name="adoption-notice-close"), path("tierschutzorganisationen/", views.list_rescue_organizations, name="rescue-organizations"), diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 8fd66f6..d6e8d4a 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -25,7 +25,7 @@ from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, Moderatio ImportantLocation, SpeciesSpecificURL, NotificationTypeChoices, SocialMediaPost from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, \ CommentForm, ReportCommentForm, AnimalForm, AdoptionNoticeFormAutoAnimal, SpeciesURLForm, RescueOrgInternalComment, \ - UpdateRescueOrgRegularCheckStatus, UserModCommentForm + UpdateRescueOrgRegularCheckStatus, UserModCommentForm, CloseAdoptionNoticeForm from .models import Language, Announcement from .tools import i18n, img 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) -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) if request.method == "POST": - reason_for_closing = request.POST.get("reason_for_closing") - if reason_for_closing not in AdoptionNoticeStatusChoices.Closed.values: - return render(request, "fellchensammlung/errors/403.html", status=403) - adoption_notice.adoption_notice_status = reason_for_closing - adoption_notice.save() - return redirect(reverse("adoption-notice-detail", args=[adoption_notice.pk], )) - context = {"adoption_notice": adoption_notice, } + form = CloseAdoptionNoticeForm(request.POST, instance=adoption_notice) + if form.is_valid(): + form.save() + return redirect(reverse("adoption-notice-detail", args=[adoption_notice.pk], )) + else: + form = CloseAdoptionNoticeForm(instance=adoption_notice) + context = {"adoption_notice": adoption_notice, "form": form} + return render(request, 'fellchensammlung/misc/deactivate-an.html', context=context)