summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2013-07-17 11:24:39 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2013-07-17 11:24:39 +0200
commitc134fda7897e667b4a3d87b0dd5413817d26d9ce (patch)
treea59cf4f022e1a127e18baade9a7a82c8852b5d7e
parent9df94fa062e738356070226965e21dfd90a4a3d0 (diff)
downloadIshtar-c134fda7897e667b4a3d87b0dd5413817d26d9ce.tar.bz2
Ishtar-c134fda7897e667b4a3d87b0dd5413817d26d9ce.zip
Fix cached forms that doesn't allow modeltypes update
Don't instanciate the form passed to the widget
-rw-r--r--archaeological_context_records/forms.py2
-rw-r--r--archaeological_files/forms.py4
-rw-r--r--archaeological_finds/forms.py37
-rw-r--r--archaeological_operations/forms.py4
-rw-r--r--ishtar_common/forms.py2
-rw-r--r--ishtar_common/widgets.py7
6 files changed, 33 insertions, 23 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index fce5193d6..48b198fe3 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -67,7 +67,7 @@ class RecordFormSelection(forms.Form):
currents = {'pk':models.ContextRecord}
pk = forms.IntegerField(label="", required=False,
widget=widgets.JQueryJqGrid(reverse_lazy('get-contextrecord'),
- RecordSelect(), models.ContextRecord,
+ RecordSelect, models.ContextRecord,
source_full=reverse_lazy('get-contextrecord-full')),
validators=[valid_id(models.ContextRecord)])
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index 67f00c8d8..ad5b3f614 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -71,7 +71,7 @@ class FileFormSelection(forms.Form):
currents = {'pk':models.File}
pk = forms.IntegerField(label="", required=False,
widget=widgets.JQueryJqGrid(reverse_lazy('get-file'),
- FileSelect(), models.File, source_full=reverse_lazy('get-file-full')),
+ FileSelect, models.File, source_full=reverse_lazy('get-file-full')),
validators=[valid_id(models.File)])
def clean(self):
@@ -194,7 +194,7 @@ class AdministrativeActFileSelect(TableSelect):
class AdministrativeActFileFormSelection(AdministrativeActOpeFormSelection):
pk = forms.IntegerField(label="", required=False,
widget=widgets.JQueryJqGrid(reverse_lazy('get-administrativeactfile'),
- AdministrativeActFileSelect(), AdministrativeAct,
+ AdministrativeActFileSelect, AdministrativeAct,
table_cols='TABLE_COLS_FILE'),
validators=[valid_id(AdministrativeAct)])
diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py
index feaad0e23..367bff023 100644
--- a/archaeological_finds/forms.py
+++ b/archaeological_finds/forms.py
@@ -54,32 +54,39 @@ class FindForm(forms.Form):
widget=forms.Textarea)
base_finds__is_isolated = forms.NullBooleanField(label=_(u"Is isolated?"),
required=False)
- material_type = forms.ChoiceField(label=_("Material type"),
- choices=models.MaterialType.get_types())
+ material_type = forms.ChoiceField(label=_("Material type"), choices=[])
volume = FloatField(label=_(u"Volume (l)"), required=False)
weight = FloatField(label=_(u"Weight (g)"), required=False)
find_number = forms.IntegerField(label=_(u"Find number"), required=False)
+ def __init__(self, *args, **kwargs):
+ super(FindForm, self).__init__(*args, **kwargs)
+ self.fields['material_type'].choices = models.MaterialType.get_types()
+ self.fields['material_type'].help_text = models.MaterialType.get_help()
+
class DateForm(forms.Form):
form_label = _("Dating")
base_model = 'dating'
associated_models = {'dating__dating_type':DatingType,
'dating__quality':DatingQuality,
'dating__period':Period}
- dating__period = forms.ChoiceField(label=_("Period"),
- choices=Period.get_types())
+ dating__period = forms.ChoiceField(label=_("Period"), choices=[])
dating__start_date = forms.IntegerField(label=_(u"Start date"),
required=False)
dating__end_date = forms.IntegerField(label=_(u"End date"), required=False)
dating__quality = forms.ChoiceField(label=_("Quality"), required=False,
- choices=DatingQuality.get_types())
+ choices=[])
dating__dating_type = forms.ChoiceField(label=_("Dating type"),
- required=False, choices=[])
+ required=False, choices=[])
def __init__(self, *args, **kwargs):
super(DateForm, self).__init__(*args, **kwargs)
self.fields['dating__dating_type'].choices = DatingType.get_types()
self.fields['dating__dating_type'].help_text = DatingType.get_help()
+ self.fields['dating__period'].choices = Period.get_types()
+ self.fields['dating__period'].help_text = Period.get_help()
+ self.fields['dating__quality'].choices = DatingQuality.get_types()
+ self.fields['dating__quality'].help_text = DatingQuality.get_help()
class FindSelect(TableSelect):
base_finds__context_record__parcel__town = get_town_field()
@@ -108,7 +115,7 @@ class FindFormSelection(forms.Form):
currents = {'pk':models.Find}
pk = forms.IntegerField(label="", required=False,
widget=widgets.JQueryJqGrid(reverse_lazy('get-find'),
- FindSelect(), models.Find, source_full=reverse_lazy('get-find-full')),
+ FindSelect, models.Find, source_full=reverse_lazy('get-find-full')),
validators=[valid_id(models.Find)])
class BaseTreatmentForm(forms.Form):
@@ -146,7 +153,7 @@ class FindMultipleFormSelection(forms.Form):
associated_labels = {'finds':_(u"Finds")}
finds = forms.CharField(label="", required=False,
widget=widgets.JQueryJqGrid(reverse_lazy('get-find'),
- FindSelect(), models.Find, multiple=True, multiple_cols=[2, 3, 4]),
+ FindSelect, models.Find, multiple=True, multiple_cols=[2, 3, 4]),
validators=[valid_ids(models.Find)])
def clean(self):
@@ -183,12 +190,16 @@ class ResultFindForm(forms.Form):
validators=[validators.MaxLengthValidator(60)])
description = forms.CharField(label=_(u"Precise description"),
widget=forms.Textarea)
- material_type = forms.ChoiceField(label=_(u"Material type"),
- choices=models.MaterialType.get_types())
+ material_type = forms.ChoiceField(label=_(u"Material type"), choices=[])
volume = forms.IntegerField(label=_(u"Volume (l)"))
weight = forms.IntegerField(label=_(u"Weight (g)"))
find_number = forms.IntegerField(label=_(u"Find number"))
+ def __init__(self, *args, **kwargs):
+ super(ResultFindForm, self).__init__(*args, **kwargs)
+ self.fields['material_type'].choices = models.MaterialType.get_types()
+ self.fields['material_type'].help_text = models.MaterialType.get_help()
+
ResultFindFormSet = formset_factory(ResultFindForm, can_delete=True,
formset=FormSet)
ResultFindFormSet.form_label = _(u"Resulting finds")
@@ -209,11 +220,9 @@ class FindSourceSelect(SourceSelect):
find__base_finds__context_record__operation__year = forms.IntegerField(
label=_(u"Year of the operation"))
find__dating__period = forms.ChoiceField(
- label=_(u"Period of the archaelogical find"),
- choices=[])
+ label=_(u"Period of the archaelogical find"), choices=[])
find__material_type = forms.ChoiceField(
- label=_("Material type of the archaelogical find"),
- choices=models.MaterialType.get_types())
+ label=_("Material type of the archaelogical find"), choices=[])
find__description = forms.CharField(
label=_(u"Description of the archaelogical find"))
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index c1003dfe9..cbdade3b2 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -158,7 +158,7 @@ class OperationFormSelection(forms.Form):
currents = {'pk':models.Operation}
pk = forms.IntegerField(label="", required=False,
widget=widgets.JQueryJqGrid(reverse_lazy('get-operation'),
- OperationSelect(), models.Operation,
+ OperationSelect, models.Operation,
source_full=reverse_lazy('get-operation-full')),
validators=[valid_id(models.Operation)])
@@ -485,7 +485,7 @@ class AdministrativeActOpeFormSelection(forms.Form):
currents = {'pk':models.AdministrativeAct}
pk = forms.IntegerField(label="", required=False,
widget=widgets.JQueryJqGrid(reverse_lazy('get-administrativeactop'),
- AdministrativeActOpeSelect(), models.AdministrativeAct,
+ AdministrativeActOpeSelect, models.AdministrativeAct,
table_cols='TABLE_COLS_OPE'),
validators=[valid_id(models.AdministrativeAct)])
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index 4477213c9..bc780ef9a 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -136,7 +136,7 @@ def get_form_selection(class_name, label, key, model, base_form, get_url,
'currents':{key:model},}
attrs[key] = forms.IntegerField(label="", required=False,
validators=[models.valid_id(model)],
- widget=widgets.JQueryJqGrid(reverse_lazy(get_url), base_form(), model,
+ widget=widgets.JQueryJqGrid(reverse_lazy(get_url), base_form, model,
new=new, new_message=new_message))
def clean(self):
cleaned_data = self.cleaned_data
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index af638aba7..d19b73b94 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -207,7 +207,8 @@ class JQueryJqGrid(forms.RadioSelect):
def render(self, name, value=None, attrs=None):
t = loader.get_template('blocks/form_snippet.html')
- rendered = t.render(Context({'form':self.form}))
+ form = self.form()
+ rendered = t.render(Context({'form':form}))
rendered += u"\n</table>\n"\
u"<button id='search_%s' class='submit'>%s</button>" % (
name, unicode(_("Search")))
@@ -219,8 +220,8 @@ class JQueryJqGrid(forms.RadioSelect):
rendered += "\n<h4>%s</h4>\n" % unicode(_("Search and select an item"))
extra_cols = []
col_names, col_idx = [], []
- for k in self.form.get_input_ids():
- #field = self.form.fields[k]
+ for k in form.get_input_ids():
+ #field = form.fields[k]
col_idx.append(u'"%s"' % k)
for field_name in getattr(self.associated_model, self.table_cols):
field = self.associated_model