diff options
Diffstat (limited to 'ishtar_common/models.py')
| -rw-r--r-- | ishtar_common/models.py | 49 | 
1 files changed, 49 insertions, 0 deletions
| diff --git a/ishtar_common/models.py b/ishtar_common/models.py index f39cdabe8..dc7c219ac 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1755,6 +1755,16 @@ class QRCodeItem(models.Model, ImageContainerModel):  class DocumentItem(object): +    def public_representation(self): +        images = [] +        if getattr(self, "main_image", None): +            images.append(self.main_image.public_representation()) +        images += [ +            image.public_representation() +            for image in self.images_without_main_image().all() +        ] +        return {"images": images} +      @property      def images(self):          if not hasattr(self, 'documents'): @@ -2058,6 +2068,9 @@ class BaseHistorizedItem(StatisticItem, TemplateItem, FullSearch, Imported,      def merge(self, item, keep_old=False):          merge_model_objects(self, item, keep_old=keep_old) +    def public_representation(self): +        return {} +      def duplicate(self, user=None, data=None):          model = self.__class__          new = model.objects.get(pk=self.pk) @@ -4720,6 +4733,12 @@ class Author(FullSearch):                 list(self.findsource_related.all()) + \                 list(self.contextrecordsource_related.all()) +    def public_representation(self): +        return { +            "type": str(self.author_type), +            "person": str(self.person) +        } +  post_save.connect(cached_label_changed, sender=Author) @@ -5028,6 +5047,36 @@ class Document(BaseHistorizedItem, OwnPerms, ImageModel, ValueGetter, MainItem):                                     self.index)      """ +    def public_representation(self): +        site = Site.objects.get_current() +        if settings.ISHTAR_SECURE: +            scheme = "https" +        else: +            scheme = "http" +        base_url = scheme + "://" + site.domain + "/" +        image = None +        if self.image: +            image = self.image.url +            if not image.startswith("http"): +                if not image.startswith("/"): +                    image = "/" + image +                image = base_url + image +        thumbnail = None +        if self.thumbnail: +            thumbnail = self.thumbnail.url +            if not thumbnail.startswith("http"): +                if not thumbnail.startswith("/"): +                    thumbnail = "/" + thumbnail +                thumbnail = base_url + thumbnail +        return { +            "title": self.title, +            "reference": self.reference, +            "type": self.source_type, +            "authors": [a.public_representation() for a in self.authors.all()], +            "image": image, +            "thumbnail": thumbnail, +        } +      @property      def image_path(self):          if not self.image: | 
