diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-10-27 00:40:22 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2013-10-27 00:40:22 +0200 |
commit | 1413776f4b79e175ec64b07208b21e4f44482390 (patch) | |
tree | ccd91e634e13948fec375332a27e5f6298f30583 /ishtar_common/forms_common.py | |
parent | a3abe56e296ce4385478c27b5573b4c4ea10765f (diff) | |
download | Ishtar-1413776f4b79e175ec64b07208b21e4f44482390.tar.bz2 Ishtar-1413776f4b79e175ec64b07208b21e4f44482390.zip |
Add person type to new person creation form (refs #1427)
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r-- | ishtar_common/forms_common.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 0a001883c..661709a09 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -139,6 +139,14 @@ class PersonForm(forms.Form): reverse_lazy('autocomplete-organization'), associated_model=models.Organization, new=True), validators=[models.valid_id(models.Organization)], required=False) + person_types = forms.MultipleChoiceField(label=_("Person type"), + choices=[], widget=forms.CheckboxSelectMultiple) + + def __init__(self, *args, **kwargs): + super(PersonForm, self).__init__(*args, **kwargs) + self.fields['person_types'].choices = models.PersonType.get_types( + empty_first=False) + self.fields['person_types'].help_text = models.PersonType.get_help() def save(self, user): dct = self.cleaned_data @@ -146,8 +154,10 @@ class PersonForm(forms.Form): if 'attached_to' in dct and dct['attached_to']: dct['attached_to'] = models.Organization.objects.get( pk=dct['attached_to']) - new_item = models.Person(**dct) - new_item.save() + person_types = dct.pop('person_types') + new_item = models.Person.objects.create(**dct) + for pt in person_types: + new_item.person_types.add(pt) return new_item class PersonTypeForm(forms.Form): |