当前位置: 首页>>代码示例>>Python>>正文


Python images.get_image_model方法代码示例

本文整理汇总了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) 
开发者ID:pydata,项目名称:conf_site,代码行数:24,代码来源:test_homepage_context.py

示例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']) 
开发者ID:wagtail,项目名称:wagtail,代码行数:19,代码来源:test_images.py

示例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']
        }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:contentstate.py

示例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,
    }) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:images.py

示例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 
开发者ID:Temeez,项目名称:wagtail-simple-gallery,代码行数:17,代码来源:models.py

示例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 
开发者ID:wagtail,项目名称:wagtail,代码行数:37,代码来源:test_images.py

示例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()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:33,代码来源:test_compare.py

示例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(),
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:12,代码来源:test_compare.py

示例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 
开发者ID:wagtail,项目名称:wagtail,代码行数:37,代码来源:test_images.py

示例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()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:8,代码来源:test_images.py

示例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()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:8,代码来源:test_images.py

示例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()) 
开发者ID:wagtail,项目名称:wagtail,代码行数:8,代码来源:test_images.py

示例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 
开发者ID:wagtail,项目名称:wagtail,代码行数:14,代码来源:test_images.py

示例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/') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_images.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:14,代码来源:signal_handlers.py


注:本文中的wagtail.images.get_image_model方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。