本文整理匯總了Python中wagtail.wagtailimages.models.get_image_model方法的典型用法代碼示例。如果您正苦於以下問題:Python models.get_image_model方法的具體用法?Python models.get_image_model怎麽用?Python models.get_image_model使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.wagtailimages.models
的用法示例。
在下文中一共展示了models.get_image_model方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Image
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import get_image_model [as 別名]
def Image(props):
"""
Inspired by:
- https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailimages/rich_text.py
- https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailimages/shortcuts.py
- https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailimages/formats.py
"""
image_model = get_image_model()
alignment = props.get('alignment', 'left')
alt_text = props.get('altText', '')
try:
image = image_model.objects.get(id=props['id'])
except image_model.DoesNotExist:
return DOM.create_element('img', {'alt': alt_text})
image_format = get_image_format(alignment)
rendition = get_rendition_or_not_found(image, image_format.filter_spec)
return DOM.create_element('img', dict(rendition.attrs_dict, **{
'class': image_format.classnames,
'src': rendition.url,
'alt': alt_text,
}))
示例2: test_custom_get_image_model
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import get_image_model [as 別名]
def test_custom_get_image_model(self):
"""Test get_image_model with a custom image model"""
self.assertIs(get_image_model(), CustomImage)
示例3: test_standard_get_image_model
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import get_image_model [as 別名]
def test_standard_get_image_model(self):
"""Test get_image_model with no WAGTAILIMAGES_IMAGE_MODEL"""
del settings.WAGTAILIMAGES_IMAGE_MODEL
from wagtail.wagtailimages.models import Image
self.assertIs(get_image_model(), Image)
示例4: test_unknown_get_image_model
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import get_image_model [as 別名]
def test_unknown_get_image_model(self):
"""Test get_image_model with an unknown model"""
with self.assertRaises(ImproperlyConfigured):
get_image_model()
示例5: test_invalid_get_image_model
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import get_image_model [as 別名]
def test_invalid_get_image_model(self):
"""Test get_image_model with an invalid model string"""
with self.assertRaises(ImproperlyConfigured):
get_image_model()
示例6: test_deprecated_get_image_model
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import get_image_model [as 別名]
def test_deprecated_get_image_model(self):
from wagtail.wagtailimages.models import get_image_model
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter('always')
self.assertIs(Image, get_image_model())
self.assertEqual(len(ws), 1)
self.assertIs(ws[0].category, RemovedInWagtail110Warning)