diff options
| -rw-r--r-- | archaeological_operations/models.py | 18 | ||||
| -rw-r--r-- | archaeological_operations/tests.py | 11 | ||||
| -rw-r--r-- | ishtar_common/models.py | 15 | 
3 files changed, 41 insertions, 3 deletions
| diff --git a/archaeological_operations/models.py b/archaeological_operations/models.py index 9d6264a4d..435394592 100644 --- a/archaeological_operations/models.py +++ b/archaeological_operations/models.py @@ -446,6 +446,9 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          "scientific_documentation_comment",          "seizure_name",      ] +    PROPERTY_SEARCH_VECTORS = [ +        "full_reference", "short_code_patriarche" +    ]      INT_SEARCH_VECTORS = ["year"]      M2M_SEARCH_VECTORS = ["periods__label", "remains__label", "towns__name"]      PARENT_SEARCH_VECTORS = ["associated_file"] @@ -846,10 +849,25 @@ class Operation(ClosedItem, BaseHistorizedItem, OwnPerms, ValueGetter,          return ref or "00"      @property +    def short_code_patriarche(self): +        if not self.code_patriarche: +            return u"" +        profile = get_current_profile() +        if not profile.operation_region_code or \ +                not self.code_patriarche.startswith( +                    profile.operation_region_code): +            return self.code_patriarche +        return self.code_patriarche[len(profile.operation_region_code):] + +    @property      def reference(self):          return self.get_reference()      @property +    def full_reference(self): +        return self.get_reference(full=True) + +    @property      def report_delivery_delay(self):          return None          # q = self.source.filter(source_type__txt_idx__endswith='_report') diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index a3cd5fd8d..a396adecf 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -1050,10 +1050,15 @@ class OperationTest(TestCase, OperationInitTest):          operation.towns.add(town)          operation = models.Operation.objects.get(pk=operation.pk)          operation.comment = u"Zardoz" -        operation.code_patriarche = u"HUIAAA5" +        profile = get_current_profile() +        profile.operation_region_code = u"42" +        profile.save() +        operation.code_patriarche = u"42HUIAAA5"          operation.save() -        for key in ('old', 'dirty', 'daisy', "'2010'", "zardoz", -                    "huiaaa5"): +        for key in ( +                'old', 'dirty', 'daisy', "'2010'", "zardoz", "huiaaa5", +                "{}42huiaaa5".format(profile.operation_prefix.lower()), +                "42huiaaa5"):              self.assertIn(key, operation.search_vector)      def test_cache_bulk_update(self): diff --git a/ishtar_common/models.py b/ishtar_common/models.py index bd800181f..38e58955b 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1089,6 +1089,7 @@ class FullSearch(models.Model):      search_vector = SearchVectorField(_("Search vector"), blank=True, null=True,                                        help_text=_("Auto filled at save"))      BASE_SEARCH_VECTORS = [] +    PROPERTY_SEARCH_VECTORS = []      INT_SEARCH_VECTORS = []      M2M_SEARCH_VECTORS = []      PARENT_SEARCH_VECTORS = [] @@ -1122,6 +1123,7 @@ class FullSearch(models.Model):              return          if not self.BASE_SEARCH_VECTORS and not self.M2M_SEARCH_VECTORS \                  and not self.INT_SEARCH_VECTORS \ +                and not self.PROPERTY_SEARCH_VECTORS \                  and not self.PARENT_SEARCH_VECTORS:              logger.warning("No search_vectors defined for {}".format(                  self.__class__)) @@ -1191,6 +1193,19 @@ class FullSearch(models.Model):                  )              ) +        if self.PROPERTY_SEARCH_VECTORS: +            for attr in self.PROPERTY_SEARCH_VECTORS: +                data = getattr(self, attr) +                if callable(data): +                    data = data() +                if not data: +                    continue +                data = unicode(data) +                with connection.cursor() as cursor: +                    cursor.execute("SELECT to_tsvector(%s)", [data]) +                    row = cursor.fetchone() +                    search_vectors.append(row[0]) +          if hasattr(self, 'data') and self.data:              content_type = ContentType.objects.get_for_model(self)              for json_field in JsonDataField.objects.filter( | 
