当前位置: 首页>>代码示例>>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;未经允许,请勿转载。