summaryrefslogtreecommitdiff
path: root/ishtar/furnitures/forms_items.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-24 14:37:16 +0200
committerÉtienne Loks <etienne.loks@peacefrogs.net>2011-06-24 14:37:16 +0200
commit05c6d94c9547377c9979e9d860c6618ee898ef6e (patch)
tree6b4fc14f42da9d91ab2bb4b989ffeeb42947392f /ishtar/furnitures/forms_items.py
parent2d008477cb66ec3e356fd9153afba7affede249c (diff)
downloadIshtar-05c6d94c9547377c9979e9d860c6618ee898ef6e.tar.bz2
Ishtar-05c6d94c9547377c9979e9d860c6618ee898ef6e.zip
Sources creation for Operation (refs #497) - restructuration (refs #57)
Diffstat (limited to 'ishtar/furnitures/forms_items.py')
-rw-r--r--ishtar/furnitures/forms_items.py280
1 files changed, 0 insertions, 280 deletions
diff --git a/ishtar/furnitures/forms_items.py b/ishtar/furnitures/forms_items.py
deleted file mode 100644
index b6da0f889..000000000
--- a/ishtar/furnitures/forms_items.py
+++ /dev/null
@@ -1,280 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2011 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
-
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# See the file COPYING for details.
-
-"""
-Items forms definitions
-"""
-import datetime
-
-from django import forms
-from django.core import validators
-from django.core.exceptions import ObjectDoesNotExist
-from django.utils.safestring import mark_safe
-from django.db.models import Max
-from django.utils.translation import ugettext_lazy as _
-
-from ishtar import settings
-
-import models
-import widgets
-from forms import Wizard, FinalForm, FormSet, SearchWizard, FloatField,\
- formset_factory, get_now, reverse_lazy
-from forms_common import get_town_field
-from forms_context_records import RecordFormSelection
-
-class ItemWizard(Wizard):
- model = models.Item
-
- def get_current_contextrecord(self, request, storage):
- step = storage.get_current_step()
- if not step:
- return
- if step.endswith('_creation'): # a context record has been selected
- main_form_key = 'selecrecord-' + self.url_name
- try:
- idx = int(self.session_get_value(request, storage,
- main_form_key, 'pk'))
- current_cr = models.ContextRecord.objects.get(pk=idx)
- return current_cr
- except(TypeError, ValueError, ObjectDoesNotExist):
- pass
- current_item = self.get_current_object(request, storage)
- if current_item:
- base_items = current_item.base_items.all()
- if base_items:
- return base_items[0].context_record
-
- def get_template_context(self, request, storage, form=None):
- """
- Get the operation and context record "reminder" on top of wizard forms
- """
- context = super(ItemWizard, self).get_template_context(request,
- storage, form)
- current_cr = self.get_current_contextrecord(request, storage)
- if not current_cr:
- return context
- operation = current_cr.operation
- items = []
- if hasattr(operation, 'code_patriarche') and operation.code_patriarche:
- items.append(unicode(operation.code_patriarche))
- items.append("-".join((unicode(operation.year),
- unicode(operation.operation_code))))
- reminder = unicode(_("Current operation: ")) + u" - ".join(items)
- reminder += u"<br/>" + unicode(_("Current context record: "))\
- + unicode(current_cr.label)
- context['reminder'] = mark_safe(reminder)
- return context
-
- def get_extra_model(self, dct, request, storage, form_list):
- dct = super(ItemWizard, self).get_extra_model(dct, request, storage,
- form_list)
- dct['order'] = 1
- if 'pk' in dct and type(dct['pk']) == models.ContextRecord:
- dct['base_items__context_record'] = dct.pop('pk')
- return dct
-
-class ItemForm(forms.Form):
- form_label = _("Item")
- base_model = 'base_items'
- associated_models = {'material_type':models.MaterialType,}
- label = forms.CharField(label=_(u"ID"),
- validators=[validators.MaxLengthValidator(60)])
- description = forms.CharField(label=_("Description"),
- widget=forms.Textarea)
- base_items__is_isolated = forms.NullBooleanField(label=_(u"Is isolated?"),
- required=False)
- material_type = forms.ChoiceField(label=_("Material type"),
- choices=models.MaterialType.get_types())
- volume = FloatField(label=_(u"Volume (l)"), required=False)
- weight = FloatField(label=_(u"Weight (g)"), required=False)
- item_number = forms.IntegerField(label=_(u"Item number"), required=False)
-
-class DateForm(forms.Form):
- form_label = _("Dating")
- base_model = 'dating'
- associated_models = {'dating__dating_type':models.DatingType,
- 'dating__quality':models.DatingQuality,
- 'dating__period':models.Period}
- dating__period = forms.ChoiceField(label=_("Period"),
- choices=models.Period.get_types())
- 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=models.DatingQuality.get_types())
- dating__dating_type = forms.ChoiceField(label=_("Dating type"),
- required=False, choices=[])
-
- def __init__(self, *args, **kwargs):
- super(DateForm, self).__init__(*args, **kwargs)
- self.fields['dating__dating_type'].choices = models.DatingType.get_types()
- self.fields['dating__dating_type'].help_text = models.DatingType.get_help()
-
-item_creation_wizard = ItemWizard([
- ('selecrecord-item_creation', RecordFormSelection),
- ('item-item_creation', ItemForm),
- ('dating-item_creation', DateForm),
- ('final-item_creation', FinalForm)],
- url_name='item_creation',)
-
-class ItemSelect(forms.Form):
- base_items__context_record__parcel__town = get_town_field()
- base_items__context_record__operation__year = forms.IntegerField(
- label=_(u"Year"))
- base_items__context_record__operation__code_patriarche = \
- forms.IntegerField(label=_(u"Code PATRIARCHE"))
- dating__period = forms.ChoiceField(
- label=_(u"Period"), choices=models.Period.get_types())
- # TODO search by warehouse
- material_type = forms.ChoiceField(
- label=_("Material type"), choices=models.MaterialType.get_types())
- base_items__item__description = forms.CharField(label=_(u"Description"))
- base_items__is_isolated = forms.NullBooleanField(label=_(u"Is isolated?"))
-
-class ItemFormSelection(forms.Form):
- form_label = _("Item search")
- associated_models = {'pk':models.Item}
- currents = {'pk':models.Item}
- pk = forms.IntegerField(label="", required=False,
- widget=widgets.JQueryJqGrid(reverse_lazy('get-item'),
- ItemSelect(), models.Item),
- validators=[models.valid_id(models.Item)])
-
-item_search_wizard = SearchWizard([
- ('general-item_search', ItemFormSelection)],
- url_name='item_search',)
-
-item_modification_wizard = ItemWizard([
- ('selec-item_modification', ItemFormSelection),
- ('item-item_modification', ItemForm),
- ('dating-item_modification', DateForm),
- ('final-item_modification', FinalForm)],
- url_name='item_modification',)
-
-class TreatmentWizard(Wizard):
- model = models.Treatment
-
-class BaseTreatmentForm(forms.Form):
- form_label = _(u"Base treatment")
- associated_models = {'treatment_type':models.TreatmentType,
- 'person':models.Person,
- 'location':models.Warehouse}
- treatment_type = forms.ChoiceField(label=_(u"Treatment type"),
- choices=models.TreatmentType.get_types())
- description = forms.CharField(label=_(u"Description"),
- widget=forms.Textarea, required=False)
- person = forms.IntegerField(label=_(u"Person"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-person'), associated_model=models.Person),
- validators=[models.valid_id(models.Person)])
- location = forms.IntegerField(label=_(u"Location"),
- widget=widgets.JQueryAutoComplete(
- reverse_lazy('autocomplete-warehouse'), associated_model=models.Warehouse,
- new=True),
- validators=[models.valid_id(models.Warehouse)])
- start_date = forms.DateField(label=_(u"Start date"), required=False,
- widget=widgets.JQueryDate)
- end_date = forms.DateField(label=_(u"End date"), required=False,
- widget=widgets.JQueryDate)
-
-class ItemMultipleFormSelection(forms.Form):
- form_label = _(u"Upstream items")
- associated_models = {'items':models.Item}
- items = forms.IntegerField(label="", required=False,
- widget=widgets.JQueryJqGrid(reverse_lazy('get-item'),
- ItemSelect(), models.Item, multiple=True),
- validators=[models.valid_id(models.Item)])
-
-class ContainerForm(forms.Form):
- form_label = _(u"Container")
- associated_models = {'container_type':models.ContainerType,}
- reference = forms.CharField(label=_(u"Reference"))
- container_type = forms.ChoiceField(label=_(u"Container type"),
- choices=models.ContainerType.get_types())
- comment = forms.CharField(label=_(u"Comment"),
- widget=forms.Textarea, required=False)
-
-def check_treatment(form_name, type_key, type_list=[], not_type_list=[]):
- type_list = [models.TreatmentType.objects.get(txt_idx=tpe).pk
- for tpe in type_list]
- not_type_list = [models.TreatmentType.objects.get(txt_idx=tpe).pk
- for tpe in not_type_list]
- def func(self, request, storage):
- if storage.prefix not in request.session or \
- 'step_data' not in request.session[storage.prefix] or \
- form_name not in request.session[storage.prefix]['step_data'] or\
- form_name + '-' + type_key not in \
- request.session[storage.prefix]['step_data'][form_name]:
- return False
- try:
- type = int(request.session[storage.prefix]['step_data']\
- [form_name][form_name+'-'+type_key])
- return (not type_list or type in type_list) \
- and type not in not_type_list
- except ValueError:
- return False
- return func
-
-class ResultItemForm(forms.Form):
- form_label = _("Resulting item")
- associated_models = {'material_type':models.MaterialType}
- label = forms.CharField(label=_(u"ID"),
- validators=[validators.MaxLengthValidator(60)])
- description = forms.CharField(label=_("Precise description"),
- widget=forms.Textarea)
- material_type = forms.ChoiceField(label=_("Material type"),
- choices=models.MaterialType.get_types())
- volume = forms.IntegerField(label=_(u"Volume (l)"))
- weight = forms.IntegerField(label=_(u"Weight (g)"))
- item_number = forms.IntegerField(label=_(u"Item number"))
-
-ResultItemFormSet = formset_factory(ResultItemForm, can_delete=True,
- formset=FormSet)
-ResultItemFormSet.form_label = _(u"Resulting items")
-
-class UpstreamItemFormSelection(ItemFormSelection):
- form_label = _(u"Upstream item")
-
-treatment_creation_wizard = TreatmentWizard([
- ('basetreatment-treatment_creation', BaseTreatmentForm),
- ('selecitem-treatment_creation', UpstreamItemFormSelection),
- ('multiselecitems-treatment_creation', ItemMultipleFormSelection),
- ('container-treatment_creation', ContainerForm),
- ('resultitem-treatment_creation', ResultItemForm),
- ('resultitems-treatment_creation', ResultItemFormSet),
- ('final-treatment_creation', FinalForm)],
- condition_list={
-'selecitem-treatment_creation':
- check_treatment('basetreatment-treatment_creation', 'treatment_type',
- not_type_list=['physical_grouping']),
-'multiselecitems-treatment_creation':
- check_treatment('basetreatment-treatment_creation', 'treatment_type',
- ['physical_grouping']),
-'resultitems-treatment_creation':
- check_treatment('basetreatment-treatment_creation', 'treatment_type',
- ['split']),
-'resultitem-treatment_creation':
- check_treatment('basetreatment-treatment_creation', 'treatment_type',
- not_type_list=['split']),
-'container-treatment_creation':
- check_treatment('basetreatment-treatment_creation', 'treatment_type',
- ['packaging']),
- },
- url_name='treatment_creation',)
-