From d66686f332337211929ddb505eeab8eff42cd4e4 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 30 Jun 2011 14:04:52 +0200 Subject: Manage many to one treatment (refs #499) --- ishtar/ishtar_base/forms_items.py | 20 +++++++++++++++----- ishtar/ishtar_base/models.py | 17 ++++++++++++++--- ishtar/ishtar_base/widgets.py | 28 ++++++++++++++++++++++------ static/js/ishtar.js | 2 +- static/media/style.css | 14 +++++++++++--- 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/ishtar/ishtar_base/forms_items.py b/ishtar/ishtar_base/forms_items.py index 7e3047741..484902341 100644 --- a/ishtar/ishtar_base/forms_items.py +++ b/ishtar/ishtar_base/forms_items.py @@ -206,10 +206,10 @@ class BaseTreatmentForm(forms.Form): class ItemMultipleFormSelection(forms.Form): form_label = _(u"Upstream items") associated_models = {'items':models.Item} - items = forms.IntegerField(label="", required=False, + items = forms.CharField(label="", required=False, widget=widgets.JQueryJqGrid(reverse_lazy('get-item'), - ItemSelect(), models.Item, multiple=True), - validators=[models.valid_id(models.Item)]) + ItemSelect(), models.Item, multiple=True, multiple_cols=[2, 3, 4]), + validators=[models.valid_ids(models.Item)]) class ContainerForm(forms.Form): form_label = _(u"Container") @@ -272,10 +272,10 @@ treatment_creation_wizard = TreatmentWizard([ condition_list={ 'selecitem-treatment_creation': check_treatment('basetreatment-treatment_creation', 'treatment_type', - not_type_list=['physical_grouping']), + not_type_list=['physical_grouping', 'packaging']), 'multiselecitems-treatment_creation': check_treatment('basetreatment-treatment_creation', 'treatment_type', - ['physical_grouping']), + ['physical_grouping', 'packaging']), 'resultitems-treatment_creation': check_treatment('basetreatment-treatment_creation', 'treatment_type', ['split']), @@ -288,6 +288,16 @@ treatment_creation_wizard = TreatmentWizard([ }, url_name='treatment_creation',) +######################## +# Warehouse management # +######################## + +""" +warehouse_packaging_wizard = ItemSourceWizard([ + ('selec-warehouse_packaging', ItemsSelection), + ('final-warehouse_packaging', FinalForm)], + url_name='warehouse_packaging',) +""" ############################################# # Source management for archaelogical items # ############################################# diff --git a/ishtar/ishtar_base/models.py b/ishtar/ishtar_base/models.py index 0f3cb8a8b..37af19f87 100644 --- a/ishtar/ishtar_base/models.py +++ b/ishtar/ishtar_base/models.py @@ -66,6 +66,17 @@ def valid_id(cls): raise ValidationError(_(u"Not a valid item.")) return func +def valid_ids(cls): + def func(value): + if "," in value: + value = value.split(",") + for v in value: + try: + cls.objects.get(pk=v) + except ObjectDoesNotExist: + raise ValidationError(_(u"Not a valid item.")) + return func + # unique validator for models def is_unique(cls, field): def func(value): @@ -945,13 +956,13 @@ class BaseItem(BaseHistorizedItem, OwnPerms): self.context_record.label, self.label)]) class Item(BaseHistorizedItem, OwnPerms): - TABLE_COLS = ['base_items.context_record.parcel.town', + TABLE_COLS = ['label', 'material_type', 'dating.period', + 'base_items.context_record.parcel.town', 'base_items.context_record.parcel.operation.year', 'base_items.context_record.parcel.operation.operation_code', - 'label', 'material_type', 'dating.period', 'base_items.is_isolated'] if settings.COUNTRY == 'fr': - TABLE_COLS.insert(1, + TABLE_COLS.insert(6, 'base_items.context_record.parcel.operation.code_patriarche') base_items = models.ManyToManyField(BaseItem, verbose_name=_(u"Base item"), related_name='item') diff --git a/ishtar/ishtar_base/widgets.py b/ishtar/ishtar_base/widgets.py index e058f7074..cb257325c 100644 --- a/ishtar/ishtar_base/widgets.py +++ b/ishtar/ishtar_base/widgets.py @@ -205,13 +205,14 @@ class JQueryJqGrid(forms.RadioSelect): ]} def __init__(self, source, form, associated_model, attrs={}, - table_cols='TABLE_COLS', multiple=False): + table_cols='TABLE_COLS', multiple=False, multiple_cols=[2]): self.source = source self.form = form self.attrs = attrs self.associated_model = associated_model self.table_cols = table_cols self.multiple = multiple + self.multiple_cols = multiple_cols def render(self, name, value=None, attrs=None): t = loader.get_template('form_snippet.html') @@ -259,11 +260,12 @@ class JQueryJqGrid(forms.RadioSelect): dct = {'name':name, 'col_names':col_names, 'extra_cols':extra_cols, 'source':unicode(self.source), 'col_idx':col_idx, 'no_result':unicode(_("No results")), 'loading':unicode(_("Loading...")), - 'remove':unicode(_("Remove")), 'sname':name.replace('-', '')} - + 'remove':unicode(_(u"Remove")), 'sname':name.replace('-', ''), + 'multi_cols': ",".join((u'"%d"' % col for col in self.multiple_cols))} rendered += """