diff options
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/forms.py | 23 | ||||
-rw-r--r-- | ishtar_common/models.py | 2 | ||||
-rw-r--r-- | ishtar_common/widgets.py | 6 | ||||
-rw-r--r-- | ishtar_common/wizards.py | 20 |
4 files changed, 36 insertions, 15 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 1d17aece7..13ad1cd30 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -266,16 +266,31 @@ class CustomForm(object): # formset fields = cls.form.base_fields customs = [] - for key in fields: + keys = fields.keys() + for key in keys: field = fields[key] - # cannot customize display of required and hidden field - # field with no label are also rejected - if field.required or field.widget.is_hidden or not field.label: + # cannot customize display of required (except in search form) and + # hidden field, search_vector and field with no label + if ('search_vector' not in keys and field.required) or \ + key == 'search_vector' or field.widget.is_hidden or \ + not field.label: continue customs.append((key, field.label)) return sorted(customs, key=lambda x: x[1]) +class CustomFormSearch(forms.Form): + need_user_for_initialization = True + + def __init__(self, *args, **kwargs): + user = None + if 'user' in kwargs: + user = kwargs.pop('user') + super(CustomFormSearch, self).__init__(*args, **kwargs) + if user and 'pk' in self.fields: + self.fields['pk'].widget.user = user + + class FormSet(CustomForm, BaseFormSet): delete_widget = widgets.DeleteWidget diff --git a/ishtar_common/models.py b/ishtar_common/models.py index d073b02c8..e1c4e825d 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1836,7 +1836,7 @@ class CustomForm(models.Model): if app_name == "archaeological_files_pdl": app_name = "archaeological_files" for form in dir(app_form): - if 'Form' not in form: + if 'Form' not in form and 'Select' not in form: # not very clean... but do not treat inappropriate items continue form = getattr(app_form, form) diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 6ec0220eb..d1f6e49d3 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -905,6 +905,7 @@ class DataTable(forms.RadioSelect): self.source_full = source_full self.sortname = sortname self.col_prefix = col_prefix + self.user = None if self.col_prefix and not self.col_prefix.endswith('__'): self.col_prefix += "__" @@ -956,7 +957,10 @@ class DataTable(forms.RadioSelect): def render(self, name, value, attrs=None, renderer=None): # t = loader.get_template('blocks/form_flex_snippet.html') t = loader.get_template('blocks/bs_form_snippet.html') - form = self.form() + if self.user: + form = self.form(user=self.user) + else: + form = self.form() rendered = t.render({'form': form, 'search': True}) dct = {} if self.new: diff --git a/ishtar_common/wizards.py b/ishtar_common/wizards.py index 979f611ce..4a55345d2 100644 --- a/ishtar_common/wizards.py +++ b/ishtar_common/wizards.py @@ -87,7 +87,16 @@ def filter_no_fields_form(form, other_check=None): return func -class Wizard(NamedUrlWizardView): +class IshtarWizard(NamedUrlWizardView): + def get_form_kwargs(self, step=None): + kwargs = super(IshtarWizard, self).get_form_kwargs(step) + if hasattr(self.form_list[step], 'need_user_for_initialization') and \ + self.form_list[step].need_user_for_initialization: + kwargs['user'] = self.request.user + return kwargs + + +class Wizard(IshtarWizard): model = None label = '' translated_keys = [] @@ -167,13 +176,6 @@ class Wizard(NamedUrlWizardView): return super(Wizard, self).dispatch(request, *args, **kwargs) - def get_form_kwargs(self, step=None): - kwargs = super(Wizard, self).get_form_kwargs(step) - if hasattr(self.form_list[step], 'need_user_for_initialization') and\ - self.form_list[step].need_user_for_initialization: - kwargs['user'] = self.request.user - return kwargs - def get_prefix(self, request, *args, **kwargs): """As the class name can interfere when reused prefix with the url_name """ @@ -1382,7 +1384,7 @@ class Wizard(NamedUrlWizardView): return initial -class SearchWizard(NamedUrlWizardView): +class SearchWizard(IshtarWizard): model = None label = '' modification = None # True when the wizard modify an item |