diff options
| -rw-r--r-- | ishtar/furnitures/forms.py | 63 | ||||
| -rw-r--r-- | ishtar/furnitures/menus.py | 2 | ||||
| -rw-r--r-- | ishtar/furnitures/models.py | 2 | ||||
| -rw-r--r-- | ishtar/furnitures/urls.py | 4 | ||||
| -rw-r--r-- | ishtar/furnitures/views.py | 5 | ||||
| -rw-r--r-- | ishtar/furnitures/widgets.py | 5 | 
6 files changed, 73 insertions, 8 deletions
| diff --git a/ishtar/furnitures/forms.py b/ishtar/furnitures/forms.py index f152d27e4..536c1c037 100644 --- a/ishtar/furnitures/forms.py +++ b/ishtar/furnitures/forms.py @@ -35,6 +35,7 @@ from django.db.models import Max  from django import forms  from django.forms.formsets import formset_factory, BaseFormSet, \                                    DELETION_FIELD_NAME +from django.contrib.auth.models import User  from formwizard.forms import NamedUrlSessionFormWizard @@ -129,6 +130,8 @@ class Wizard(NamedUrlSessionFormWizard):                      form_datas.append(("", "", "spacer"))                  for key in cleaned_data:                      lbl = None +                    if key.startswith('hidden_'): +                        continue                      if hasattr(base_form, 'fields') and key in base_form.fields:                          lbl = base_form.fields[key].label                      if not lbl: @@ -184,7 +187,7 @@ class Wizard(NamedUrlSessionFormWizard):          obj = self.get_current_object(request, storage)          if obj:              for k in dct: -                if k == 'pk': +                if k.startswith('pk'):                      continue                  setattr(obj, k, dct[k])          else: @@ -384,7 +387,7 @@ class PersonForm(forms.Form):                                validators=[name_validator])      name = forms.CharField(label=_(u"Name"), max_length=30,                                validators=[name_validator]) -    email = forms.CharField(label=_(u"Email"), max_length=40, +    email = forms.CharField(label=_(u"Email"), max_length=40, required=False,                              validators=[validators.validate_email])      person_type = forms.ChoiceField(label=_("Person type"),                                    choices=models.PersonType.get_types()) @@ -402,6 +405,60 @@ person_creation_wizard = PersonWizard([                          ('final-person_creation', FinalForm)],                           url_name='person_creation',) +class AccountWizard(Wizard): +    model = User +    def get_formated_datas(self, forms): +        datas = super(AccountWizard, self).get_formated_datas(forms) +        for form in forms: +            if not hasattr(form, "cleaned_data"): +                continue +            for key in form.cleaned_data: +                if key == 'hidden_password' and form.cleaned_data[key]: +                    datas[-1][1].append((_("New password"), "*"*8)) + +        return datas + +class PersonFormSelection(forms.Form): +    form_label = _("Person") +    associated_models = {'pk':models.Person} +    currents = {'pk':models.Person} +    pk = forms.IntegerField(label=_("Person"), +         widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-person'), +                                           associated_model=models.Person), +         validators=[models.valid_id(models.Person)]) + +class AccountForm(forms.Form): +    form_label = _("Account") +    pk = forms.IntegerField(widget=forms.HiddenInput, required=False) +    username = forms.CharField(label=_(u"Account"), max_length=30) +    email = forms.CharField(label=_(u"Email"), max_length=75, +                            validators=[validators.validate_email]) +    hidden_password = forms.CharField(label=_(u"New password"), max_length=128, + widget=forms.PasswordInput, required=False, + validators=[validators.MinLengthValidator(4)]) +    hidden_password_confirm = forms.CharField( +                label=_(u"New password (confirmation)"), max_length=128, +                widget=forms.PasswordInput, required=False) + +    def clean(self): +        cleaned_data = self.cleaned_data +        password = cleaned_data.get("hidden_password") +        if password and password != cleaned_data.get("hidden_password_confirm"): +            raise forms.ValidationError(_(u"Your password and confirmation " +"password do not match.")) +        if not cleaned_data.get("pk"): +            models.is_unique(User, 'username')(cleaned_data.get("username")) +            if not password: +                raise forms.ValidationError(_(u"You must provide a correct \ +password.")) +        return cleaned_data + +account_management_wizard = AccountWizard([ +                        ('selec-account_management', PersonFormSelection), +                        ('account-account_management', AccountForm), +                        ('final-account_management', FinalForm)], +                         url_name='account_management',) +  class FileWizard(Wizard):      model = models.File @@ -517,7 +574,7 @@ class FileFormGeneralRO(FileFormGeneral):      numeric_reference = forms.IntegerField(label=_("Numeric reference"),                          widget=forms.TextInput(attrs={'readonly':True}))      internal_reference = forms.CharField(label=_(u"Internal reference"), -                        widget=forms.TextInput(attrs={'readonly':True})) +                        widget=forms.TextInput(attrs={'readonly':True},))  class FileFormAddress(forms.Form):      form_label = _("Address") diff --git a/ishtar/furnitures/menus.py b/ishtar/furnitures/menus.py index 5b03e0156..63bb85d58 100644 --- a/ishtar/furnitures/menus.py +++ b/ishtar/furnitures/menus.py @@ -62,6 +62,8 @@ class Menu:              childs=[                  MenuItem('person_creation', _(u"Person creation"),                      access_controls=['add_person', 'add_own_person']), +                MenuItem('account_management', _(u"Account management"), +                    access_controls=['add_ishtaruser',]),              ]),          SectionItem('file_management', _(u"File management"),              childs=[ diff --git a/ishtar/furnitures/models.py b/ishtar/furnitures/models.py index 3863669e7..0b42249a7 100644 --- a/ishtar/furnitures/models.py +++ b/ishtar/furnitures/models.py @@ -167,7 +167,7 @@ class Person(Address, OwnPerms) :      title = models.CharField(_(u"Title"), max_length=2, choices=TYPE)      surname = models.CharField(_(u"Surname"), max_length=20)      name = models.CharField(_(u"Name"), max_length=30) -    email = models.CharField(_(u"Email"), max_length=40) +    email = models.CharField(_(u"Email"), max_length=40, blank=True, null=True)      person_type = models.ForeignKey(PersonType, verbose_name=_(u"Type"))      attached_to = models.ForeignKey('Organization',                         verbose_name=_(u"Is attached to"), blank=True, null=True) diff --git a/ishtar/furnitures/urls.py b/ishtar/furnitures/urls.py index 75759c9aa..01c8968a5 100644 --- a/ishtar/furnitures/urls.py +++ b/ishtar/furnitures/urls.py @@ -23,13 +23,15 @@ 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,\ -                  person_creation_wizard +                  person_creation_wizard, account_management_wizard  urlpatterns, actions = [], []  urlpatterns = patterns('',           url(BASE_URL + r'person_creation/(?P<step>.+)$',                          person_creation_wizard, name='person_creation'), +         url(BASE_URL + r'account_management/(?P<step>.+)$', +                        account_management_wizard, name='account_management'),           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 defb2a0a2..ce9b2f6d2 100644 --- a/ishtar/furnitures/views.py +++ b/ishtar/furnitures/views.py @@ -34,7 +34,7 @@ from ishtar import settings  from menus import menu  from forms import file_creation_wizard, file_modification_wizard, \                    operation_creation_wizard, operation_modification_wizard, \ -                  person_creation_wizard +                  person_creation_wizard, account_management_wizard  import models  def index(request): @@ -175,6 +175,9 @@ def action(request, action_slug, obj_id=None, *args, **kwargs):  def person_creation(request, dct, obj_id, *args, **kwargs):      return person_creation_wizard(request, *args, **kwargs) +def account_management(request, dct, obj_id, *args, **kwargs): +    return account_management_wizard(request, *args, **kwargs) +  def file_creation(request, dct, obj_id, *args, **kwargs):      return file_creation_wizard(request, *args, **kwargs) diff --git a/ishtar/furnitures/widgets.py b/ishtar/furnitures/widgets.py index e93463200..dc00f8676 100644 --- a/ishtar/furnitures/widgets.py +++ b/ishtar/furnitures/widgets.py @@ -86,9 +86,10 @@ class JQueryAutoComplete(forms.TextInput):              options += ',%s' % self.options
          js = u'$(\'#id_select_%s\').autocomplete({%s});\n' % (field_id, options)
 -        js += u'''$(\'#id_select_%s\').live('keypress', function(){
 +        js += u'''$(\'#id_select_%s\').live('click', function(){
                  $('#id_%s').val(null);
 -});''' % (field_id, field_id)
 +                $('#id_select_%s').val(null);
 +});''' % (field_id, field_id, field_id)
          return js
      def render(self, name, value=None, attrs=None):
 | 
