From c6ebf3353c9b981c3c805b82bf4d48bb8731262a Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sun, 27 Oct 2013 00:40:22 +0200 Subject: Add person type to new person creation form (refs #1427) --- ishtar_common/forms_common.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'ishtar_common/forms_common.py') 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): -- cgit v1.2.3