feat: Add form for internal comment in dq view
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from django import forms
|
||||
|
||||
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 crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field, Hidden
|
||||
@@ -117,6 +117,12 @@ class SpeciesURLForm(forms.ModelForm):
|
||||
fields = ('species', 'url')
|
||||
|
||||
|
||||
class RescueOrgInternalComment(forms.ModelForm):
|
||||
class Meta:
|
||||
model = RescueOrganization
|
||||
fields = ('internal_comment',)
|
||||
|
||||
|
||||
class ModerationActionForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = ModerationAction
|
||||
|
@@ -10,28 +10,45 @@
|
||||
</div>
|
||||
|
||||
<div class="card-content">
|
||||
<p>
|
||||
<strong>{% translate 'Zuletzt geprüft:' %}</strong> {{ rescue_org.last_checked_hr }}
|
||||
</p>
|
||||
{% if rescue_org.website %}
|
||||
<a href="{{ rescue_org.website }}" target="_blank">
|
||||
<i class="fas fa-globe" aria-label="{% translate "Website" %}"></i>
|
||||
{{ rescue_org.website|domain }}
|
||||
</a>
|
||||
<div class="block">
|
||||
<p>
|
||||
<strong>{% translate 'Zuletzt geprüft:' %}</strong> {{ rescue_org.last_checked_hr }}
|
||||
</p>
|
||||
{% if rescue_org.website %}
|
||||
<a href="{{ rescue_org.website }}" target="_blank">
|
||||
<i class="fas fa-globe" aria-label="{% translate "Website" %}"></i>
|
||||
{{ 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 %}
|
||||
{% 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 %}
|
||||
{% if set_species_url_available %}
|
||||
<div class="block">
|
||||
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="set_species_url">
|
||||
<input type="hidden" name="rescue_organization_id" value={{ rescue_org.id }}>
|
||||
{{ species_url_form }}
|
||||
<input type="submit" class="button is-primary" value="{% trans 'Speichern' %}">
|
||||
</form>
|
||||
{% endif %}
|
||||
{% if set_species_url_available %}
|
||||
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="action" value="set_species_url">
|
||||
<input type="hidden" name="rescue_organization_id" value={{ rescue_org.id }}>
|
||||
{{ species_url_form }}
|
||||
<input type="submit" class="button is-primary" value="{% trans 'Speichern' %}">
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<div class="card-footer-item is-confirm">
|
||||
|
@@ -103,3 +103,8 @@ def type_to_bulma_class(value):
|
||||
@register.simple_tag
|
||||
def trust_level(level_string):
|
||||
return getattr(TrustLevel, level_string)
|
||||
|
||||
|
||||
@register.filter
|
||||
def dictkey(d, key):
|
||||
return d.get(key)
|
||||
|
@@ -21,7 +21,7 @@ from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, Moderatio
|
||||
Species, Log, Timestamp, TrustLevel, SexChoicesWithAll, SearchSubscription, AdoptionNoticeNotification, \
|
||||
ImportantLocation, SpeciesSpecificURL
|
||||
from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, \
|
||||
CommentForm, ReportCommentForm, AnimalForm, AdoptionNoticeFormAutoAnimal, SpeciesURLForm
|
||||
CommentForm, ReportCommentForm, AnimalForm, AdoptionNoticeFormAutoAnimal, SpeciesURLForm, RescueOrgInternalComment
|
||||
from .models import Language, Announcement
|
||||
from .tools import i18n
|
||||
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")
|
||||
if action == "checked":
|
||||
rescue_org.set_checked()
|
||||
if action == "exclude":
|
||||
elif action == "exclude":
|
||||
rescue_org.set_exclusion_from_checks()
|
||||
if action == "set_species_url":
|
||||
elif action == "set_species_url":
|
||||
species_url_form = SpeciesURLForm(request.POST)
|
||||
|
||||
if species_url_form.is_valid():
|
||||
species_url_instance = species_url_form.save(commit=False)
|
||||
species_url_instance.rescue_organization_id = rescue_org.id
|
||||
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]
|
||||
# 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]
|
||||
context["rescue_orgs_to_check"] = rescue_orgs_to_check
|
||||
context["rescue_orgs_last_checked"] = rescue_orgs_last_checked
|
||||
context["comment_forms"] = comment_forms
|
||||
return render(request, 'fellchensammlung/rescue-organization-check.html', context=context)
|
||||
|
||||
|
||||
@@ -737,7 +746,9 @@ def rescue_organization_check_dq(request):
|
||||
DQ = data quality
|
||||
"""
|
||||
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)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user