本文整理匯總了Python中wagtail.wagtailimages.models.Image方法的典型用法代碼示例。如果您正苦於以下問題:Python models.Image方法的具體用法?Python models.Image怎麽用?Python models.Image使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.wagtailimages.models
的用法示例。
在下文中一共展示了models.Image方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: make_run_test
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def make_run_test(cls, filter_spec, image_kwargs, expected_output):
def test_run(self):
image = Image(**image_kwargs)
# Make operation
operation = self.operation_class(*filter_spec.split('-'))
# Make operation recorder
operation_recorder = WillowOperationRecorder((image.width, image.height))
# Run
operation.run(operation_recorder, image, {})
# Check
self.assertEqual(operation_recorder.ran_operations, expected_output)
test_run.__name__ = str('test_run_%s' % filter_spec)
return test_run
示例2: test_runs_operations
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def test_runs_operations(self):
run_mock = Mock()
def run(willow, image, env):
run_mock(willow, image, env)
self.operation_instance.run = run
fil = Filter(spec='operation1|operation2')
image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
fil.run(image, BytesIO())
self.assertEqual(run_mock.call_count, 2)
示例3: setUp
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def setUp(self):
self.site = Site.objects.first()
self.site.site_name = 'Example site'
self.site.save()
self.factory = RequestFactory()
self.request = self.factory.get('/test/')
self.request.site = self.site
self.image = Image.objects.create(
title='Test Image',
file=get_test_image_file(),
)
self.page = self.site.root_page.add_child(instance=TestPage(
title='Test Page',
search_image=self.image,
search_description='Some test content description',
))
self.test_model = TestModel.objects.create()
示例4: fetch_hut_images
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def fetch_hut_images():
for hpage in HutPage.objects.all():
if hpage.link_url:
try:
r = requests.get(hpage.link_url, timeout=settings.API_TIMEOUT)
except requests.exceptions.RequestException as e:
logger.exception(str(e))
else:
soup = BeautifulSoup(r.content, 'html5lib')
a_tag = soup.find_all("a", {"class": "fancybox-gallery"})
if a_tag:
img_tag = a_tag[0].find_all("img")
if img_tag:
img_url = 'http://www.doc.govt.nz/%s' % img_tag[0].get('src')
logger.debug("Hut %s using img %s from HTML body.", str(hpage.pk), img_url)
else:
page = metadata_parser.MetadataParser(url=hpage.link_url)
img_url = page.get_metadata_link('image')
logger.debug("Hut %s using img %s from HTML meta", str(hpage.pk), img_url)
if img_url:
try:
response = requests.get(img_url, timeout=settings.API_TIMEOUT)
except requests.exceptions.RequestException as e:
logger.exception(str(e))
image = Image(title=hpage.title, file=ImageFile(BytesIO(response.content), name=img_url.split('/')[-1]))
image.save()
hpage.meta_image = image
hpage.save()
else:
logger.debug("No img found for hut %s", str(hpage.pk))
示例5: default
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def default(self, obj):
if isinstance(obj, Image):
return image_ld(obj)
if isinstance(obj, ThingLD):
return obj.ld_nested_entity()
return super(JSONLDEncoder, self).default(obj)
示例6: test_feed_image
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def test_feed_image(self):
field = BasicPage._meta.get_field('feed_image')
self.assertModelPKField(field, Image, models.SET_NULL, True, True)
# properties
示例7: setUp
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def setUp(self):
# Create an image for running tests on
self.image = Image.objects.create(
title="Test image",
file=get_test_image_file(),
)
示例8: test_fields
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def test_fields(self):
form = get_image_form(Image)
self.assertEqual(list(form.base_fields.keys()), [
'title',
'file',
'collection',
'tags',
'focal_point_x',
'focal_point_y',
'focal_point_width',
'focal_point_height',
])
示例9: test_normal_filter
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def test_normal_filter(self):
image = Image.objects.create(
title="Test image",
file=get_test_image_file(filename='test_rf1.png'),
)
rendition = image.get_rendition('width-100')
self.assertEqual(rendition.file.name, 'images/test_rf1.width-100.png')
示例10: test_fill_filter_with_focal_point
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def test_fill_filter_with_focal_point(self):
image = Image.objects.create(
title="Test image",
file=get_test_image_file(filename='test_rf3.png'),
)
image.set_focal_point(Rect(100, 100, 200, 200))
image.save()
rendition = image.get_rendition('fill-100x100')
self.assertEqual(rendition.file.name, 'images/test_rf3.15ee4958.fill-100x100.png')
示例11: test_filter_with_pipe_gets_dotted
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def test_filter_with_pipe_gets_dotted(self):
image = Image.objects.create(
title="Test image",
file=get_test_image_file(filename='test_rf4.png'),
)
image.set_focal_point(Rect(100, 100, 200, 200))
image.save()
rendition = image.get_rendition('fill-200x200|height-150')
self.assertEqual(rendition.file.name, 'images/test_rf4.15ee4958.fill-200x200.height-150.png')
示例12: test_upload_path
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def test_upload_path(self):
image = CustomImageFilePath.objects.create(
title="Test image",
file=get_test_image_file(),
)
second_image = CustomImageFilePath.objects.create(
title="Test Image",
file=get_test_image_file(colour='black'),
)
# The files should be uploaded based on it's content, not just
# it's filename
self.assertFalse(image.file.url == second_image.file.url)
示例13: test_standard_get_image_model
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [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)
示例14: test_standard_get_image_model_string
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def test_standard_get_image_model_string(self):
"""Test get_image_model_STRING with no WAGTAILIMAGES_IMAGE_MODEL"""
del settings.WAGTAILIMAGES_IMAGE_MODEL
self.assertEqual(get_image_model_string(), 'wagtailimages.Image')
示例15: test_cache_key
# 需要導入模塊: from wagtail.wagtailimages import models [as 別名]
# 或者: from wagtail.wagtailimages.models import Image [as 別名]
def test_cache_key(self):
image = Image(width=1000, height=1000)
fil = Filter(spec='max-100x100')
cache_key = fil.get_cache_key(image)
self.assertEqual(cache_key, '')