summaryrefslogtreecommitdiff
path: root/archaeological_operations
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_operations')
-rw-r--r--archaeological_operations/forms.py11
-rw-r--r--archaeological_operations/models.py13
-rw-r--r--archaeological_operations/tests.py59
3 files changed, 73 insertions, 10 deletions
diff --git a/archaeological_operations/forms.py b/archaeological_operations/forms.py
index cbaa37310..4e01a492a 100644
--- a/archaeological_operations/forms.py
+++ b/archaeological_operations/forms.py
@@ -472,6 +472,8 @@ RecordRelationsFormSet.form_slug = "operation-080-relations"
class OperationSelect(TableSelect):
+ _model = models.Operation
+
search_vector = forms.CharField(label=_(u"Full text search"),
widget=widgets.SearchWidget)
year = forms.IntegerField(label=_("Year"))
@@ -486,12 +488,9 @@ class OperationSelect(TableSelect):
if settings.ISHTAR_DPTS:
towns__numero_insee__startswith = forms.ChoiceField(
label=_(u"Department"), choices=[])
- common_name = forms.CharField(label=_(u"Name"),
- max_length=30)
- address = forms.CharField(label=_(u"Address / Locality"),
- max_length=100)
- operation_type = forms.ChoiceField(label=_(u"Operation type"),
- choices=[])
+ common_name = forms.CharField(label=_(u"Name"), max_length=30)
+ address = forms.CharField(label=_(u"Address / Locality"), max_length=100)
+ operation_type = forms.ChoiceField(label=_(u"Operation type"), choices=[])
end_date = forms.NullBooleanField(label=_(u"Is open?"))
in_charge = forms.IntegerField(
widget=widgets.JQueryAutoComplete(
diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py
index d50c9e43c..688c12bea 100644
--- a/archaeological_operations/models.py
+++ b/archaeological_operations/models.py
@@ -27,7 +27,7 @@ from django.db import IntegrityError, transaction
from django.db.models import Q, Count, Sum, Max, Avg
from django.db.models.signals import post_save, m2m_changed, post_delete
from django.forms import ValidationError
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext_lazy as _, pgettext_lazy
from ishtar_common.models import BaseHistorizedItem, Dashboard, \
DashboardFormItem, Department, Document, DocumentTemplate, \
@@ -362,6 +362,17 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,
},
}
+ # alternative names of fields for searches
+ ALT_NAMES = {
+ 'periods__pk': pgettext_lazy(
+ "key for text search (no accent, no spaces)", u"period"),
+ 'operation_type__pk': pgettext_lazy(
+ "key for text search (no accent, no spaces)", u"operation-type"),
+ 'remains__pk': pgettext_lazy(
+ "key for text search (no accent, no spaces)", u"remain"),
+ }
+ EXTRA_REQUEST_KEYS.update(dict([(v, k) for k, v in ALT_NAMES.items()]))
+
# fields definition
creation_date = models.DateField(_(u"Creation date"),
default=datetime.date.today)
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 381efd070..1480eb502 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -33,7 +33,7 @@ from django.db.models import Q
from django.test.client import Client
from django.contrib.auth.models import User, Permission
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext_lazy as _, pgettext
import models
from archaeological_operations import views
@@ -1538,11 +1538,64 @@ class OperationSearchTest(TestCase, OperationInitTest):
self.assertEqual(result['recordsTotal'], 2)
# open search
- response = c.get(reverse('get-operation'),
- {'search_vector': 'cha*'})
+ response = c.get(reverse('get-operation'), {'search_vector': 'cha*'})
result = json.loads(response.content)
self.assertEqual(result['recordsTotal'], 3)
+ def test_facet_search_vector(self):
+ ope1 = self.operations[0]
+ ope2 = self.operations[1]
+ ope3 = self.operations[2]
+ c = Client()
+ c.login(username=self.username, password=self.password)
+
+ neo = models.Period.objects.get(txt_idx='neolithic')
+ final_neo = models.Period.objects.get(txt_idx='final-neolithic')
+ gallo = models.Period.objects.get(txt_idx="gallo-roman")
+ ope1.periods.add(final_neo)
+ ope1.periods.add(gallo)
+ ope2.periods.add(neo)
+ ope3.periods.add(gallo)
+
+ villa = models.RemainType.objects.get(txt_idx='villa')
+ ope1.remains.add(villa)
+
+ # simple
+ search_q = unicode(
+ pgettext("key for text search (no accent, no spaces)", u"period")
+ )
+ search = {'search_vector': u'{}="{}"'.format(search_q, final_neo.label)}
+ response = c.get(reverse('get-operation'), search)
+ self.assertEqual(response.status_code, 200)
+ result = json.loads(response.content)
+ self.assertEqual(result['recordsTotal'], 1)
+
+ # hierarchic
+ search = {'search_vector': u'{}="{}"'.format(search_q, neo.label)}
+ response = c.get(reverse('get-operation'), search)
+ self.assertEqual(response.status_code, 200)
+ result = json.loads(response.content)
+ self.assertEqual(result['recordsTotal'], 2)
+
+ # OR
+ search = {'search_vector': u'{}="{}";"{}"'.format(search_q, neo.label,
+ gallo.label)}
+ response = c.get(reverse('get-operation'), search)
+ self.assertEqual(response.status_code, 200)
+ result = json.loads(response.content)
+ self.assertEqual(result['recordsTotal'], 3)
+
+ # non hierarchic search
+ search_q = unicode(
+ pgettext("key for text search (no accent, no spaces)", u"remain")
+ )
+ search = {'search_vector': u'{}="{}"'.format(search_q, villa.label)}
+ response = c.get(reverse('get-operation'), search)
+ self.assertEqual(response.status_code, 200)
+ result = json.loads(response.content)
+ self.assertEqual(result['recordsTotal'], 1)
+
+
def create_relations(self):
rel1 = models.RelationType.objects.create(
symmetrical=True, label='Include', txt_idx='include')