summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_operations/forms.py5
-rw-r--r--archaeological_operations/models.py1
-rw-r--r--archaeological_operations/urls.py6
-rw-r--r--archaeological_operations/views.py24
4 files changed, 34 insertions, 2 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index f5f0fea99..62425b68d 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -95,6 +95,11 @@ ParcelFormSet.form_label = _(u"Parcels")
class OperationSelect(forms.Form):
common_name = forms.CharField(label=_(u"Name"), max_length=30)
+ if settings.COUNTRY == 'fr':
+ code_patriarche = forms.IntegerField(
+ widget=widgets.JQueryAutoComplete("/" + settings.URL_PATH + \
+ 'autocomplete-patriarche/'),
+ label="Code PATRIARCHE")
towns = get_town_field()
operation_type = forms.ChoiceField(label=_(u"Operation type"),
choices=[])
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index 399b536e2..675666dbb 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -163,6 +163,7 @@ class Operation(BaseHistorizedItem, OwnPerms):
def year_index(self):
if not self.operation_code:
return ""
+ lbl = unicode(self.operation_code)
lbl = u"%d-%s%s" % (self.year, (3-len(lbl))*"0", lbl)
return lbl
diff --git a/archaeological_operations/urls.py b/archaeological_operations/urls.py
index 23632f1cf..0da649d2d 100644
--- a/archaeological_operations/urls.py
+++ b/archaeological_operations/urls.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# Copyright (C) 2010-2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet>
+# Copyright (C) 2010-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
@@ -72,5 +72,7 @@ urlpatterns += patterns('archaeological_operations.views',
url(r'get-operationsource/(?P<type>.+)?$',
'get_operationsource', name='get-operationsource'),
url(r'dashboard_operation/$', 'dashboard_operation',
- name='dashboard-operation')
+ name='dashboard-operation'),
+ url(r'autocomplete-patriarche/$', 'autocomplete_patriarche',
+ name='autocomplete-patriarche'),
)
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 9aa2222ba..96fd2efd2 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -30,6 +30,30 @@ from wizards import *
from forms import *
import models
+def autocomplete_patriarche(request, non_closed=True):
+ person_types = request.user.ishtaruser.person.person_type
+ if (not request.user.has_perm('ishtar_common.view_operation',
+ models.Operation)
+ and not request.user.has_perm('ishtar_common.view_own_operation',
+ models.Operation)
+ and not person_types.rights.filter(
+ wizard__url_name='operation_search').count()):
+ return HttpResponse(mimetype='text/plain')
+ if not request.GET.get('term'):
+ return HttpResponse(mimetype='text/plain')
+ q = request.GET.get('term')
+ query = Q()
+ for q in q.split(' '):
+ query = query & Q(code_patriarche__startswith=q)
+ if non_closed:
+ query = query & Q(end_date__isnull=True)
+ limit = 15
+ operations = models.Operation.objects.filter(query)[:limit]
+ data = json.dumps([{'id':operation.code_patriarche,
+ 'value':operation.code_patriarche}
+ for operation in operations])
+ return HttpResponse(data, mimetype='text/plain')
+
def autocomplete_operation(request, non_closed=True):
person_types = request.user.ishtaruser.person.person_type
if (not request.user.has_perm('ishtar_common.view_operation',