From 0e36237890323aa808f55c801b10ce79bac12590 Mon Sep 17 00:00:00 2001 From: moanos Date: Fri, 5 Sep 2025 16:07:21 +0200 Subject: [PATCH] feat: Add adoption notice template for contacting a person directly --- .../0063_adoptionnotice_adoption_process.py | 18 ++++++++++++++++++ src/fellchensammlung/models.py | 5 ++++- .../adoption_process/contact_person_in_an.html | 7 +++++++ src/fellchensammlung/tools/model_helpers.py | 15 +++++++++++++-- src/fellchensammlung/views.py | 11 +++++++++-- 5 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/fellchensammlung/migrations/0063_adoptionnotice_adoption_process.py create mode 100644 src/fellchensammlung/templates/fellchensammlung/partials/adoption_process/contact_person_in_an.html diff --git a/src/fellchensammlung/migrations/0063_adoptionnotice_adoption_process.py b/src/fellchensammlung/migrations/0063_adoptionnotice_adoption_process.py new file mode 100644 index 0000000..7546de9 --- /dev/null +++ b/src/fellchensammlung/migrations/0063_adoptionnotice_adoption_process.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.1 on 2025-09-05 14:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0062_alter_adoptionnotice_adoption_notice_status_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='adoptionnotice', + name='adoption_process', + field=models.TextField(blank=True, choices=[('contact_person_in_an', 'Kontaktiere die Person im Vermittlungstext')], max_length=64, null=True, verbose_name='Adoptionsprozess'), + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 51d79f1..c12a932 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -11,7 +11,7 @@ from .tools import misc, geo from notfellchen.settings import MEDIA_URL, base_url from .tools.geo import LocationProxy, Position from .tools.misc import time_since_as_hr_string -from .tools.model_helpers import NotificationTypeChoices, AdoptionNoticeStatusChoices +from .tools.model_helpers import NotificationTypeChoices, AdoptionNoticeStatusChoices, AdoptionProcess from .tools.model_helpers import ndm as NotificationDisplayMapping @@ -391,6 +391,9 @@ class AdoptionNotice(models.Model): owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('Creator')) adoption_notice_status = models.TextField(max_length=64, verbose_name=_('Status'), choices=AdoptionNoticeStatusChoices.all_choices()) + adoption_process = models.TextField(null=True, blank=True, + max_length=64, verbose_name=_('Adoptionsprozess'), + choices=AdoptionProcess) @property def animals(self): diff --git a/src/fellchensammlung/templates/fellchensammlung/partials/adoption_process/contact_person_in_an.html b/src/fellchensammlung/templates/fellchensammlung/partials/adoption_process/contact_person_in_an.html new file mode 100644 index 0000000..93291c1 --- /dev/null +++ b/src/fellchensammlung/templates/fellchensammlung/partials/adoption_process/contact_person_in_an.html @@ -0,0 +1,7 @@ +{% load i18n %} + +
+ {% translate 'Kontaktiere die Person mit den Kontaktdaten in der Beschreibung.' %} +
+ + diff --git a/src/fellchensammlung/tools/model_helpers.py b/src/fellchensammlung/tools/model_helpers.py index 3149cb7..a1b7f24 100644 --- a/src/fellchensammlung/tools/model_helpers.py +++ b/src/fellchensammlung/tools/model_helpers.py @@ -94,7 +94,7 @@ class AdoptionNoticeStatusChoices: class AdoptionNoticeStatusChoicesDescriptions: - _ansc = AdoptionNoticeStatusChoices # Mapping for readability + _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."), @@ -104,10 +104,21 @@ class AdoptionNoticeStatusChoicesDescriptions: _ansc.Closed.NOT_OPEN_ANYMORE: _("Tier(e) stehen nicht mehr zur Vermittlung bereit."), _ansc.Closed.OTHER: _("Vermittlung geschlossen."), - _ansc.AwaitingAction.WAITING_FOR_REVIEW: _("Deaktiviert bis Moderator*innen die Vermittlung prüfen können."), + _ansc.AwaitingAction.WAITING_FOR_REVIEW: _( + "Deaktiviert bis Moderator*innen die Vermittlung prüfen können."), _ansc.AwaitingAction.NEEDS_ADDITIONAL_INFO: _("Deaktiviert bis Informationen nachgetragen werden."), _ansc.Disabled.AGAINST_RULES: _("Vermittlung deaktiviert da sie gegen die Regeln verstößt."), _ansc.Disabled.UNCHECKED: _("Vermittlung deaktiviert bis sie vom Team auf Aktualität geprüft wurde."), _ansc.Disabled.OTHER: _("Vermittlung deaktiviert.") } + + +class AdoptionProcess(TextChoices): + CONTACT_PERSON_IN_AN = "contact_person_in_an", _("Kontaktiere die Person im Vermittlungstext") + + +class AdoptionNoticeProcessTemplates: + _bp = "fellchensammlung/partials/adoption_process/" # Base path for ease + mapping = {AdoptionProcess.CONTACT_PERSON_IN_AN: f"{_bp}contact_person_in_an.html", + } diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 7fa068a..b00df49 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -36,7 +36,7 @@ from .tools.admin import clean_locations, get_unchecked_adoption_notices, deacti from .tasks import post_adoption_notice_save from rest_framework.authtoken.models import Token -from .tools.model_helpers import AdoptionNoticeStatusChoices +from .tools.model_helpers import AdoptionNoticeStatusChoices, AdoptionNoticeProcessTemplates from .tools.search import AdoptionNoticeSearch, RescueOrgSearch @@ -170,10 +170,17 @@ def adoption_notice_detail(request, adoption_notice_id): return HttpResponseForbidden() else: comment_form = CommentForm(instance=adoption_notice) + + # Set the adoption notice template, use default when not set + if adoption_notice.adoption_process is not None: + adoption_process_template = AdoptionNoticeProcessTemplates.mapping[adoption_notice.adoption_process] + else: + adoption_process_template = "fellchensammlung/partials/adoption_process/generic.html" + context = {"adoption_notice": adoption_notice, "comment_form": comment_form, "user": request.user, "has_edit_permission": has_edit_permission, "is_subscribed": is_subscribed, "adoption_notice_meta": adoption_notice_meta, - "adoption_process_template": "fellchensammlung/partials/adoption_process/generic.html", + "adoption_process_template": adoption_process_template, "oxitraffic_base_url": settings.OXITRAFFIC_BASE_URL} return render(request, 'fellchensammlung/details/detail-adoption-notice.html', context=context)