feat: Add form for internal comment in dq view

This commit is contained in:
2025-06-22 17:35:36 +02:00
parent aabc549bcf
commit fe92d762be
4 changed files with 64 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
from django import forms from django import forms
from .models import AdoptionNotice, Animal, Image, ReportAdoptionNotice, ReportComment, ModerationAction, User, Species, \ from .models import AdoptionNotice, Animal, Image, ReportAdoptionNotice, ReportComment, ModerationAction, User, Species, \
Comment, SexChoicesWithAll, DistanceChoices, SpeciesSpecificURL Comment, SexChoicesWithAll, DistanceChoices, SpeciesSpecificURL, RescueOrganization
from django_registration.forms import RegistrationForm from django_registration.forms import RegistrationForm
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field, Hidden from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field, Hidden
@@ -117,6 +117,12 @@ class SpeciesURLForm(forms.ModelForm):
fields = ('species', 'url') fields = ('species', 'url')
class RescueOrgInternalComment(forms.ModelForm):
class Meta:
model = RescueOrganization
fields = ('internal_comment',)
class ModerationActionForm(forms.ModelForm): class ModerationActionForm(forms.ModelForm):
class Meta: class Meta:
model = ModerationAction model = ModerationAction

View File

@@ -10,28 +10,45 @@
</div> </div>
<div class="card-content"> <div class="card-content">
<p> <div class="block">
<strong>{% translate 'Zuletzt geprüft:' %}</strong> {{ rescue_org.last_checked_hr }} <p>
</p> <strong>{% translate 'Zuletzt geprüft:' %}</strong> {{ rescue_org.last_checked_hr }}
{% if rescue_org.website %} </p>
<a href="{{ rescue_org.website }}" target="_blank"> {% if rescue_org.website %}
<i class="fas fa-globe" aria-label="{% translate "Website" %}"></i> <a href="{{ rescue_org.website }}" target="_blank">
{{ rescue_org.website|domain }} <i class="fas fa-globe" aria-label="{% translate "Website" %}"></i>
</a> {{ rescue_org.website|domain }}
</a>
{% endif %}
{% for species_url in rescue_org.species_urls %}
<p>{{ species_url.species }}: <a href="{{ species_url.url }}" target="_blank">{{ species_url.url }}</a>
</p>
{% endfor %}
</div>
{% if set_internal_comment_avilable %}
<div class="block">
<form method="post">
{% csrf_token %}
{{ comment_forms|dictkey:rescue_org.id }}
<input type="hidden" name="rescue_organization_id" value="{{ rescue_org.id }}">
<input type="hidden" name="action" value="update_internal_comment">
<button class="button is-primary" type="submit">{% trans 'Kommentar speichern' %}</button>
</form>
</div>
{% endif %} {% endif %}
{% for species_url in rescue_org.species_urls %} <div class="block">
<p>{{ species_url.species }}: <a href="{{ species_url.url }}" target="_blank">{{ species_url.url }}</a></p>
{% endfor %}
{% if set_species_url_available %}
<form method="POST"> {% if set_species_url_available %}
{% csrf_token %}
<input type="hidden" name="action" value="set_species_url"> <form method="POST">
<input type="hidden" name="rescue_organization_id" value={{ rescue_org.id }}> {% csrf_token %}
{{ species_url_form }} <input type="hidden" name="action" value="set_species_url">
<input type="submit" class="button is-primary" value="{% trans 'Speichern' %}"> <input type="hidden" name="rescue_organization_id" value={{ rescue_org.id }}>
</form> {{ species_url_form }}
{% endif %} <input type="submit" class="button is-primary" value="{% trans 'Speichern' %}">
</form>
{% endif %}
</div>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<div class="card-footer-item is-confirm"> <div class="card-footer-item is-confirm">

View File

@@ -103,3 +103,8 @@ def type_to_bulma_class(value):
@register.simple_tag @register.simple_tag
def trust_level(level_string): def trust_level(level_string):
return getattr(TrustLevel, level_string) return getattr(TrustLevel, level_string)
@register.filter
def dictkey(d, key):
return d.get(key)

View File

@@ -21,7 +21,7 @@ from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, Moderatio
Species, Log, Timestamp, TrustLevel, SexChoicesWithAll, SearchSubscription, AdoptionNoticeNotification, \ Species, Log, Timestamp, TrustLevel, SexChoicesWithAll, SearchSubscription, AdoptionNoticeNotification, \
ImportantLocation, SpeciesSpecificURL ImportantLocation, SpeciesSpecificURL
from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, \ from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, \
CommentForm, ReportCommentForm, AnimalForm, AdoptionNoticeFormAutoAnimal, SpeciesURLForm CommentForm, ReportCommentForm, AnimalForm, AdoptionNoticeFormAutoAnimal, SpeciesURLForm, RescueOrgInternalComment
from .models import Language, Announcement from .models import Language, Announcement
from .tools import i18n from .tools import i18n
from .tools.geo import GeoAPI, zoom_level_for_radius from .tools.geo import GeoAPI, zoom_level_for_radius
@@ -713,20 +713,29 @@ def rescue_organization_check(request, context=None):
action = request.POST.get("action") action = request.POST.get("action")
if action == "checked": if action == "checked":
rescue_org.set_checked() rescue_org.set_checked()
if action == "exclude": elif action == "exclude":
rescue_org.set_exclusion_from_checks() rescue_org.set_exclusion_from_checks()
if action == "set_species_url": elif action == "set_species_url":
species_url_form = SpeciesURLForm(request.POST) species_url_form = SpeciesURLForm(request.POST)
if species_url_form.is_valid(): if species_url_form.is_valid():
species_url_instance = species_url_form.save(commit=False) species_url_instance = species_url_form.save(commit=False)
species_url_instance.rescue_organization_id = rescue_org.id species_url_instance.rescue_organization_id = rescue_org.id
species_url_instance.save() species_url_instance.save()
elif action == "update_internal_comment":
comment_form = RescueOrgInternalComment(request.POST, instance=rescue_org)
if comment_form.is_valid():
comment_form.save()
rescue_orgs_to_check = RescueOrganization.objects.filter(exclude_from_check=False).order_by("last_checked")[:10] rescue_orgs_to_check = RescueOrganization.objects.filter(exclude_from_check=False).order_by("last_checked")[:10]
# Prepare a form for each organization
comment_forms = {
org.id: RescueOrgInternalComment(instance=org) for org in rescue_orgs_to_check
}
rescue_orgs_last_checked = RescueOrganization.objects.filter().order_by("-last_checked")[:10] rescue_orgs_last_checked = RescueOrganization.objects.filter().order_by("-last_checked")[:10]
context["rescue_orgs_to_check"] = rescue_orgs_to_check context["rescue_orgs_to_check"] = rescue_orgs_to_check
context["rescue_orgs_last_checked"] = rescue_orgs_last_checked context["rescue_orgs_last_checked"] = rescue_orgs_last_checked
context["comment_forms"] = comment_forms
return render(request, 'fellchensammlung/rescue-organization-check.html', context=context) return render(request, 'fellchensammlung/rescue-organization-check.html', context=context)
@@ -737,7 +746,9 @@ def rescue_organization_check_dq(request):
DQ = data quality DQ = data quality
""" """
context = {"set_species_url_available": True, context = {"set_species_url_available": True,
"species_url_form": SpeciesURLForm} "set_internal_comment_avilable": True,
"species_url_form": SpeciesURLForm,
"internal_comment_form": RescueOrgInternalComment}
return rescue_organization_check(request, context) return rescue_organization_check(request, context)