diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-08-19 12:04:58 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-08-19 12:04:58 +0200 |
commit | 6443d7865bd7ac37cf3969b429cf0659b7d7ac2e (patch) | |
tree | de69c2af87cef1e2c7f89feae3c53aaa860c96d8 | |
parent | 958a9a61c3a6fc54189fe941cb41782d1d19e9ed (diff) | |
download | Ishtar-6443d7865bd7ac37cf3969b429cf0659b7d7ac2e.tar.bz2 Ishtar-6443d7865bd7ac37cf3969b429cf0659b7d7ac2e.zip |
Operations: check PATRIARCHE unicity inside forms (refs #2930)
-rw-r--r-- | archaeological_context_records/forms.py | 5 | ||||
-rw-r--r-- | archaeological_finds/forms.py | 10 | ||||
-rw-r--r-- | archaeological_operations/forms.py | 25 | ||||
-rw-r--r-- | archaeological_operations/models.py | 4 | ||||
-rw-r--r-- | archaeological_operations/templates/ishtar/blocks/OAWidget.html | 1 | ||||
-rw-r--r-- | archaeological_operations/widgets.py | 18 | ||||
-rw-r--r-- | ishtar_common/static/media/style.css | 5 |
7 files changed, 57 insertions, 11 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py index 512d2069b..0bdc04fb4 100644 --- a/archaeological_context_records/forms.py +++ b/archaeological_context_records/forms.py @@ -34,6 +34,7 @@ from archaeological_operations.models import Period, Parcel, Operation, \ import models from ishtar_common import widgets +from archaeological_operations.widgets import OAWidget from ishtar_common.forms import FinalForm, FormSet, \ reverse_lazy, get_form_selection, TableSelect from ishtar_common.forms_common import get_town_field, SourceSelect @@ -46,6 +47,7 @@ class RecordSelect(TableSelect): parcel__town = get_town_field() if settings.COUNTRY == 'fr': operation__code_patriarche = forms.IntegerField( + widget=OAWidget, label=_(u"Code PATRIARCHE")) operation__year = forms.IntegerField(label=_(u"Operation's year")) operation__operation_code = forms.IntegerField( @@ -295,7 +297,8 @@ class RecordSourceSelect(SourceSelect): label=_(u"Numeric reference")) if settings.COUNTRY == 'fr': context_record__operation__code_patriarche = forms.IntegerField( - label="Numéro d'opération (OA Patriarche)") + widget=OAWidget, + label="Code PATRIARCHE") context_record__parcel__town = get_town_field( label=_(u"Town of the operation")) context_record__datings__period = forms.ChoiceField( diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index ba6426cae..e3082c736 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -38,6 +38,7 @@ from archaeological_warehouse.models import Warehouse import models from ishtar_common import widgets +from archaeological_operations.widgets import OAWidget from ishtar_common.forms import FormSet, FloatField, \ get_form_selection, reverse_lazy, TableSelect, get_now, FinalForm from ishtar_common.forms_common import get_town_field, SourceSelect @@ -204,7 +205,10 @@ class FindSelect(TableSelect): base_finds__context_record__operation__year = forms.IntegerField( label=_(u"Year")) base_finds__context_record__operation__code_patriarche = \ - forms.IntegerField(label=_(u"Code PATRIARCHE")) + forms.IntegerField( + label=_(u"Code PATRIARCHE"), + widget=OAWidget + ) archaeological_sites = forms.IntegerField( label=_("Archaelogical site"), widget=widgets.JQueryAutoComplete( @@ -448,7 +452,9 @@ class FindSourceSelect(SourceSelect): forms.IntegerField(label=_(u"Numeric reference")) if settings.COUNTRY == 'fr': find__base_finds__context_record__operation__code_patriarche = \ - forms.IntegerField(label="Numéro d'opération (OA Patriarche)") + forms.IntegerField( + widget=OAWidget, + label="Code PATRIARCHE") find__datings__period = forms.ChoiceField( label=_(u"Period of the archaelogical find"), choices=[]) find__material_type = forms.ChoiceField( diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py index 644114619..eaba1bca3 100644 --- a/archaeological_operations/forms.py +++ b/archaeological_operations/forms.py @@ -41,7 +41,7 @@ from ishtar_common.wizards import MultiValueDict from archaeological_files.models import File import models -from widgets import ParcelWidget, SelectParcelWidget +from widgets import ParcelWidget, SelectParcelWidget, OAWidget from ishtar_common import widgets from ishtar_common.forms import FinalForm, FormSet, get_now, \ @@ -458,7 +458,8 @@ class OperationSelect(TableSelect): operation_code = forms.IntegerField(label=_(u"Numeric reference")) if settings.COUNTRY == 'fr': code_patriarche = forms.IntegerField( - label="Numéro d'opération (OA Patriarche)") + widget=OAWidget, + label="Code PATRIARCHE") towns = get_town_field() parcel = ParcelField(label=_("Parcel (section/number/public domain)")) if settings.ISHTAR_DPTS: @@ -721,6 +722,7 @@ class OperationFormGeneral(forms.Form): pk = forms.IntegerField(required=False, widget=forms.HiddenInput) if settings.COUNTRY == 'fr': code_patriarche = forms.IntegerField(label=u"Code PATRIARCHE", + widget=OAWidget, required=False) common_name = forms.CharField(label=_(u"Generic name"), required=False, max_length=120, widget=forms.Textarea) @@ -831,13 +833,24 @@ class OperationFormGeneral(forms.Form): raise forms.ValidationError( _(u"The excavation end date cannot be before the start " u"date.")) + # verify patriarche + code_p = self.cleaned_data.get('code_patriarche', None) + + if code_p: + ops = models.Operation.objects.filter(code_patriarche=code_p) + if 'pk' in cleaned_data and cleaned_data['pk']: + ops = ops.exclude(pk=cleaned_data['pk']) + if ops.count(): + msg = _(u"Ce code Patriarche a déjà été affecté à une " + u"autre opération") + raise forms.ValidationError(msg) + # manage unique operation ID year = self.cleaned_data.get("year") operation_code = cleaned_data.get("operation_code", None) if not operation_code: return self.cleaned_data ops = models.Operation.objects.filter(year=year, operation_code=operation_code) - # manage unique operation ID if 'pk' in cleaned_data and cleaned_data['pk']: ops = ops.exclude(pk=cleaned_data['pk']) if ops.count(): @@ -1150,7 +1163,8 @@ class OperationSourceSelect(SourceSelect): label=_(u"Numeric reference")) if settings.COUNTRY == 'fr': operation__code_patriarche = forms.IntegerField( - label="Numéro d'opération (OA Patriarche)") + widget=OAWidget, + label="Code PATRIARCHE") operation__towns = get_town_field(label=_(u"Operation's town")) operation__operation_type = forms.ChoiceField(label=_(u"Operation type"), choices=[]) @@ -1181,7 +1195,8 @@ class AdministrativeActOpeSelect(TableSelect): ref_sra = forms.CharField(label=u"Autre référence", max_length=15) operation__code_patriarche = forms.IntegerField( - label="Numéro d'opération (OA Patriarche)") + widget=OAWidget, + label="Code PATRIARCHE") act_type = forms.ChoiceField(label=_("Act type"), choices=[]) indexed = forms.NullBooleanField(label=_(u"Indexed?")) operation__towns = get_town_field() diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index ec2a29f51..de44e6d97 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -846,8 +846,8 @@ class Parcel(LightHistorizedItem): nb += unicode(_(u"Public domain")) grouped[-1].parcel_numbers.append(nb) grouped[-1].parcel_numbers.sort() - grouped[-1].parcel_numbers = [strip_zero(nb) - for nb in grouped[-1].parcel_numbers] + grouped[-1].parcel_numbers = [strip_zero(n) + for n in grouped[-1].parcel_numbers] return grouped @classmethod diff --git a/archaeological_operations/templates/ishtar/blocks/OAWidget.html b/archaeological_operations/templates/ishtar/blocks/OAWidget.html new file mode 100644 index 000000000..a1df5a00c --- /dev/null +++ b/archaeological_operations/templates/ishtar/blocks/OAWidget.html @@ -0,0 +1 @@ +OA <input class="widget-oa" type="text"{{final_attrs|safe}}> diff --git a/archaeological_operations/widgets.py b/archaeological_operations/widgets.py index 3a4c458f6..bb219ab76 100644 --- a/archaeological_operations/widgets.py +++ b/archaeological_operations/widgets.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (C) 2013 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# Copyright (C) 2013-2016 É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 @@ -17,7 +17,9 @@ # See the file COPYING for details. +from django import forms from django.forms import widgets +from django.template import Context, loader from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ @@ -52,3 +54,17 @@ class SelectParcelWidget(widgets.TextInput): render += u" <button name='formset_add' value='add'>%s</button>" \ % _(u"Add") return mark_safe(render) + + +class OAWidget(forms.TextInput): + def render(self, name, value, attrs=None): + if not value: + value = u"" + final_attrs = widgets.flatatt( + self.build_attrs(attrs, name=name, value=value)) + dct = {'final_attrs': final_attrs, + 'id': attrs['id'], + "safe_id": attrs['id'].replace('-', '_')} + t = loader.get_template('ishtar/blocks/OAWidget.html') + rendered = t.render(Context(dct)) + return mark_safe(rendered) diff --git a/ishtar_common/static/media/style.css b/ishtar_common/static/media/style.css index 3c7dd8d32..7aef23099 100644 --- a/ishtar_common/static/media/style.css +++ b/ishtar_common/static/media/style.css @@ -1112,6 +1112,11 @@ a.remove{ width:50px; } +.form p.input input.widget-oa, +input.widget-oa{ + width:100px; +} + .small, .small input{ width:60px; } |