summaryrefslogtreecommitdiff
path: root/ishtar/furnitures/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar/furnitures/forms.py')
-rw-r--r--ishtar/furnitures/forms.py45
1 files changed, 40 insertions, 5 deletions
diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py
index c393bb3df..f152d27e4 100644
--- a/ishtar/furnitures/forms.py
+++ b/ishtar/furnitures/forms.py
@@ -21,6 +21,7 @@
Forms definition
"""
import datetime
+import re
from django.core.urlresolvers import reverse
from django.core import validators
@@ -176,7 +177,7 @@ class Wizard(NamedUrlSessionFormWizard):
if key.startswith('hidden_'):
continue
value = form.cleaned_data[key]
- if key in associated_models:
+ if key in associated_models and value:
value = associated_models[key].objects.get(pk=value)
dct[key] = value
dct = self.get_extra_model(dct, request, storage, form_list)
@@ -362,6 +363,44 @@ class Wizard(NamedUrlSessionFormWizard):
initial.append(vals)
return initial
+def get_now():
+ format = formats.get_format('DATE_INPUT_FORMATS')[0]
+ value = datetime.datetime.now().strftime(format)
+ return value
+
+regexp_name = re.compile(r'^[\w\- ]+$', re.UNICODE)
+name_validator = validators.RegexValidator(regexp_name,
+_(u"Enter a valid name consisting of letters, spaces and hyphens."), 'invalid')
+
+class PersonWizard(Wizard):
+ model = models.Person
+
+class PersonForm(forms.Form):
+ form_label = _("Identity")
+ associated_models = {'attached_to':models.Organization,
+ 'person_type':models.PersonType}
+ title = forms.ChoiceField(label=_("Title"), choices=models.Person.TYPE)
+ surname = forms.CharField(label=_(u"Surname"), max_length=20,
+ validators=[name_validator])
+ name = forms.CharField(label=_(u"Name"), max_length=30,
+ validators=[name_validator])
+ email = forms.CharField(label=_(u"Email"), max_length=40,
+ validators=[validators.validate_email])
+ person_type = forms.ChoiceField(label=_("Person type"),
+ choices=models.PersonType.get_types())
+ attached_to = forms.IntegerField(label=_("Current organization"),
+ widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-organization'),
+ associated_model=models.Organization),
+ validators=[models.valid_id(models.Organization)], required=False)
+ is_author = forms.NullBooleanField(label=_(u"Is an author?"),
+ required=False)
+ in_charge_storage = forms.NullBooleanField(required=False,
+ label=_(u"In charge of a storage?"))
+
+person_creation_wizard = PersonWizard([
+ ('identity-person_creation', PersonForm),
+ ('final-person_creation', FinalForm)],
+ url_name='person_creation',)
class FileWizard(Wizard):
model = models.File
@@ -438,10 +477,6 @@ class FileWizard(Wizard):
parcel.save()
return res
-def get_now():
- format = formats.get_format('DATE_INPUT_FORMATS')[0]
- value = datetime.datetime.now().strftime(format)
- return value
class FileFormSelection(forms.Form):
form_label = _("Archaelogical file")