summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.example5
-rw-r--r--archaeological_context_records/tests.py59
-rw-r--r--ishtar_common/models_common.py2
-rw-r--r--ishtar_common/views_item.py11
4 files changed, 71 insertions, 6 deletions
diff --git a/Makefile.example b/Makefile.example
index 3db2ca477..ef6259b58 100644
--- a/Makefile.example
+++ b/Makefile.example
@@ -10,6 +10,7 @@ export PATH := $(HOME)/bin/geckodriver:$(PATH)
project=example_project
# list used apps
apps="ishtar_common" "archaeological_operations" "archaeological_context_records" "archaeological_files" "archaeological_finds" "archaeological_warehouse"
+apps_test="archaeological_context_records" "ishtar_common" "archaeological_operations" "archaeological_files" "archaeological_finds" "archaeological_warehouse"
default_data='fr'
version=`head -n 1 version.py | cut -d' ' -f2`
branch_name=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"`
@@ -143,10 +144,10 @@ build_gitlab: clean collectstatic makemessages ## specific build for gitlab
cd $(project); $(PYTHON) ./manage.py migrate
test_gitlab: clean collectstatic makemessages ## specific test for gitlab
- cd $(project); $(PYTHON) manage.py test --exclude-tag no_ci --exclude-tag gis --exclude-tag ui --exclude-tag libreoffice $(apps)
+ cd $(project); $(PYTHON) manage.py test --exclude-tag no_ci --exclude-tag gis --exclude-tag ui --exclude-tag libreoffice $(apps_test)
soft_test_gitlab: build_gitlab ## run test for gitlab - do not erase previous database
- cd $(project); $(PYTHON) manage.py test --keep --exclude-tag no_ci --exclude-tag gis --exclude-tag ui --exclude-tag libreoffice $(apps)
+ cd $(project); $(PYTHON) manage.py test --keep --exclude-tag no_ci --exclude-tag gis --exclude-tag ui --exclude-tag libreoffice $(apps_test)
run_libreoffice: ## run libreoffice daemon for testing purpose
/usr/bin/libreoffice --headless --accept="socket,host=127.0.0.1,port=8101;urp;" --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --invisible --pidfile=/var/run/libreoffice.pid
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index 22c9d9197..e0c6e4399 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -34,11 +34,17 @@ from django.utils.translation import pgettext_lazy
from ishtar_common.models import (
Area,
+ CustomForm,
+ CustomFormJsonField,
+ FormaterType,
get_current_profile,
+ ImporterColumn,
ImporterModel,
ImporterType,
+ ImportTarget,
IshtarSiteProfile,
IshtarUser,
+ JsonDataField,
ProfileType,
Town,
UserProfile,
@@ -354,6 +360,59 @@ class ExportTest(ContextRecordInit, TestCase):
self.assertEqual(row_cr[1], "12345")
self.assertEqual(row_cr[2], "A1")
+ def test_ishtar_export_json_field(self):
+ """
+ Export JSON fields with a JSON search (#6602)
+ """
+ ope = self.create_operation()[0]
+ ope.code_patriarche = "45000"
+ ope.save()
+ self.create_context_record(
+ data={"label": "CR 1", "data": {"test": "value test"}}
+ )
+ imp = ImporterType.objects.get(slug="ishtar-context-record")
+ col_number = imp.columns.order_by("-col_number").values_list(
+ "col_number", flat=True
+ )[0] + 1
+ col = ImporterColumn.objects.create(
+ col_number=col_number, label="Json value", importer_type=imp
+ )
+ ImportTarget.objects.create(
+ column=col, target="data__test",
+ formater_type=FormaterType.objects.get(
+ formater_type="UnicodeFormater", options="")
+ )
+
+ json_field = JsonDataField.objects.create(
+ name="test", key="test",
+ content_type=ContentType.objects.get_for_model(models.ContextRecord)
+ )
+ cf = CustomForm.objects.create(
+ name="Contect record search form",
+ form="contextrecord-001-search",
+ apply_to_all=True
+ )
+ CustomFormJsonField.objects.create(json_field=json_field, custom_form=cf,
+ order=200)
+
+ c = Client()
+
+ url = reverse(
+ "get-by-importer", kwargs={"slug": "ishtar-context-record", "type": "csv"}
+ )
+ get_args = {"search_vector": 'test="value test"'}
+ response = c.get(url, get_args)
+ # no result when no authentication
+ self.assertTrue(not response.content)
+ c.login(username=self.username, password=self.password)
+ response = c.get(url, get_args)
+ ENCODING = settings.ENCODING or "utf-8"
+ rows = list(csv.reader(StringIO(response.content.decode(ENCODING))))
+ # one header + one context record
+ self.assertEqual(len(rows), 2)
+ row_cr = rows[1]
+ self.assertEqual(row_cr[-1], "value test")
+
class ContextRecordTest(ContextRecordInit, TestCase):
fixtures = CONTEXT_RECORD_TOWNS_FIXTURES
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index c68d3252b..9ce5b9e70 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -1005,7 +1005,9 @@ class FullSearch(models.Model):
@classmethod
def get_default_search_form(cls):
# DEFAULT_SEARCH_FORM is used to get the form when exporting tables
+ # necessary to manage correctly search with json fields
if not cls.DEFAULT_SEARCH_FORM:
+ print(f"**WARNING** DEFAULT_SEARCH_FORM not specified for {cls}")
return
form = getattr(import_module(cls.DEFAULT_SEARCH_FORM[0]),
cls.DEFAULT_SEARCH_FORM[1])
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 2d22a93cc..82eb4c7a8 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -2588,12 +2588,15 @@ def get_item(
)
request_keys.update(my_extra_request_keys)
+ current_search_form = search_form
+ if not current_search_form and hasattr(model, "get_default_search_form"):
+ current_search_form = model.get_default_search_form()
+
# manage search on json fields and excluded fields
ishtaruser = request.user.ishtaruser if request else ishtaruser
- if search_form:
- available, __, excluded_fields, json_fields = search_form.check_custom_form(
- ishtaruser
- )
+ if current_search_form:
+ available, __, excluded_fields, json_fields = \
+ current_search_form.check_custom_form(ishtaruser)
# for now no manage on excluded_fields: should we prevent search on
# some fields regarding the user concerned?
if available: