本文整理汇总了Python中wagtail.images.get_image_model方法的典型用法代码示例。如果您正苦于以下问题:Python images.get_image_model方法的具体用法?Python images.get_image_model怎么用?Python images.get_image_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.images
的用法示例。
在下文中一共展示了images.get_image_model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_logo_image
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_logo_image(self):
homepage = HomePage.objects.get()
self.assertIsNone(homepage.logo_image)
with self.settings(CONFERENCE_ID=self.conference.id):
# Test that default logo image appears.
response = self.client.get(homepage.url)
self.assertContains(response, "/logo.png")
# Replace default logo with a new image.
test_logo_name = Faker().uuid4()
image_file = ImageFile(
open("conf_site/cms/tests/test-logo.png", "rb"), test_logo_name
)
ImageModel = get_image_model()
image = ImageModel(file=image_file)
# The image must be saved before it is attached
# to the homepage.
image.save()
homepage.logo_image = image
homepage.save()
response = self.client.get(homepage.url)
self.assertNotContains(response, "/logo.288981a8dfa8.png")
self.assertContains(response, test_logo_name)
示例2: test_thumbnail
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_thumbnail(self):
# Add a new image with source file
image = get_image_model().objects.create(
title="Test image",
file=get_test_image_file(),
)
response = self.get_response(image.id)
content = json.loads(response.content.decode('UTF-8'))
self.assertIn('thumbnail', content)
self.assertEqual(content['thumbnail']['width'], 165)
self.assertEqual(content['thumbnail']['height'], 123)
self.assertTrue(content['thumbnail']['url'].startswith('/media/images/test'))
# Check that source_image_error didn't appear
self.assertNotIn('source_image_error', content['meta'])
示例3: create_entity
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def create_entity(self, name, attrs, state, contentstate):
Image = get_image_model()
try:
image = Image.objects.get(id=attrs['id'])
image_format = get_image_format(attrs['format'])
rendition = get_rendition_or_not_found(image, image_format.filter_spec)
src = rendition.url
except Image.DoesNotExist:
src = ''
return Entity('IMAGE', 'IMMUTABLE', {
'id': attrs['id'],
'src': src,
'alt': attrs.get('alt'),
'format': attrs['format']
})
示例4: url_generator
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def url_generator(request, image_id):
image = get_object_or_404(get_image_model(), id=image_id)
if not permission_policy.user_has_permission_for_instance(request.user, 'change', image):
return permission_denied(request)
form = URLGeneratorForm(initial={
'filter_method': 'original',
'width': image.width,
'height': image.height,
})
return TemplateResponse(request, "wagtailimages/images/url_generator.html", {
'image': image,
'form': form,
})
示例5: get_gallery_images
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def get_gallery_images(collection, page=None, tags=None):
# Tags must be a list of tag names like ["Hasthag", "Kawabonga", "Winter is coming"]
images = None
try:
images = get_image_model().objects.filter(collection__name=collection).prefetch_related("tags")
if page:
if page.order_images_by == 1:
images = images.order_by('title')
elif page.order_images_by == 2:
images = images.order_by('-created_at')
except Exception as e:
pass
if images and tags:
images = images.filter(tags__name__in=tags).prefetch_related("tags").distinct()
return images
示例6: test_basic
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_basic(self):
response = self.get_response()
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-type'], 'application/json')
# Will crash if the JSON is invalid
content = json.loads(response.content.decode('UTF-8'))
# Check that the meta section is there
self.assertIn('meta', content)
self.assertIsInstance(content['meta'], dict)
# Check that the total count is there and correct
self.assertIn('total_count', content['meta'])
self.assertIsInstance(content['meta']['total_count'], int)
self.assertEqual(content['meta']['total_count'], get_image_model().objects.count())
# Check that the items section is there
self.assertIn('items', content)
self.assertIsInstance(content['items'], list)
# Check that each image has a meta section with type, detail_url and tags attributes
for image in content['items']:
self.assertIn('meta', image)
self.assertIsInstance(image['meta'], dict)
self.assertEqual(set(image['meta'].keys()), {'type', 'detail_url', 'tags', 'download_url'})
# Type should always be wagtailimages.Image
self.assertEqual(image['meta']['type'], 'wagtailimages.Image')
# Check detail url
self.assertEqual(image['meta']['detail_url'], 'http://localhost/admin/api/main/images/%d/' % image['id'])
# FIELDS
示例7: test_compare_imagechooserblock
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_compare_imagechooserblock(self):
image_model = get_image_model()
test_image_1 = image_model.objects.create(
title="Test image 1",
file=get_test_image_file(),
)
test_image_2 = image_model.objects.create(
title="Test image 2",
file=get_test_image_file(),
)
field = StreamPage._meta.get_field('body')
comparison = self.comparison_class(
field,
StreamPage(body=StreamValue(field.stream_block, [
('image', test_image_1, '1'),
])),
StreamPage(body=StreamValue(field.stream_block, [
('image', test_image_2, '1'),
])),
)
result = comparison.htmldiff()
self.assertIn('<div class="preview-image deletion">', result)
self.assertIn('alt="Test image 1"', result)
self.assertIn('<div class="preview-image addition">', result)
self.assertIn('alt="Test image 2"', result)
self.assertIsInstance(result, SafeString)
self.assertTrue(comparison.has_changed())
示例8: setUpTestData
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def setUpTestData(cls):
image_model = get_image_model()
cls.test_image_1 = image_model.objects.create(
title="Test image 1",
file=get_test_image_file(),
)
cls.test_image_2 = image_model.objects.create(
title="Test image 2",
file=get_test_image_file(),
)
示例9: test_basic
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_basic(self):
response = self.get_response()
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-type'], 'application/json')
# Will crash if the JSON is invalid
content = json.loads(response.content.decode('UTF-8'))
# Check that the meta section is there
self.assertIn('meta', content)
self.assertIsInstance(content['meta'], dict)
# Check that the total count is there and correct
self.assertIn('total_count', content['meta'])
self.assertIsInstance(content['meta']['total_count'], int)
self.assertEqual(content['meta']['total_count'], get_image_model().objects.count())
# Check that the items section is there
self.assertIn('items', content)
self.assertIsInstance(content['items'], list)
# Check that each image has a meta section with type and detail_url attributes
for image in content['items']:
self.assertIn('meta', image)
self.assertIsInstance(image['meta'], dict)
self.assertEqual(set(image['meta'].keys()), {'type', 'detail_url', 'tags', 'download_url'})
# Type should always be wagtailimages.Image
self.assertEqual(image['meta']['type'], 'wagtailimages.Image')
# Check detail url
self.assertEqual(image['meta']['detail_url'], 'http://localhost/api/main/images/%d/' % image['id'])
# FIELDS
示例10: test_limit_total_count
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_limit_total_count(self):
response = self.get_response(limit=2)
content = json.loads(response.content.decode('UTF-8'))
# The total count must not be affected by "limit"
self.assertEqual(content['meta']['total_count'], get_image_model().objects.count())
示例11: test_limit_max_none_gives_no_errors
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_limit_max_none_gives_no_errors(self):
response = self.get_response(limit=1000000)
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(len(content['items']), get_image_model().objects.count())
示例12: test_offset_total_count
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_offset_total_count(self):
response = self.get_response(offset=10)
content = json.loads(response.content.decode('UTF-8'))
# The total count must not be affected by "offset"
self.assertEqual(content['meta']['total_count'], get_image_model().objects.count())
示例13: test_tags
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_tags(self):
image = get_image_model().objects.get(id=5)
image.tags.add('hello')
image.tags.add('world')
response = self.get_response(5)
content = json.loads(response.content.decode('UTF-8'))
self.assertIn('tags', content['meta'])
self.assertEqual(content['meta']['tags'], ['hello', 'world'])
# FIELDS
示例14: test_resave_image_purges
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def test_resave_image_purges(self, purge):
get_image_model().objects.get(id=5).save()
purge.assert_any_call('http://api.example.com/api/main/images/5/')
示例15: register_signal_handlers
# 需要导入模块: from wagtail import images [as 别名]
# 或者: from wagtail.images import get_image_model [as 别名]
def register_signal_handlers():
Image = get_image_model()
Document = get_document_model()
for model in get_page_models():
page_published.connect(purge_page_from_cache, sender=model)
page_unpublished.connect(purge_page_from_cache, sender=model)
post_save.connect(purge_image_from_cache, sender=Image)
post_delete.connect(purge_image_from_cache, sender=Image)
post_save.connect(purge_document_from_cache, sender=Document)
post_delete.connect(purge_document_from_cache, sender=Document)