summaryrefslogtreecommitdiff
path: root/archaeological_context_records
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-08-18 13:44:22 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-08-18 13:44:22 +0200
commit6c40a1c20aecdd826760bc5ab87c20dc2ea9f40b (patch)
tree838b2a369a6b10261bb8269366ae5666cb62ecaf /archaeological_context_records
parentd3183ca243377637f84f74862f2b2660a4364198 (diff)
downloadIshtar-6c40a1c20aecdd826760bc5ab87c20dc2ea9f40b.tar.bz2
Ishtar-6c40a1c20aecdd826760bc5ab87c20dc2ea9f40b.zip
Manage operation relation types in context record and find searches (refs #2799)
Diffstat (limited to 'archaeological_context_records')
-rw-r--r--archaeological_context_records/forms.py10
-rw-r--r--archaeological_context_records/tests.py39
-rw-r--r--archaeological_context_records/views.py1
3 files changed, 46 insertions, 4 deletions
diff --git a/archaeological_context_records/forms.py b/archaeological_context_records/forms.py
index 7572b0bcb..512d2069b 100644
--- a/archaeological_context_records/forms.py
+++ b/archaeological_context_records/forms.py
@@ -30,7 +30,7 @@ from django.utils.translation import ugettext_lazy as _
from ishtar_common.models import valid_id
from archaeological_operations.models import Period, Parcel, Operation, \
- ArchaeologicalSite
+ ArchaeologicalSite, RelationType as OpeRelationType
import models
from ishtar_common import widgets
@@ -56,6 +56,9 @@ class RecordSelect(TableSelect):
reverse_lazy('autocomplete-archaeologicalsite'),
associated_model=ArchaeologicalSite),
validators=[valid_id(ArchaeologicalSite)])
+ ope_relation_types = forms.MultipleChoiceField(
+ label=_(u"Search within operation relations"), choices=[],
+ widget=forms.CheckboxSelectMultiple)
datings__period = forms.ChoiceField(label=_(u"Period"), choices=[])
unit = forms.ChoiceField(label=_(u"Unit type"), choices=[])
parcel = ParcelField(label=_(u"Parcel (section/number/public domain)"))
@@ -71,6 +74,8 @@ class RecordSelect(TableSelect):
self.fields['unit'].help_text = models.Unit.get_help()
self.fields['relation_types'].choices = models.RelationType.get_types(
empty_first=False)
+ self.fields['ope_relation_types'].choices = OpeRelationType.get_types(
+ empty_first=False)
def get_input_ids(self):
ids = super(RecordSelect, self).get_input_ids()
@@ -81,6 +86,9 @@ class RecordSelect(TableSelect):
ids.pop(ids.index('relation_types'))
for idx, c in enumerate(self.fields['relation_types'].choices):
ids.append('relation_types_{}'.format(idx))
+ ids.pop(ids.index('ope_relation_types'))
+ for idx, c in enumerate(self.fields['ope_relation_types'].choices):
+ ids.append('ope_relation_types_{}'.format(idx))
return ids
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 614156528..27ba0ab71 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -30,6 +30,7 @@ from ishtar_common.models import ImporterType, IshtarSiteProfile
from ishtar_common.tests import create_superuser
from archaeological_operations.tests import OperationInitTest, \
ImportOperationTest
+from archaeological_operations import models as models_ope
from archaeological_context_records import models
from ishtar_common import forms_common
@@ -126,18 +127,18 @@ class ContextRecordTest(ContextRecordInit, TestCase):
def setUp(self):
IshtarSiteProfile.objects.create()
self.username, self.password, self.user = create_superuser()
- self.create_context_record({"label": u"CR 1"})
- self.create_context_record({"label": u"CR 2"})
+ self.create_context_record(data={"label": u"CR 1"})
+ self.create_context_record(data={"label": u"CR 2"})
cr_1 = self.context_records[0]
cr_2 = self.context_records[1]
sym_rel_type = models.RelationType.objects.filter(
symmetrical=True).all()[0]
+ self.cr_rel_type = sym_rel_type
models.RecordRelations.objects.create(
left_record=cr_1, right_record=cr_2, relation_type=sym_rel_type)
def testSearchExport(self):
- "url = reverse()get-contextrecord-full/csv?submited=1&"
c = Client()
response = c.get(reverse('get-contextrecord'))
# no result when no authentification
@@ -145,6 +146,38 @@ class ContextRecordTest(ContextRecordInit, TestCase):
c.login(username=self.username, password=self.password)
response = c.get(reverse('get-contextrecord'))
self.assertTrue(json.loads(response.content)['total'] == 2)
+ # test search label
+ response = c.get(reverse('get-contextrecord'),
+ {'label': 'cr 1'})
+ self.assertEqual(json.loads(response.content)['total'], 1)
+ # test search between relations
+ response = c.get(reverse('get-contextrecord'),
+ {'label': 'cr 1',
+ 'relation_types_0': self.cr_rel_type.pk})
+ self.assertEqual(json.loads(response.content)['total'], 2)
+ # test search between operation relations
+ first_ope = self.operations[0]
+ first_ope.year = 2010
+ first_ope.save()
+ cr_1 = self.context_records[0]
+ cr_1.operation = first_ope
+ cr_1.save()
+ other_ope = self.operations[1]
+ other_ope.year = 2016
+ other_ope.save()
+ cr_2 = self.context_records[1]
+ cr_2.operation = other_ope
+ cr_2.save()
+ rel_ope = models_ope.RelationType.objects.create(
+ symmetrical=True, label='Linked', txt_idx='link')
+ models_ope.RecordRelations.objects.create(
+ left_record=other_ope,
+ right_record=first_ope,
+ relation_type=rel_ope)
+ response = c.get(reverse('get-contextrecord'),
+ {'operation__year': 2010,
+ 'ope_relation_types_0': rel_ope.pk})
+ self.assertEqual(json.loads(response.content)['total'], 2)
# export
response = c.get(reverse('get-contextrecord-full',
kwargs={'type': 'csv'}), {'submited': '1'})
diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py
index 1b8585b82..4e3dcf7fe 100644
--- a/archaeological_context_records/views.py
+++ b/archaeological_context_records/views.py
@@ -80,6 +80,7 @@ def autocomplete_contextrecord(request):
get_contextrecord = get_item(
models.ContextRecord,
'get_contextrecord', 'contextrecord',
+ relation_types_prefix={'ope_relation_types': 'operation__'},
extra_request_keys=contextrecord_extra_keys,)
get_contextrecord_for_ope = get_item(
models.ContextRecord,