diff options
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 37 | 
1 files changed, 36 insertions, 1 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 205935f7b..7a10c3e9d 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -115,6 +115,18 @@ class ValueGetter(object):          'search_vector', 'id', 'multi_polygon', 'point_2d', 'point',          'history_m2m'] +    def _get_values_documents(self, prefix=""): +        values = {} +        if not hasattr(self, 'documents'): +            return values +        values[prefix + "documents"] = [ +            doc.get_values(prefix=prefix) for doc in self.documents.all() +        ] +        if hasattr(self, "main_image") and self.main_image and hasattr( +                self.main_image, "get_values"): +            values[prefix + "main_image"] = self.main_image.get_values() +        return values +      def get_values(self, prefix=''):          if not prefix:              prefix = self._prefix @@ -128,6 +140,7 @@ class ValueGetter(object):                  values.update(value.get_values(prefix + field_name + '_'))              else:                  values[prefix + field_name] = value +        values.update(self._get_values_documents(prefix=prefix))          for extra_field in self.GET_VALUES_EXTRA:              values[prefix + extra_field] = getattr(self, extra_field) or ''          for key in values.keys(): @@ -4368,7 +4381,7 @@ post_save.connect(post_save_cache, sender=LicenseType)  post_delete.connect(post_save_cache, sender=LicenseType) -class Document(BaseHistorizedItem, OwnPerms, ImageModel): +class Document(BaseHistorizedItem, OwnPerms, ImageModel, ValueGetter):      EXTERNAL_ID_KEY = 'document_external_id'      # order is important: put the image in the first match found      # other will be symbolic links @@ -4384,6 +4397,17 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel):      SLUG = 'document'      LINK_SPLIT = u"<||>" +    GET_VALUE_EXCLUDE_FIELDS = ValueGetter.GET_VALUE_EXCLUDE_FIELDS + [ +        "warehouses", "operations", "treatments", +        "files", "treatment_files", "id", +        "associated_links", "source_type_id", +        "history_creator_id", "containers", "sites", +        "main_image_warehouses", "main_image_operations", "main_image_treatments", +        "main_image_files", "main_image_treatment_files", "main_image_id", +        "main_image_associated_links", "main_image_source_type_id", +        "main_image_history_creator_id", "main_image_containers", "main_image_sites", +    ] +      TABLE_COLS = ['title', 'source_type', 'cache_related_label',                    'authors__cached_label',                    'associated_url'] @@ -4600,6 +4624,17 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel):      """      @property +    def image_path(self): +        if not self.image: +            return "" +        return self.image.path + +    def get_values(self, prefix=""): +        values = super(Document, self).get_values(prefix=prefix) +        values[prefix + "image_path"] = self.image_path +        return values + +    @property      def images_without_main_image(self):          return [] | 
