34 lines
1.5 KiB
Python
34 lines
1.5 KiB
Python
from django import forms
|
|
from django.utils.translation import gettext_lazy as _
|
|
from .models import FieldNote
|
|
|
|
|
|
class FieldNoteForm(forms.ModelForm):
|
|
class Meta:
|
|
model = FieldNote
|
|
fields = ["content", "category", "source_type", "verification_status", "visibility", "observed_at"]
|
|
widgets = {
|
|
"content": forms.Textarea(attrs={"rows": 3, "placeholder": _("What did you observe or learn?")}),
|
|
"observed_at": forms.DateTimeInput(format="%Y-%m-%dT%H:%M", attrs={"type": "datetime-local"}),
|
|
}
|
|
labels = {"content": _("Note"), "observed_at": _("Observed at (optional)"),
|
|
"category": _("Category"), "source_type": _("Source"),
|
|
"verification_status": _("Verification status"), "visibility": _("Visibility")}
|
|
help_texts = {
|
|
"visibility": _("Private by default. Reportable permits authorised export; it does not mean verified or public."),
|
|
"observed_at": _("Local time (Europe/Amsterdam). The entry time is recorded separately."),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
for name in self.fields:
|
|
if name != "content":
|
|
self.fields[name].required = False
|
|
|
|
def clean(self):
|
|
data = super().clean()
|
|
for name in ("category", "source_type", "verification_status", "visibility"):
|
|
if not data.get(name):
|
|
data[name] = FieldNote._meta.get_field(name).get_default()
|
|
return data
|