d4ec85add4
Add independent map profiles, offline city lookup, bundled world artwork and collision-free portrait placement with optional person details. Deploy with updated requirements, migrations 0029-0031 and collectstatic.
55 lines
2.2 KiB
Python
55 lines
2.2 KiB
Python
from django import forms
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from .contact_uploads import validate_contact_attachments
|
|
from .models import ContactSubmission, MapMembership
|
|
|
|
|
|
class ContactForm(forms.ModelForm):
|
|
attachments = forms.Field(required=False)
|
|
|
|
class Meta:
|
|
model = ContactSubmission
|
|
fields = ["name", "title", "description", "email"]
|
|
widgets = {
|
|
"name": forms.TextInput(
|
|
attrs={"placeholder": "Your full name", "autocomplete": "name"}
|
|
),
|
|
"title": forms.TextInput(attrs={"placeholder": "Subject / topic"}),
|
|
"description": forms.Textarea(
|
|
attrs={"placeholder": "Write your message here…", "rows": 5}
|
|
),
|
|
"email": forms.EmailInput(
|
|
attrs={
|
|
"placeholder": "your@email.com (optional)",
|
|
"autocomplete": "email",
|
|
}
|
|
),
|
|
}
|
|
|
|
def __init__(self, *args, file_list=None, **kwargs):
|
|
self.file_list = file_list
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def clean(self):
|
|
cleaned_data = super().clean()
|
|
try:
|
|
cleaned_data["attachments"] = validate_contact_attachments(self.file_list)
|
|
except ValidationError as exc:
|
|
self.add_error("attachments", exc)
|
|
cleaned_data["attachments"] = []
|
|
return cleaned_data
|
|
|
|
|
|
class MapMembershipAdminForm(forms.ModelForm):
|
|
class Meta:
|
|
model = MapMembership
|
|
fields = "__all__"
|
|
help_texts = {
|
|
"location_method": "City mode calculates coordinates on save. Choose Coordinates to set latitude and longitude yourself.",
|
|
"country": "For city lookup, enter an English country name or ISO code, e.g. Canada / CA. Optional location label in Coordinates mode.",
|
|
"city": "Required in city mode. Unknown, small or ambiguous towns can be placed using Coordinates mode instead.",
|
|
"latitude": "Coordinates mode: -90 to 90. In city mode this value is calculated from the country and city on save.",
|
|
"longitude": "Coordinates mode: -180 to 180. In city mode this value is calculated from the country and city on save.",
|
|
}
|