diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-17 16:09:34 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-02-17 16:09:34 +0100 |
commit | 4e512fd38e2fa275112b90d863b67acee3539789 (patch) | |
tree | 412d1a4aa99c429d4de3a599e6c5f97c2fbbe141 | |
parent | 5921fedef065a34a97ecdd2ca4353aa72f25b116 (diff) | |
download | Ishtar-4e512fd38e2fa275112b90d863b67acee3539789.tar.bz2 Ishtar-4e512fd38e2fa275112b90d863b67acee3539789.zip |
Accounts: initialize new account with default username extract from raw name
-rw-r--r-- | ishtar_common/forms_common.py | 8 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 6 |
2 files changed, 13 insertions, 1 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 67299fbac..e2c0e5db5 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -581,6 +581,7 @@ class AccountForm(forms.Form): widget=forms.PasswordInput, required=False) def __init__(self, *args, **kwargs): + person = None if 'initial' in kwargs and 'pk' in kwargs['initial']: try: person = models.Person.objects.get(pk=kwargs['initial']['pk']) @@ -591,7 +592,12 @@ class AccountForm(forms.Form): kwargs['initial']['email'] = account.email except ObjectDoesNotExist: pass - return super(AccountForm, self).__init__(*args, **kwargs) + if 'person' in kwargs: + person = kwargs.pop('person') + super(AccountForm, self).__init__(*args, **kwargs) + if person: + self.fields['username'].initial = \ + person.raw_name.lower().replace(' ', '.') def clean(self): cleaned_data = self.cleaned_data diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 5105418a5..c2cd54d03 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -1343,6 +1343,12 @@ class AccountWizard(Wizard): context_instance=RequestContext(self.request)) return res + def get_form_kwargs(self, step=None): + kwargs = super(AccountWizard, self).get_form_kwargs(step) + if step == 'account-account_management': + kwargs['person'] = self.get_current_object() + return kwargs + def get_form(self, step=None, data=None, files=None): """ Display the "Send email" field if necessary |