From 7101be68fefe107a5037b11e0f1b9c209e712145 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 2 Jan 2018 18:23:45 +0100 Subject: Custom form: change label --- ishtar_common/models.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ishtar_common/models.py') diff --git a/ishtar_common/models.py b/ishtar_common/models.py index b0751f661..626770011 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1651,6 +1651,9 @@ class CustomForm(models.Model): verbose_name_plural = _(u"Custom forms") ordering = ['name', 'form'] + def __unicode__(self): + return u"{} - {}".format(self.name, self.form) + def users_lbl(self): users = [unicode(user) for user in self.users.all()] return " ; ".join(users) -- cgit v1.2.3 From 7fa12413028c8681f81832770b00bf07a950693d 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 +++++++++++------- ishtar_common/models.py | 4 +++- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'ishtar_common/models.py') 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 diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 626770011..4db445c41 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -23,6 +23,7 @@ Models description from cStringIO import StringIO import copy import datetime +import inspect from PIL import Image import logging import os @@ -1686,7 +1687,8 @@ class CustomForm(models.Model): # not very clean... but do not treat inappropriate items continue form = getattr(app_form, form) - if not issubclass(form, CustomForm) \ + if not inspect.isclass(form) \ + or not issubclass(form, CustomForm) \ or not getattr(form, 'form_slug', None): continue cls._register[form.form_slug] = form -- cgit v1.2.3