當前位置: 首頁>>代碼示例>>Python>>正文


Python files.get_thumbnailer方法代碼示例

本文整理匯總了Python中easy_thumbnails.files.get_thumbnailer方法的典型用法代碼示例。如果您正苦於以下問題:Python files.get_thumbnailer方法的具體用法?Python files.get_thumbnailer怎麽用?Python files.get_thumbnailer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在easy_thumbnails.files的用法示例。


在下文中一共展示了files.get_thumbnailer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: thumbnailer

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def thumbnailer(obj, relative_name=None):
    """
    Creates a thumbnailer from an object (usually a ``FileField``).

    Example usage::

        {% with photo=person.photo|thumbnailer %}
        {% if photo %}
            <a href="{{ photo.large.url }}">
                {{ photo.square.tag }}
            </a>
        {% else %}
            <img src="{% static 'template/fallback.png' %}" alt="" />
        {% endif %}
        {% endwith %}

    If you know what you're doing, you can also pass the relative name::

        {% with photo=storage|thumbnailer:'some/file.jpg' %}...
    """
    return get_thumbnailer(obj, relative_name=relative_name) 
開發者ID:amaozhao,項目名稱:gougo,代碼行數:23,代碼來源:thumbnail.py

示例2: thumbnailer_passive

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def thumbnailer_passive(obj):
    """
    Creates a thumbnailer from an object (usually a ``FileFile``) that won't
    generate new thumbnails.

    This is useful if you are using another process to generate the thumbnails
    rather than having them generated on the fly if they are missing.

    Example usage::

        {% with avatar=person.avatar|thumbnailer_passive %}
            {% with avatar_thumb=avatar.small %}
                {% if avatar_thumb %}
                    <img src="{{ avatar_thumb.url }}" alt="" />
                {% else %}
                    <img src="{% static 'img/default-avatar-small.png' %}"
                        alt="" />
                {% endif %}
            {% endwith %}
        {% endwith %}
    """
    thumbnailer = get_thumbnailer(obj)
    thumbnailer.generate = False
    return thumbnailer 
開發者ID:amaozhao,項目名稱:gougo,代碼行數:26,代碼來源:thumbnail.py

示例3: thumbnail_url

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def thumbnail_url(source, alias):
    """
    Return the thumbnail url for a source file using an aliased set of
    thumbnail options.

    If no matching alias is found, returns an empty string.

    Example usage::

        <img src="{{ person.photo|thumbnail_url:'small' }}" alt="">
    """
    try:
        thumb = get_thumbnailer(source)[alias]
    except Exception:
        return ''
    return thumb.url 
開發者ID:amaozhao,項目名稱:gougo,代碼行數:18,代碼來源:thumbnail.py

示例4: delete_exercise_image_on_update

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def delete_exercise_image_on_update(sender, instance, **kwargs):
    '''
    Delete the corresponding image from the filesystem when the an ExerciseImage
    object was changed
    '''
    if not instance.pk:
        return False

    try:
        old_file = ExerciseImage.objects.get(pk=instance.pk).image
    except ExerciseImage.DoesNotExist:
        return False

    new_file = instance.image
    if not old_file == new_file:
        thumbnailer = get_thumbnailer(instance.image)
        thumbnailer.delete_thumbnails()
        instance.image.delete(save=False)


# Generate thumbnails when uploading a new image 
開發者ID:andela,項目名稱:wger-lycan-clan,代碼行數:23,代碼來源:signals.py

示例5: thumbnails

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def thumbnails(self, request, pk):
        '''
        Return a list of the image's thumbnails
        '''
        try:
            image = ExerciseImage.objects.get(pk=pk)
        except ExerciseImage.DoesNotExist:
            return Response([])

        thumbnails = {}
        for alias in aliases.all():
            t = get_thumbnailer(image.image)
            thumbnails[alias] = {
                'url': t.get_thumbnail(aliases.get(alias)).url,
                'settings': aliases.get(alias)
            }
        thumbnails['original'] = image.image.url
        return Response(thumbnails) 
開發者ID:andela,項目名稱:wger-lycan-clan,代碼行數:20,代碼來源:views.py

示例6: test_get_thumbnail_lazy

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def test_get_thumbnail_lazy(self):
        self.create_thumbnail_options()

        base_image = self.create_filer_image_object()
        context = {
            'image': base_image
        }
        request = self.get_request(page=None, lang='en', path='/')
        template = (
            '{% load filer_celery %}\n'
            '{% generate_thumbnail image size="20x20" '
            'crop=True subject_location=image.subject_location as image_big %}\n'
            '{% generate_thumbnail image size="100x20" '
            'crop=False subject_location=image.subject_location %}\n'
            '{% generate_thumbnail image alias="1" '
            'subject_location=image.subject_location%}\n'
            '-{{ image_big.url }}-'
        )
        template_obj = engines['django'].from_string(template)
        output_first_pass = template_obj.render(context, request)
        output_second_pass = template_obj.render(context, request)
        opts = (
            {'size': (20, 20), 'crop': True},
            {'size': (100, 20), 'crop': False},
        )
        self.assertFalse(output_first_pass == output_second_pass)
        for opt in opts:
            existing = get_thumbnailer(base_image).get_existing_thumbnail(opt)
            self.assertTrue(existing)
            self.assertTrue(os.path.exists(existing.path))
            self.assertTrue(output_second_pass.find(existing.url) > -1)

            opt['quality'] = 10
            existing = get_thumbnailer(base_image).get_existing_thumbnail(opt)
            self.assertTrue(existing)
            self.assertTrue(os.path.exists(existing.path))
            self.assertTrue(output_first_pass.find(existing.url) > -1) 
