summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/forms.py24
-rw-r--r--archaeological_operations/views.py14
-rw-r--r--archaeological_operations/widgets.py43
3 files changed, 77 insertions, 4 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index 5501857ba..547daf828 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -35,13 +35,23 @@ from django.utils.translation import ugettext_lazy as _
from ishtar_common.models import valid_id, PersonType, Person, Town
from archaeological_files.models import File
import models
+from widgets import ParcelWidget
from ishtar_common import widgets
from ishtar_common.forms import FinalForm, FormSet, ClosingDateFormSelection, \
- formset_factory, get_now, reverse_lazy, get_form_selection
+ formset_factory, get_now, reverse_lazy, get_form_selection, TableSelect
from ishtar_common.forms_common import TownForm, TownFormSet, TownFormset, \
AuthorFormset, SourceForm, SourceSelect, \
SourceDeletionForm, get_town_field
+class ParcelField(forms.MultiValueField):
+ def __init__(self, *args, **kwargs):
+ if 'widget' not in kwargs:
+ self.widget = ParcelWidget()
+ return super(ParcelField, self).__init__(*args, **kwargs)
+
+ def compress(data_list):
+ return u"-".join(data_list)
+
class ParcelForm(forms.Form):
form_label = _("Parcels")
base_model = 'parcel'
@@ -93,7 +103,7 @@ ParcelFormSet = formset_factory(ParcelForm, can_delete=True,
formset=ParcelFormSet)
ParcelFormSet.form_label = _(u"Parcels")
-class OperationSelect(forms.Form):
+class OperationSelect(TableSelect):
common_name = forms.CharField(label=_(u"Name"), max_length=30)
if settings.COUNTRY == 'fr':
code_patriarche = forms.IntegerField(
@@ -120,6 +130,7 @@ class OperationSelect(forms.Form):
widget=widgets.JQueryDate)
end_after = forms.DateField(label=_(u"Ended after"),
widget=widgets.JQueryDate)
+ parcel = ParcelField(label=_("Parcel (section/number)"))
end_date = forms.NullBooleanField(label=_(u"Is open?"))
def __init__(self, *args, **kwargs):
@@ -127,6 +138,13 @@ class OperationSelect(forms.Form):
self.fields['operation_type'].choices = models.OperationType.get_types()
self.fields['operation_type'].help_text = models.OperationType.get_help()
+ def get_input_ids(self):
+ ids = super(OperationSelect, self).get_input_ids()
+ ids.pop(ids.index('parcel'))
+ ids.append('parcel_0')
+ ids.append('parcel_1')
+ return ids
+
class OperationFormSelection(forms.Form):
form_label = _(u"Operation search")
associated_models = {'pk':models.Operation}
@@ -425,7 +443,7 @@ OperationSourceFormSelection = get_form_selection(
# Administrative act management for operations #
################################################
-class AdministrativeActOpeSelect(forms.Form):
+class AdministrativeActOpeSelect(TableSelect):
operation__towns = get_town_field()
act_type = forms.ChoiceField(label=_("Act type"), choices=[])
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 4650e4764..84f208bf3 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -92,6 +92,14 @@ def get_available_operation_code(request, year=None):
data = json.dumps({'id':models.Operation.get_available_operation_code(year)})
return HttpResponse(data, mimetype='text/plain')
+def get_parcel_parser(key_section, key_number):
+ def func(dct):
+ print dct
+ section, number = dct.get(key_section), dct.get(key_number)
+ if not section or not number:
+ return {}
+ return {key_section:section, key_number:number}
+
get_operation = get_item(models.Operation, 'get_operation', 'operation',
bool_fields = ['end_date__isnull'],
dated_fields = ['start_date__lte', 'start_date__gte',
@@ -102,7 +110,11 @@ get_operation = get_item(models.Operation, 'get_operation', 'operation',
'start_before':'start_date__lte',
'start_after':'start_date__gte',
'end_before':'excavation_end_date__lte',
- 'end_after':'excavation_end_date__gte',})
+ 'end_after':'excavation_end_date__gte',
+ 'parcel_0':'parcels__section',
+ 'parcel_1':'parcels__parcel_number',
+ },
+ )
show_operation = show_item(models.Operation, 'operation')
revert_operation = revert_item(models.Operation)
diff --git a/archaeological_operations/widgets.py b/archaeological_operations/widgets.py
new file mode 100644
index 000000000..0e84b2047
--- /dev/null
+++ b/archaeological_operations/widgets.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 É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.
+
+from django import forms
+from django.forms import widgets
+
+class ParcelWidget(widgets.MultiWidget):
+ def __init__(self, attrs=None):
+ if not attrs:
+ attrs = {'class':'widget-parcel'}
+ elif 'class' not in attrs:
+ attrs['class'] = 'widget-parcel'
+ else:
+ attrs['class'] += ' widget-parcel'
+ _widgets = (
+ widgets.TextInput(attrs=attrs),
+ widgets.TextInput(attrs=attrs),
+ )
+ super(ParcelWidget, self).__init__(_widgets, attrs)
+
+ def decompress(self, value):
+ if value:
+ return value
+ return [None, None]
+
+ def format_output(self, rendered_widgets):
+ return u' / '.join(rendered_widgets)