diff options
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r-- | ishtar_common/forms_common.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 2788283db..560a1abb3 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -261,6 +261,8 @@ class SimplePersonForm(ManageOldType, NewItemForm): associated_models = {'attached_to': models.Organization, 'title': models.TitleType} title = forms.ChoiceField(label=_("Title"), choices=[]) + salutation = forms.CharField(label=_("Salutation"), max_length=200, + required=False) surname = forms.CharField(label=_(u"Surname"), max_length=50, validators=[name_validator]) name = forms.CharField(label=_(u"Name"), max_length=200, @@ -363,14 +365,14 @@ class AccountFormSelection(forms.Form): class BasePersonForm(forms.ModelForm): class Meta: model = models.Person - fields = ['title', 'name', 'surname', 'address', 'address_complement', - 'town', 'postal_code'] + fields = ['title', 'salutation', 'name', 'surname', 'address', + 'address_complement', 'town', 'postal_code'] class BaseOrganizationPersonForm(forms.ModelForm): class Meta: model = models.Person - fields = ['attached_to', 'title', 'name', 'surname'] + fields = ['attached_to', 'title', 'salutation', 'name', 'surname'] widgets = {'attached_to': widgets.JQueryPersonOrganization( reverse_lazy('autocomplete-organization'), reverse_lazy('organization_create'), @@ -412,8 +414,17 @@ class PersonForm(SimplePersonForm): dct = self.cleaned_data dct['history_modifier'] = user if 'attached_to' in dct and dct['attached_to']: - dct['attached_to'] = models.Organization.objects.get( - pk=dct['attached_to']) + try: + dct['attached_to'] = models.Organization.objects.get( + pk=dct['attached_to']) + except models.Organization.DoesNotExist: + dct.pop('attached_to') + if 'title' in dct and dct['title']: + try: + dct['title'] = models.TitleType.objects.get( + pk=dct['title']) + except models.TitleType.DoesNotExist: + dct.pop('title') person_types = dct.pop('person_types') new_item = models.Person.objects.create(**dct) for pt in person_types: |