summaryrefslogtreecommitdiff
path: root/ishtar_common/forms_common.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2012-10-19 18:47:08 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2012-10-19 18:47:08 +0200
commitec6795dc5d3046f2f85a24d4aeffc00af6b2d81b (patch)
tree8d3166afc43c176bbe271623bf21a91970e8d56e /ishtar_common/forms_common.py
parent64b8c24de9263baf6207f7c6d64b892e37be083a (diff)
downloadIshtar-ec6795dc5d3046f2f85a24d4aeffc00af6b2d81b.tar.bz2
Ishtar-ec6795dc5d3046f2f85a24d4aeffc00af6b2d81b.zip
Djangoization - Fix account and person management
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r--ishtar_common/forms_common.py118
1 files changed, 7 insertions, 111 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index d034f6ddf..e5f23e620 100644
--- a/ishtar_common/forms_common.py
+++ b/ishtar_common/forms_common.py
@@ -194,104 +194,6 @@ class PersonForm(forms.Form):
new_item.save()
return new_item
-'''
-person_search_wizard = SearchWizard([
- ('general-person_search', PersonFormSelection)],
- url_name='person_search',)
-
-
-
-person_modification_wizard = PersonWizard([
- ('selec-person_modification', PersonFormSelection),
- ('identity-person_modification', PersonForm),
- ('final-person_modification', FinalForm)],
- url_name='person_modification',)
-
-class AccountWizard(Wizard):
- model = models.Person
- 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
-
- def done(self, request, storage, form_list, **kwargs):
- """
- Save the account
- """
- dct = {}
- for form in form_list:
- if not form.is_valid():
- return self.render(request, storage, form)
- associated_models = hasattr(form, 'associated_models') and \
- form.associated_models or {}
- if type(form.cleaned_data) == dict:
- for key in form.cleaned_data:
- if key == 'pk':
- continue
- value = form.cleaned_data[key]
- if key in associated_models and value:
- value = associated_models[key].objects.get(pk=value)
- dct[key] = value
- person = self.get_current_object(request, storage)
- if not person:
- return self.render(request, storage, form)
- for key in dct.keys():
- if key.startswith('hidden_password'):
- dct['password'] = dct.pop(key)
- try:
- account = models.IshtarUser.objects.get(person=person)
- account.username = dct['username']
- account.email = dct['email']
- except ObjectDoesNotExist:
- now = datetime.datetime.now()
- account = models.IshtarUser(person=person, username=dct['username'],
- email=dct['email'], first_name=person.surname,
- last_name=person.name, is_staff=False, is_active=True,
- is_superuser=False, last_login=now, date_joined=now)
- if dct['password']:
- account.set_password(dct['password'])
- account.save()
-
- if 'send_password' in dct and dct['send_password'] and \
- settings.ADMINS:
- site = Site.objects.get_current()
-
- app_name = site and ("Ishtar - " + site.name) \
- or "Ishtar"
- context = Context({'login':dct['username'],
- 'password':dct['password'],
- 'app_name':app_name,
- 'site': site and site.domain or ""
- })
- t = loader.get_template('account_activation_email.txt')
- msg = t.render(context)
- subject = _(u"[%(app_name)s] Account creation/modification") % {
- "app_name":app_name}
- send_mail(subject, msg, settings.ADMINS[0][1],
- [dct['email']], fail_silently=True)
- res = render_to_response('wizard_done.html', {},
- context_instance=RequestContext(request))
- return res
-
- def get_form(self, request, storage, step=None, data=None, files=None):
- """
- Display the "Send email" field if necessary
- """
- form = super(AccountWizard, self).get_form(request, storage, step, data,
- files)
- if not hasattr(form, 'is_hidden'):
- return form
- if self.session_get_value(request, storage,
- 'account-account_management', 'hidden_password'):
- form.is_hidden = False
- return form
-
-'''
class AccountForm(forms.Form):
form_label = _("Account")
associated_models = {'pk':models.Person}
@@ -301,11 +203,11 @@ class AccountForm(forms.Form):
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)])
+ 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)
+ label=_(u"New password (confirmation)"), max_length=128,
+ widget=forms.PasswordInput, required=False)
def __init__(self, *args, **kwargs):
if 'initial' in kwargs and 'pk' in kwargs['initial']:
@@ -327,8 +229,8 @@ class AccountForm(forms.Form):
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."))
+ raise forms.ValidationError(_(u"You must provide a correct "\
+ u"password."))
# check username unicity
usernames = models.IshtarUser.objects.filter(username=
cleaned_data.get('username'))
@@ -347,13 +249,7 @@ class FinalAccountForm(forms.Form):
def __init__(self, *args, **kwargs):
self.is_hidden = True
return super(FinalAccountForm, self).__init__(*args, **kwargs)
-'''
-account_management_wizard = AccountWizard([
- ('selec-account_management', PersonFormSelection),
- ('account-account_management', AccountForm),
- ('final-account_management', FinalAccountForm)],
- url_name='account_management',)
-'''
+
class TownForm(forms.Form):
form_label = _("Towns")
base_model = 'town'