開發者ID:nephila,項目名稱:django-filer-celery,代碼行數:39,代碼來源:test_templatetags.py

示例7: test_generate_thumbnails

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def test_generate_thumbnails(self):
        base_image = self.create_filer_image_object()
        self.create_thumbnail_options()

        model = '{}.{}'.format(base_image._meta.app_label, base_image._meta.model_name)
        generate_thumbnails(model, base_image.pk, 'file')
        for alias in aliases.all():
            existing = get_thumbnailer(base_image)[alias]
            self.assertTrue(existing)
            self.assertTrue(os.path.exists(existing.path)) 
開發者ID:nephila,項目名稱:django-filer-celery,代碼行數:12,代碼來源:test_tasks.py

示例8: test_generate_thumbnail

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def test_generate_thumbnail(self):
        base_image = self.create_filer_image_object()
        for opt in self.options_list:
            model = '{}.{}'.format(base_image._meta.app_label, base_image._meta.model_name)
            generate_thumbnail(model, base_image.pk, 'file', opt)
            existing = get_thumbnailer(base_image).get_existing_thumbnail(opt)
            self.assertTrue(existing)
            self.assertTrue(os.path.exists(existing.path)) 
開發者ID:nephila,項目名稱:django-filer-celery,代碼行數:10,代碼來源:test_tasks.py

示例9: generate_thumbnail

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def generate_thumbnail(model_name, pk, field, opts):
    model = apps.get_model(model_name)
    instance = model.objects.get(pk=pk)
    fieldfile = getattr(instance, field)
    thumbnail = get_thumbnailer(fieldfile).get_thumbnail(opts)
    return thumbnail.url 
開發者ID:nephila,項目名稱:django-filer-celery,代碼行數:8,代碼來源:tasks.py

示例10: generate_thumbnail_from_file

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def generate_thumbnail_from_file(fieldfile, opts):
    try:
        thumbnail = get_thumbnailer(fieldfile).get_thumbnail(opts)
        return thumbnail
    except Exception as e:  # pragma: no cover
        if filer_settings.FILER_ENABLE_LOGGING:
            logger.error('Error while generating thumbnail: %s', e)
        if filer_settings.FILER_DEBUG:
            raise 
開發者ID:nephila,項目名稱:django-filer-celery,代碼行數:11,代碼來源:tasks.py

示例11: image_admin_tag

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def image_admin_tag(self):
      return '<img src="/media/%s" height="80" />' % get_thumbnailer(self.image)['admin_thumb'] 
開發者ID:timwaters,項目名稱:leodis-collections,代碼行數:4,代碼來源:models.py

示例12: get_geojson

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def get_geojson(self):
      #if not self.location == None:
      geom = self.location
      feature_type = 'Point'
      
      properties = {
          'id': self.id,
          'title': self.title,
          'icon' : get_thumbnailer(self.image)['popup'].url
      }
      return {
          'type': 'Feature',
          'properties': properties,
          'geometry': geom
      } 
開發者ID:timwaters,項目名稱:leodis-collections,代碼行數:17,代碼來源:models.py

示例13: preview

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def preview(self, obj, request=None):
        """
        Generate the HTML to display for the image.

        :param obj: An object with a thumbnail_field defined.
        :return: HTML for image display.
        """
        source = self.get_thumbnail_source(obj)
        if source:
            try:
                from easy_thumbnails.files import get_thumbnailer
            except ImportError:
                logger.warning(
                    _(
                        '`easy_thumbnails` is not installed and required for '
                        'icekit.utils.admin.mixins.ThumbnailAdminMixin'
                    )
                )
                return ''
            try:
                thumbnailer = get_thumbnailer(source)
                thumbnail = thumbnailer.get_thumbnail(self.thumbnail_options)
                return '<img class="thumbnail" src="{0}" />'.format(
                    thumbnail.url)
            except Exception as ex:
                logger.warning(
                    _(u'`easy_thumbnails` failed to generate a thumbnail image'
                      u' for {0}'.format(source)))
                if self.thumbnail_show_exceptions:
                    return 'Thumbnail exception: {0}'.format(ex)
        return '' 
開發者ID:ic-labs,項目名稱:django-icekit,代碼行數:33,代碼來源:mixins.py

示例14: get_og_image_url

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def get_og_image_url(self):
        """
        :return: URL of the image to use in OG shares
        """
        li = self.get_list_image()
        if li:
            from easy_thumbnails.files import get_thumbnailer
            thumb_url = get_thumbnailer(li)['og_image'].url
            # TODO: looks like this may fail if SITE_DOMAIN = "acmi.lvh.me"
            return urljoin(settings.SITE_DOMAIN, thumb_url) 
開發者ID:ic-labs,項目名稱:django-icekit,代碼行數:12,代碼來源:mixins.py

示例15: prepare_get_list_image_url

# 需要導入模塊: from easy_thumbnails import files [as 別名]
# 或者: from easy_thumbnails.files import get_thumbnailer [as 別名]
def prepare_get_list_image_url(self, obj):
        list_image = getattr(obj, "get_list_image", lambda x: None)()
        if list_image:
            # resize according to the `list_image` alias
            try:
                return get_thumbnailer(list_image)['list_image'].url
            except InvalidImageFormatError:
                pass
        return "" 
開發者ID:ic-labs,項目名稱:django-icekit,代碼行數:11,代碼來源:search_indexes.py


注:本文中的easy_thumbnails.files.get_thumbnailer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。