diff options
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r-- | ishtar_common/forms_common.py | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index aef94476c..f6889ae1f 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -33,7 +33,8 @@ from django.utils.translation import ugettext_lazy as _ import models import widgets -from forms import FinalForm, FormSet, reverse_lazy, name_validator, TableSelect +from forms import FinalForm, FormSet, reverse_lazy, name_validator, \ + TableSelect, ManageOldType def get_town_field(label=_(u"Town"), required=True): @@ -154,7 +155,7 @@ class TargetKeyForm(forms.ModelForm): self.instance.save() -class OrganizationForm(NewItemForm): +class OrganizationForm(ManageOldType, NewItemForm): form_label = _(u"Organization") associated_models = {'organization_type': models.OrganizationType} name = forms.CharField( @@ -178,7 +179,8 @@ class OrganizationForm(NewItemForm): def __init__(self, *args, **kwargs): super(OrganizationForm, self).__init__(*args, **kwargs) self.fields['organization_type'].choices = \ - models.OrganizationType.get_types() + models.OrganizationType.get_types( + initial=self.init_data.get('organization_type')) self.fields['organization_type'].help_text = \ models.OrganizationType.get_help() self.limit_fields() @@ -254,10 +256,11 @@ class PersonFormSelection(forms.Form): validators=[models.valid_id(models.Person)]) -class SimplePersonForm(NewItemForm): +class SimplePersonForm(ManageOldType, NewItemForm): form_label = _("Identity") - associated_models = {'attached_to': models.Organization} - title = forms.ChoiceField(label=_("Title"), choices=models.Person.TYPE) + associated_models = {'attached_to': models.Organization, + 'title': models.TitleType} + title = forms.ChoiceField(label=_("Title"), choices=[]) surname = forms.CharField(label=_(u"Surname"), max_length=50, validators=[name_validator]) name = forms.CharField(label=_(u"Name"), max_length=200, @@ -308,6 +311,8 @@ class SimplePersonForm(NewItemForm): def __init__(self, *args, **kwargs): super(SimplePersonForm, self).__init__(*args, **kwargs) self.fields['raw_name'].widget.attrs['readonly'] = True + self.fields['title'].choices = models.TitleType.get_types( + initial=self.init_data.get('title')) class PersonUserSelect(PersonSelect): @@ -398,6 +403,7 @@ class PersonForm(SimplePersonForm): def __init__(self, *args, **kwargs): super(PersonForm, self).__init__(*args, **kwargs) self.fields['person_types'].choices = models.PersonType.get_types( + initial=self.init_data.get('person_types'), empty_first=False) self.fields['person_types'].help_text = models.PersonType.get_help() self.limit_fields() @@ -421,7 +427,7 @@ class NoOrgaPersonForm(PersonForm): self.fields.pop('attached_to') -class PersonTypeForm(forms.Form): +class PersonTypeForm(ManageOldType, forms.Form): form_label = _("Person type") base_model = 'person_type' associated_models = {'person_type': models.PersonType} @@ -432,6 +438,7 @@ class PersonTypeForm(forms.Form): def __init__(self, *args, **kwargs): super(PersonTypeForm, self).__init__(*args, **kwargs) self.fields['person_type'].choices = models.PersonType.get_types( + initial=self.init_data.get('person_type'), empty_first=False) self.fields['person_type'].help_text = models.PersonType.get_help() @@ -457,8 +464,10 @@ class AccountForm(forms.Form): try: person = models.Person.objects.get(pk=kwargs['initial']['pk']) account = models.IshtarUser.objects.get(person=person) - kwargs['initial'].update({'username': account.username, - 'email': account.email}) + if not kwargs['initial'].get('username'): + kwargs['initial']['username'] = account.username + if not kwargs['initial'].get('email'): + kwargs['initial']['email'] = account.email except ObjectDoesNotExist: pass return super(AccountForm, self).__init__(*args, **kwargs) @@ -638,7 +647,7 @@ class MergeOrganizationForm(MergeForm): ###################### # Sources management # ###################### -class SourceForm(forms.Form): +class SourceForm(ManageOldType, forms.Form): form_label = _(u"Documentation informations") associated_models = {'source_type': models.SourceType} title = forms.CharField(label=_(u"Title"), @@ -671,7 +680,8 @@ class SourceForm(forms.Form): def __init__(self, *args, **kwargs): super(SourceForm, self).__init__(*args, **kwargs) - self.fields['source_type'].choices = models.SourceType.get_types() + self.fields['source_type'].choices = models.SourceType.get_types( + initial=self.init_data.get('source_type')) class SourceSelect(TableSelect): @@ -707,7 +717,7 @@ class SourceDeletionForm(FinalForm): ###################### -class AuthorForm(NewItemForm): +class AuthorForm(ManageOldType, NewItemForm): form_label = _(u"Author") associated_models = {'person': models.Person, 'author_type': models.AuthorType} @@ -720,7 +730,8 @@ class AuthorForm(NewItemForm): def __init__(self, *args, **kwargs): super(AuthorForm, self).__init__(*args, **kwargs) - self.fields['author_type'].choices = models.AuthorType.get_types() + self.fields['author_type'].choices = models.AuthorType.get_types( + initial=self.init_data.get('author_type')) self.limit_fields() def save(self, user): |