diff options
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r-- | ishtar_common/forms_common.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 5078ffaae..db406aaa9 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -53,14 +53,15 @@ def get_town_field(label=_(u"Town"), required=True): validators=[models.valid_id(models.Town)], label=label, help_text=mark_safe(help_text), required=required) -def get_person_field(label=_(u"Person"), required=True, person_type=None): +def get_person_field(label=_(u"Person"), required=True, person_types=[]): # !FIXME hard_link, reverse_lazy doen't seem to work with formsets widget = None url = "/" + settings.URL_PATH + 'autocomplete-person' - if person_type: - if isinstance(person_type, unicode) or isinstance(person_type, str): - person_type = models.PersonType.objects.get(txt_idx=person_type) - url += u"/" + unicode(person_type.pk) + if person_types: + person_types = [ + unicode(models.PersonType.objects.get(txt_idx=person_type).pk) + for person_type in person_types] + url += u"/" + u'_'.join(person_types) widget = widgets.JQueryAutoComplete(url, associated_model=models.Person) return forms.IntegerField(widget=widget, label=label, required=required, validators=[models.valid_id(models.Person)]) @@ -110,8 +111,7 @@ class PersonFormSelection(forms.Form): class PersonForm(forms.Form): form_label = _("Identity") - associated_models = {'attached_to':models.Organization, - 'person_type':models.PersonType} + associated_models = {'attached_to':models.Organization} title = forms.ChoiceField(label=_("Title"), choices=models.Person.TYPE) surname = forms.CharField(label=_(u"Surname"), max_length=20, validators=[name_validator]) @@ -119,23 +119,15 @@ class PersonForm(forms.Form): validators=[name_validator]) email = forms.CharField(label=_(u"Email"), max_length=40, required=False, validators=[validators.validate_email]) - person_type = forms.ChoiceField(label=_("Person type"), - choices=[]) attached_to = forms.IntegerField(label=_("Current organization"), - widget=widgets.JQueryAutoComplete(reverse_lazy('autocomplete-organization'), - associated_model=models.Organization, new=True), - validators=[models.valid_id(models.Organization)], required=False) - - def __init__(self, *args, **kwargs): - super(PersonForm, self).__init__(*args, **kwargs) - self.fields['person_type'].choices = models.PersonType.get_types() - self.fields['person_type'].help_text = models.PersonType.get_help() + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-organization'), + associated_model=models.Organization, new=True), + validators=[models.valid_id(models.Organization)], required=False) def save(self, user): dct = self.cleaned_data dct['history_modifier'] = user - dct['person_type'] = models.PersonType.objects.get( - pk=dct['person_type']) if 'attached_to' in dct and dct['attached_to']: dct['attached_to'] = models.Organization.objects.get( pk=dct['attached_to']) @@ -143,6 +135,19 @@ class PersonForm(forms.Form): new_item.save() return new_item +class PersonTypeForm(forms.Form): + form_label = _("Person type") + base_model = 'person_type' + associated_models = {'person_type':models.PersonType} + person_type = forms.MultipleChoiceField(label=_("Person type"), + choices=[], widget=forms.CheckboxSelectMultiple) + + def __init__(self, *args, **kwargs): + super(PersonTypeForm, self).__init__(*args, **kwargs) + self.fields['person_type'].choices = models.PersonType.get_types( + empty_first=False) + self.fields['person_type'].help_text = models.PersonType.get_help() + class AccountForm(forms.Form): form_label = _("Account") associated_models = {'pk':models.Person} |