diff options
| author | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-01-15 12:26:35 +0100 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2011-01-15 12:26:35 +0100 | 
| commit | 3e0796a88f231f07d41a8a182eb82f8baf1b0ba6 (patch) | |
| tree | 5a0ad2c3921e7b7a95f5ad3bd71823ed2f16736b | |
| parent | d9b82554ab1f42691c992c2eac932b47e93e3ab7 (diff) | |
| download | Ishtar-3e0796a88f231f07d41a8a182eb82f8baf1b0ba6.tar.bz2 Ishtar-3e0796a88f231f07d41a8a182eb82f8baf1b0ba6.zip | |
Creation of person (refs #20)
| -rw-r--r-- | ishtar/furnitures/forms.py | 45 | ||||
| -rw-r--r-- | ishtar/furnitures/menus.py | 5 | ||||
| -rw-r--r-- | ishtar/furnitures/urls.py | 5 | ||||
| -rw-r--r-- | ishtar/furnitures/views.py | 5 | 
4 files changed, 53 insertions, 7 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") diff --git a/ishtar/furnitures/menus.py b/ishtar/furnitures/menus.py index bfa04e0bf..5b03e0156 100644 --- a/ishtar/furnitures/menus.py +++ b/ishtar/furnitures/menus.py @@ -58,6 +58,11 @@ class Menu:          self.user = user          self.initialized = False          self.childs = [ +        SectionItem('administration', _(u"Administration"), +            childs=[ +                MenuItem('person_creation', _(u"Person creation"), +                    access_controls=['add_person', 'add_own_person']), +            ]),          SectionItem('file_management', _(u"File management"),              childs=[                  MenuItem('file_creation', _(u"File creation"), diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py index abbe93e35..75759c9aa 100644 --- a/ishtar/furnitures/urls.py +++ b/ishtar/furnitures/urls.py @@ -22,11 +22,14 @@ from django.conf.urls.defaults import *  from ishtar.urls import BASE_URL  from menus import menu  from forms import file_creation_wizard, file_modification_wizard,\ -                  operation_creation_wizard, operation_modification_wizard +                  operation_creation_wizard, operation_modification_wizard,\ +                  person_creation_wizard  urlpatterns, actions = [], []  urlpatterns = patterns('', +         url(BASE_URL + r'person_creation/(?P<step>.+)$', +                        person_creation_wizard, name='person_creation'),           url(BASE_URL + r'file_creation/(?P<step>.+)$', file_creation_wizard,                                               name='file_creation'),           url(BASE_URL + r'file_modification/(?P<step>.+)$', diff --git a/ishtar/furnitures/views.py b/ishtar/furnitures/views.py index 5a2ba12e4..defb2a0a2 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -33,7 +33,8 @@ from django.core import serializers  from ishtar import settings  from menus import menu  from forms import file_creation_wizard, file_modification_wizard, \ -                  operation_creation_wizard, operation_modification_wizard +                  operation_creation_wizard, operation_modification_wizard, \ +                  person_creation_wizard  import models  def index(request): @@ -171,6 +172,8 @@ def action(request, action_slug, obj_id=None, *args, **kwargs):      return render_to_response('index.html', dct,                                context_instance=RequestContext(request)) +def person_creation(request, dct, obj_id, *args, **kwargs): +    return person_creation_wizard(request, *args, **kwargs)  def file_creation(request, dct, obj_id, *args, **kwargs):      return file_creation_wizard(request, *args, **kwargs) | 
