summaryrefslogtreecommitdiff
path: root/ishtar_common/forms_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/forms_common.py')
-rw-r--r--ishtar_common/forms_common.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py
index 2859ed4e5..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,7 +256,7 @@ 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': models.TitleType}
@@ -309,7 +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()
+ self.fields['title'].choices = models.TitleType.get_types(
+ initial=self.init_data.get('title'))
class PersonUserSelect(PersonSelect):
@@ -400,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()
@@ -423,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}
@@ -434,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()
@@ -642,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"),
@@ -675,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):
@@ -711,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}
@@ -724,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):