-
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]>
- Loading branch information
1 parent
127d22a
commit afbd95d
Showing
20 changed files
with
813 additions
and
107 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,106 @@ | ||
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", | ||
"email_from_location", | ||
"phone_number", | ||
"phone_number_from_location", | ||
"website", | ||
"website_from_location", | ||
] | ||
|
||
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() | ||
|
||
email_from_location = self.data.get("email_from_location", None) | ||
phone_number_from_location = self.data.get("phone_number_from_location", None) | ||
website_from_location = self.data.get("website_from_location", None) | ||
|
||
if related_location is None: | ||
self.add_error( | ||
None, | ||
forms.ValidationError( | ||
_("Location cannot be empty."), | ||
code="invalid", | ||
), | ||
) | ||
else: | ||
if email_from_location and not self.data["email"] == related_location.email: | ||
self.add_error( | ||
"email", | ||
forms.ValidationError( | ||
_( | ||
"E-mail address does not match with that of the selected location. Please check again." | ||
), | ||
code="invalid", | ||
), | ||
) | ||
if ( | ||
phone_number_from_location | ||
and not self.data["phone_number"] == related_location.phone_number | ||
): | ||
self.add_error( | ||
"phone_number", | ||
forms.ValidationError( | ||
_( | ||
"Phone number does not match with that of the selected location. Please check again." | ||
), | ||
code="invalid", | ||
), | ||
) | ||
if ( | ||
website_from_location | ||
and not self.data["website"] == related_location.website | ||
): | ||
self.add_error( | ||
"website", | ||
forms.ValidationError( | ||
_( | ||
"Website URL does not match with that of the selected location. Please check again." | ||
), | ||
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,66 @@ | ||
# 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", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="contact", | ||
name="email_from_location", | ||
field=models.BooleanField( | ||
default=True, | ||
help_text="Will be taken over from the location.", | ||
verbose_name="E-mail from location", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="contact", | ||
name="phone_number_from_location", | ||
field=models.BooleanField( | ||
default=True, | ||
help_text="Will be taken over from the location.", | ||
verbose_name="phone number from location", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="contact", | ||
name="website_from_location", | ||
field=models.BooleanField( | ||
default=True, | ||
help_text="Will be taken over from the location.", | ||
verbose_name="website from 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
Oops, something went wrong.