當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。