コード例 #1
0
 def resolve_thumbnail_url(self, info):
     asset = self.primary_image_webasset
     if asset:
         return generate_thumbnail_url(asset,
                                       width=300,
                                       height=None,
                                       operation="thumbnail")
     return ""
コード例 #2
0
ファイル: serializers.py プロジェクト: patriciodaxxi/hav
 def get_preview_url(self, media):
     if media.primary_file:
         webasset_images = filter(
             lambda x: x.mime_type.startswith("image"),
             media.primary_file.webasset_set.all(),
         )
         webasset_images = list(webasset_images)
         try:
             webasset = webasset_images[0]
         except IndexError:
             return None
         else:
             return generate_thumbnail_url(webasset)
コード例 #3
0
 def get_preview_url(self, path):
     rel_path = path.relative_to(self.get_root()).as_posix()
     return generate_thumbnail_url(rel_path)
コード例 #4
0
ファイル: views.py プロジェクト: patriciodaxxi/hav
 def get_preview_url(self, p):
     return generate_thumbnail_url(self.upload)
コード例 #5
0
ファイル: views.py プロジェクト: patriciodaxxi/hav
    def get(self, request, format=None):
        query_serializer = QuerySerializer(data=request.GET)
        query_serializer.is_valid()
        query = query_serializer.data.get('query')
        node = query_serializer.data.get('node')

        search_filters = ''
        if node:
            search_filters += f'parents = {node}'

        # build valid search options
        search_options = {
            'matches': True,
            'attributesToCrop': ['*'],
            'cropLength': 200
        }
        if search_filters:
            search_options.update({'filters': search_filters})

        index = get_index()
        response = index.search(query, search_options)
        hits = response.get('hits', [])

        # get all folder and media pks in one go
        media_pks = []
        node_pks = []
        for hit in hits:
            type = hit.get('type')
            pk = hit.get('pk')
            if type == 'media':
                media_pks.append(pk)
            elif type == 'folder':
                node_pks.append(pk)
            else:
                raise NotImplementedError(
                    f'Unknown type "{type}" returned from search query.')

        # and fetch in one query per type
        media_items = {
            media.pk: media
            for media in Media.objects.filter(pk__in=media_pks)
        }
        nodes = {
            node.pk: node
            for node in Node.objects.filter(pk__in=node_pks)
        }

        # decorate search results with thumbnails
        for hit in hits:
            type = hit.get('type')
            pk = hit.get('pk')
            if type == 'media':
                m = media_items[pk]
            elif type == 'folder':
                m = nodes[pk].representative_media

            asset = m.primary_image_webasset
            if asset:
                formatted = hit.pop('_formatted', {})
                hit.update({
                    'thumbnail':
                    generate_thumbnail_url(asset,
                                           width=300,
                                           height=None,
                                           operation="thumbnail")
                })
                hit.update(formatted)

        return Response(response)
コード例 #6
0
 def get_preview_url(self, mo):
     return generate_thumbnail_url(self._get_image_url(mo))
コード例 #7
0
ファイル: schema.py プロジェクト: mcallistersean/hav
 def resolve_thumbnail_url(self, info):
     asset = self.primary_image_webasset
     if asset:
         return generate_thumbnail_url(asset)
     return ""