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 ""
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)
def get_preview_url(self, path): rel_path = path.relative_to(self.get_root()).as_posix() return generate_thumbnail_url(rel_path)
def get_preview_url(self, p): return generate_thumbnail_url(self.upload)
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)
def get_preview_url(self, mo): return generate_thumbnail_url(self._get_image_url(mo))
def resolve_thumbnail_url(self, info): asset = self.primary_image_webasset if asset: return generate_thumbnail_url(asset) return ""