diff options
| -rw-r--r-- | Makefile.example | 2 | ||||
| -rw-r--r-- | archaeological_operations/tests.py | 59 | ||||
| -rw-r--r-- | ishtar_common/views_item.py | 5 | 
3 files changed, 63 insertions, 3 deletions
| diff --git a/Makefile.example b/Makefile.example index a340f93b0..0d49c0c70 100644 --- a/Makefile.example +++ b/Makefile.example @@ -6,7 +6,7 @@ PYTHON=python3  # put name of your current project  project=example_project  # list used apps -apps="ishtar_common" "archaeological_operations" "archaeological_context_records" "archaeological_files" "archaeological_finds" "archaeological_warehouse" "archaeological_files_pdl" +apps="archaeological_operations" "ishtar_common" "archaeological_context_records" "archaeological_files" "archaeological_finds" "archaeological_warehouse" "archaeological_files_pdl"  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/"` diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index 3f4e73639..192d51214 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -33,6 +33,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile  from django.core.urlresolvers import reverse  from django.db.models import Q  from django.test.client import Client +from django.utils.text import slugify  from django.contrib.auth.models import User, Permission  from django.utils.translation import ugettext_lazy as _, pgettext, pgettext_lazy @@ -2487,6 +2488,64 @@ class CustomFormTest(TestCase, OperationInitTest):              msg="json field form: existing value should be presented in select",          ) +    def test_json_search(self): +        operation = self.operations[0] +        operation.data = { +            "groundhog": { +                "awake_state": "réveillée", +                "with_feather": True, +            }, +        } +        operation.save() + +        content_type = ContentType.objects.get_for_model(operation) +        field = JsonDataField.objects.create( +            name="État d'éveil", +            key="groundhog__awake_state", +            content_type=content_type, +            value_type="C", +        ) +        field2 = JsonDataField.objects.create( +            name="As une plume ?", +            key="groundhog__with_feather", +            content_type=content_type, +            value_type="B", +        ) +        form = CustomForm.objects.create( +            name="Test", form="operation-001-search", available=True, apply_to_all=True +        ) +        cf1 = CustomFormJsonField.objects.create( +            custom_form=form, +            json_field=field, +            label="Est-elle éveillée ?", +        ) +        cf2 = CustomFormJsonField.objects.create( +            custom_form=form, +            json_field=field2, +            label="Plume", +        ) + +        c = Client() +        c.login(username=self.username, password=self.password) + +        response = c.get( +            reverse("get-operation"), +            {"search_vector": "{}=endormie".format(slugify(cf1.label))}) +        result = json.loads(response.content.decode()) +        self.assertEqual(result["recordsTotal"], 0) + +        response = c.get( +            reverse("get-operation"), +            {"search_vector": "{}=réveillée".format(slugify(cf1.label))}) +        result = json.loads(response.content.decode()) +        self.assertEqual(result["recordsTotal"], 1) + +        response = c.get( +            reverse("get-operation"), +            {"search_vector": "{}=oui".format(slugify(cf2.label))}) +        result = json.loads(response.content.decode()) +        self.assertEqual(result["recordsTotal"], 1) +  class OperationSearchTest(TestCase, OperationInitTest, SearchText):      fixtures = FILE_FIXTURES diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index b37bba45c..796a3eb47 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -806,7 +806,7 @@ def _manage_bool_fields(model, bool_fields, reversed_bool_fields, dct, or_reqs):          try:              c_field = model._meta.get_field(field_names[0])              for field_name in field_names[1:-1]: -                if not hasattr(c_field, "related_model"): +                if not hasattr(c_field, "related_model") or not c_field.related_model:                      return                  c_field = c_field.related_model._meta.get_field(field_name)              if k.endswith("__isnull") and ( @@ -1691,7 +1691,8 @@ def get_item(              if available:                  for __, jkey, jfield in json_fields:                      if jfield.alt_name not in request_keys: -                        if isinstance(jfield, (forms.NullBooleanField, forms.BooleanField)): +                        if isinstance(jfield, (forms.NullBooleanField, +                                               forms.BooleanField)):                              my_bool_fields.append(jkey)                              request_keys[jfield.alt_name] = jkey                          else: | 
