From f458f61e9cc55a188ac87cfab5a1bb90a31b702f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 4 Jan 2018 12:16:14 +0100 Subject: Custom form: warehouse forms --- archaeological_warehouse/forms.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'archaeological_warehouse') diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index f020864ff..f98adc33a 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -30,7 +30,8 @@ from archaeological_finds.models import TreatmentType, FindBasket import models from ishtar_common import widgets from ishtar_common.forms import name_validator, reverse_lazy, \ - get_form_selection, TableSelect, ManageOldType, FinalForm, FormSet + get_form_selection, TableSelect, ManageOldType, FinalForm, FormSet, \ + CustomForm, FieldType from archaeological_finds.forms import FindMultipleFormSelection, \ SelectFindBasketForm @@ -67,9 +68,12 @@ class DivisionFormSet(FormSet): return self.check_duplicate(('division',), _("There are identical divisions.")) + SelectedDivisionFormset = formset_factory( SelectedDivisionForm, can_delete=True, formset=DivisionFormSet) SelectedDivisionFormset.form_label = _(u"Divisions") +SelectedDivisionFormset.form_admin_name = _(u"Warehouse - 020 - Divisions") +SelectedDivisionFormset.form_slug = "warehouse-020-divisions" class WarehouseSelect(TableSelect): @@ -97,8 +101,10 @@ class WarehouseFormSelection(forms.Form): validators=[valid_id(models.Warehouse)]) -class WarehouseForm(ManageOldType, forms.Form): +class WarehouseForm(CustomForm, ManageOldType, forms.Form): form_label = _(u"Warehouse") + form_admin_name = _(u"Warehouse - 010 - General") + form_slug = "warehouse-010-general" associated_models = {'warehouse_type': models.WarehouseType, 'person_in_charge': Person} @@ -127,16 +133,14 @@ class WarehouseForm(ManageOldType, forms.Form): phone = forms.CharField(label=_(u"Phone"), max_length=18, required=False) mobile_phone = forms.CharField(label=_(u"Mobile phone"), max_length=18, required=False) + TYPES = [ + FieldType('warehouse_type', models.WarehouseType) + ] def __init__(self, *args, **kwargs): if 'limits' in kwargs: kwargs.pop('limits') super(WarehouseForm, self).__init__(*args, **kwargs) - self.fields['warehouse_type'].choices = \ - models.WarehouseType.get_types( - initial=self.init_data.get('warehouse_type')) - self.fields['warehouse_type'].help_text = \ - models.WarehouseType.get_help() def save(self, user): dct = self.cleaned_data -- cgit v1.2.3