diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-21 16:56:36 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-11-21 16:56:36 +0100 |
commit | fe2a6ea1d32042a9f60fd2434cc465ffd9ab0d39 (patch) | |
tree | a7403c8968011f51cbc4a3b9d9a6b1001e4f721b /ishtar_common | |
parent | ff60c200ddc406250c335de3b59a56b9327a16ec (diff) | |
download | Ishtar-fe2a6ea1d32042a9f60fd2434cc465ffd9ab0d39.tar.bz2 Ishtar-fe2a6ea1d32042a9f60fd2434cc465ffd9ab0d39.zip |
Custom form: operations forms
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms.py | 18 | ||||
-rw-r--r-- | ishtar_common/forms_common.py | 15 |
2 files changed, 22 insertions, 11 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 8b97cfbab..eebd912ea 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -336,18 +336,26 @@ def get_data_from_formset(data): class FieldType(object): - def __init__(self, key, model, is_multiple=False): + def __init__(self, key, model, is_multiple=False, extra_args=None): self.key = key self.model = model self.is_multiple = is_multiple + self.extra_args = extra_args def get_choices(self, initial=None): - return self.model.get_types( - empty_first=not self.is_multiple, - initial=initial) + args = { + 'empty_first': not self.is_multiple, + 'initial': initial + } + if self.extra_args: + args.update(self.extra_args) + return self.model.get_types(**args) def get_help(self): - return self.model.get_help() + args = {} + if self.extra_args: + args.update(self.extra_args) + return self.model.get_help(**args) class ManageOldType(object): diff --git a/ishtar_common/forms_common.py b/ishtar_common/forms_common.py index 116c8c277..32c91b683 100644 --- a/ishtar_common/forms_common.py +++ b/ishtar_common/forms_common.py @@ -35,7 +35,7 @@ import models import widgets from ishtar_common.templatetags.link_to_window import link_to_window from forms import FinalForm, FormSet, reverse_lazy, name_validator, \ - TableSelect, ManageOldType + TableSelect, ManageOldType, CustomForm, FieldType def get_town_field(label=_(u"Town"), required=True): @@ -733,6 +733,8 @@ class TownFormSet(FormSet): TownFormset = formset_factory(TownForm, can_delete=True, formset=TownFormSet) TownFormset.form_label = _("Towns") +TownFormset.form_admin_name = _(u"Towns") +TownFormset.form_slug = "towns" class MergeFormSet(BaseModelFormSet): @@ -860,7 +862,7 @@ class MergeOrganizationForm(MergeForm): ###################### # Sources management # ###################### -class SourceForm(ManageOldType, forms.Form): +class SourceForm(CustomForm, ManageOldType, forms.Form): form_label = _(u"Documentation informations") file_upload = True associated_models = {'source_type': models.SourceType} @@ -899,10 +901,9 @@ class SourceForm(ManageOldType, forms.Form): 'height': settings.IMAGE_MAX_SIZE[1]}), max_length=255, required=False, widget=widgets.ImageFileInput()) - def __init__(self, *args, **kwargs): - super(SourceForm, self).__init__(*args, **kwargs) - self.fields['source_type'].choices = models.SourceType.get_types( - initial=self.init_data.get('source_type')) + TYPES = [ + FieldType('source_type', models.SourceType), + ] class SourceSelect(TableSelect): @@ -986,3 +987,5 @@ class AuthorFormSet(FormSet): AuthorFormset = formset_factory(AuthorFormSelection, can_delete=True, formset=AuthorFormSet) AuthorFormset.form_label = _("Authors") +AuthorFormset.form_admin_name = _(u"Authors") +AuthorFormset.form_slug = "authors" |