-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: David Venhoff <[email protected]> Co-authored-by: Peter Nerlich <[email protected]>
- Loading branch information
1 parent
c6975a1
commit 2d58236
Showing
23 changed files
with
695 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -958,7 +958,7 @@ | |
"fields": { | ||
"title": "Integrationsbeauftragte", | ||
"name": "Martina Musterfrau", | ||
"poi": 6, | ||
"location": 6, | ||
"email": "[email protected]", | ||
"phone_number": "0123456789", | ||
"website": "", | ||
|
@@ -973,7 +973,7 @@ | |
"fields": { | ||
"title": "Integrationsberaterin", | ||
"name": "Melanie Musterfrau", | ||
"poi": 6, | ||
"location": 6, | ||
"email": "[email protected]", | ||
"phone_number": "0987654321", | ||
"website": "www.random-page.com", | ||
|
@@ -988,7 +988,7 @@ | |
"fields": { | ||
"title": "Integrationsbeauftragte", | ||
"name": "Mariana Musterfrau", | ||
"poi": 6, | ||
"location": 6, | ||
"email": "[email protected]", | ||
"phone_number": "0123456789", | ||
"website": "https://integreat-app.de/", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
Forms for creating and modifying contact objects | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import TYPE_CHECKING | ||
|
||
from django import forms | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from ...models import Contact | ||
from ..custom_model_form import CustomModelForm | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ContactForm(CustomModelForm): | ||
""" | ||
Form for creating and modifying contact objects | ||
""" | ||
|
||
class Meta: | ||
""" | ||
This class contains additional meta configuration of the form class, see the :class:`django.forms.ModelForm` | ||
for more information. | ||
""" | ||
|
||
#: The model of this :class:`django.forms.ModelForm` | ||
model = Contact | ||
#: The fields of the model which should be handled by this form | ||
fields = [ | ||
"title", | ||
"name", | ||
"location", | ||
"email", | ||
"phone_number", | ||
"website", | ||
] | ||
|
||
def clean(self) -> dict[str, Any]: | ||
""" | ||
Validate the fields | ||
:return: The cleaned form data | ||
""" | ||
cleaned_data = super().clean() | ||
|
||
related_location = self.instance.region.pois.filter( | ||
id=self.data["location"] | ||
).first() | ||
|
||
if related_location is None: | ||
self.add_error( | ||
None, | ||
forms.ValidationError( | ||
_("Location cannot be empty."), | ||
code="invalid", | ||
), | ||
) | ||
|
||
return cleaned_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Generated by Django 4.2.13 on 2024-08-20 16:10 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
""" | ||
Make the field name not mandatory. | ||
Rename the field from "poi" to "location". | ||
Add new fields to save whether the information must be taken over from the location. | ||
""" | ||
|
||
dependencies = [ | ||
("cms", "0102_alter_contact_poi"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="contact", | ||
name="name", | ||
field=models.CharField(blank=True, max_length=200, verbose_name="name"), | ||
), | ||
migrations.RenameField( | ||
model_name="contact", | ||
old_name="poi", | ||
new_name="location", | ||
), | ||
migrations.AlterField( | ||
model_name="contact", | ||
name="location", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="contacts", | ||
to="cms.poi", | ||
verbose_name="location", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
{% extends "_base.html" %} | ||
{% load i18n %} | ||
{% load widget_tweaks %} | ||
{% block content %} | ||
{% with request.region.default_language as current_language %} | ||
<form id="content_form" | ||
method="post" | ||
enctype="multipart/form-data" | ||
data-unsaved-warning | ||
{% if contact_form.disabled %}data-disable-poi-query{% endif %}> | ||
{% csrf_token %} | ||
<div class="flex justify-between mb-4"> | ||
<h1 class="heading"> | ||
{% if contact_form.instance.id %} | ||
{% translate "Edit contact" %} | ||
{% else %} | ||
{% translate "Create new contact" %} | ||
{% endif %} | ||
</h1> | ||
<div class="flex flex-wrap justify-between gap-4"> | ||
{% if perms.cms.change_contact and not contact_form.instance.archived %} | ||
<div class="flex flex-wrap gap-4"> | ||
<button class="btn"> | ||
{% if contact_form.instance.id %} | ||
{% translate "Update" %} | ||
{% else %} | ||
{% translate "Create" %} | ||
{% endif %} | ||
</button> | ||
</div> | ||
{% endif %} | ||
</div> | ||
</div> | ||
<div class="grid xl:grid-cols-3 gap-4"> | ||
{% include "ajax_poi_form/poi_box.html" with form=contact_form box_id="contact-location" title=_("Connect a location") %} | ||
<div id="contact_fields" | ||
class="mb-4 rounded border border-solid border-blue-500 shadow-2xl bg-white {% if not contact_form.instance.id %}hidden{% endif %}"> | ||
<div class="p-4 rounded bg-water-500"> | ||
<h3 class="heading font-bold text-black"> | ||
<i icon-name="message-square" class="mr-2"></i> {% translate "Manage contact data" %} | ||
</h3> | ||
</div> | ||
<div class="p-4"> | ||
<div class="help-text mt-4 font-bold"> | ||
{% translate "Add missing data or change existing data. Select the data you want to import." %} | ||
</div> | ||
<label for="{{ contact_form.title.id_for_label }}"> | ||
{{ contact_form.title.label }} | ||
</label> | ||
{% render_field contact_form.title|add_error_class:"border-red-500" %} | ||
<label for="{{ contact_form.name.id_for_label }}"> | ||
{{ contact_form.name.label }} | ||
</label> | ||
{% render_field contact_form.name|add_error_class:"border-red-500" %} | ||
<label for="{{ contact_form.email.id_for_label }}"> | ||
{{ contact_form.email.label }} | ||
</label> | ||
{% render_field contact_form.email|add_error_class:"border-red-500" %} | ||
<label for="{{ contact_form.phone_number.id_for_label }}"> | ||
{{ contact_form.phone_number.label }} | ||
</label> | ||
{% render_field contact_form.phone_number|add_error_class:"border-red-500" %} | ||
<label for="{{ contact_form.website.id_for_label }}"> | ||
{{ contact_form.website.label }} | ||
</label> | ||
{% render_field contact_form.website|add_error_class:"border-red-500" %} | ||
</div> | ||
</div> | ||
{% if contact_form.instance.id %} | ||
<div id="contact_usage" | ||
class="mb-4 rounded border border-solid border-blue-500 shadow-2xl bg-white"> | ||
<div class="p-4 rounded bg-water-500"> | ||
<h3 class="heading font-bold text-black"> | ||
<i icon-name="message-square" class="mr-2"></i> {% translate "Contact information" %} | ||
</h3> | ||
</div> | ||
<div class="p-4"> | ||
<div class="help-text mt-4 font-bold"> | ||
{% trans "This contact is referred to in those contents." %} | ||
</div> | ||
</div> | ||
{% include "../_related_contents_table.html" with contents=referring_pages table_title=_("Pages") no_content_message=_("This contact is not currently referred to on any page.") %} | ||
{% include "../_related_contents_table.html" with contents=referring_locations table_title=_("Locations") no_content_message=_("This contact is not currently referred to in any location.") %} | ||
{% include "../_related_contents_table.html" with contents=referring_events table_title=_("Events") no_content_message=_("This contact is not currently referred to in any event.") %} | ||
</div> | ||
{% endif %} | ||
</div> | ||
{% if contact_form.instance.id %} | ||
<div class="flex flex-wrap grow justify-end gap-2 items-center"> | ||
{% if perms.cms.change_contact and not contact_form.instance.archived %} | ||
<button title="{% translate "Archive contact" %}" | ||
class="btn confirmation-button btn-blue" | ||
data-confirmation-title="{{ archive_dialog_title }}" | ||
data-confirmation-text="{{ archive_dialog_text }}" | ||
data-confirmation-subject="{{ contact_form.instance.name }}" | ||
data-action="{% url 'archive_contact' contact_id=contact_form.instance.id region_slug=request.region.slug %}"> | ||
<i icon-name="archive" class="mr-2"></i> | ||
{% translate "Archive this contact" %} | ||
</button> | ||
{% endif %} | ||
{% if perms.cms.change_contact and contact_form.instance.archived %} | ||
<button title="{% translate "Restore page" %}" | ||
class="btn confirmation-button btn-blue" | ||
data-confirmation-title="{{ restore_dialog_title }}" | ||
data-confirmation-text="{{ restore_dialog_text }}" | ||
data-confirmation-subject="{{ contact_form.instance.name }}" | ||
data-action="{% url 'restore_contact' contact_id=contact_form.instance.id region_slug=request.region.slug %}"> | ||
<i icon-name="refresh-ccw" class="mr-2"></i> {% translate "Restore this contact" %} | ||
</button> | ||
{% endif %} | ||
{% if perms.cms.delete_contact %} | ||
<div class="flex flex-wrap gap-4"> | ||
<button title="{% translate "Delete contact" %}" | ||
class="btn confirmation-button btn-red" | ||
data-confirmation-title="{{ delete_dialog_title }}" | ||
data-confirmation-text="{{ delete_dialog_text }}" | ||
data-confirmation-subject="{{ contact_form.instance.name }}" | ||
data-action="{% url 'delete_contact' contact_id=contact_form.instance.id region_slug=request.region.slug %}"> | ||
<i icon-name="trash-2" class="mr-2"></i> | ||
{% translate "Delete contact" %} | ||
</button> | ||
</div> | ||
{% endif %} | ||
</div> | ||
{% endif %} | ||
</form> | ||
<form id="ajax_poi_form" | ||
name="ajax_poi_form" | ||
method="post" | ||
enctype="multipart/form-data" | ||
data-unsaved-warning> | ||
</form> | ||
{% include "generic_confirmation_dialog.html" %} | ||
{% endwith %} | ||
{% endblock content %} |
Oops, something went wrong.