本文整理汇总了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)
示例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
示例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
示例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
示例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)
示例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)
示例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))
示例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))
示例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
示例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
示例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']
示例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
}
示例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 ''
示例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)
示例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 ""