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


Python models.Image方法代码示例

本文整理汇总了Python中wagtail.images.models.Image方法的典型用法代码示例。如果您正苦于以下问题:Python models.Image方法的具体用法?Python models.Image怎么用?Python models.Image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wagtail.images.models的用法示例。


在下文中一共展示了models.Image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_run_test

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.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 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:test_image_operations.py

示例2: make_norun_test

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.models import Image [as 别名]
def make_norun_test(cls, filter_spec, image_kwargs):
        def test_norun(self):
            image = Image(**image_kwargs)

            # Make operation
            operation = self.operation_class(*filter_spec.split('-'))

            # Make operation recorder
            operation_recorder = WillowOperationRecorder((image.width, image.height))

            # Attempt (and hopefully fail) to run
            with self.assertRaises(ValueError):
                operation.run(operation_recorder, image, {})

        test_norun.__name__ = str('test_norun_%s' % filter_spec)
        return test_norun 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_image_operations.py

示例3: setUp

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.models import Image [as 别名]
def setUp(self):
        super().setUp()
        self.policy = BlanketPermissionPolicy(Image)

        self.active_users = [
            self.superuser,
            self.image_adder,
            self.oneoff_image_adder,
            self.image_changer,
            self.oneoff_image_changer,
            self.oneoff_image_deleter,
            self.useless_user,
        ]
        self.all_users = self.active_users + [
            self.inactive_superuser,
            self.inactive_image_adder,
            self.inactive_image_changer,
            self.anonymous_user,
        ] 
开发者ID:wagtail,项目名称:wagtail,代码行数:21,代码来源:test_permission_policies.py

示例4: process_content_image

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.models import Image [as 别名]
def process_content_image(self, content):
        self.stdout.write('\tGenerate and replace entry content images....')
        if content:
            root = lxml.html.fromstring(content)
            for img_node in root.iter('img'):
                parent_node = img_node.getparent()
                if 'wp-content' in img_node.attrib['src'] or 'files' in img_node.attrib['src']:
                    image = self._import_image(img_node.attrib['src'])
                    if image:
                        title = img_node.attrib.get('title') or img_node.attrib.get('alt')
                        new_image = WagtailImage(file=File(file=image), title=title)
                        new_image.save()
                        if parent_node.tag == 'a':
                            parent_node.addnext(ET.XML(self._image_to_embed(new_image)))
                            parent_node.drop_tree()
                        else:
                            parent_node.append(ET.XML(self._image_to_embed(new_image)))
                            img_node.drop_tag()
            content = ET.tostring(root)
        return content 
开发者ID:APSL,项目名称:wordpress-to-puput,代码行数:22,代码来源:wp2puput.py

示例5: setUp

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.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() 
开发者ID:neon-jungle,项目名称:wagtail-metadata,代码行数:21,代码来源:test_templates.py

示例6: ImageQueryMixin

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.models import Image [as 别名]
def ImageQueryMixin():
    class Mixin:
        images = graphene.List(Image)
        image = graphene.Field(Image,
                               id=graphene.Int(required=True))

        def resolve_images(self, info: ResolveInfo):
            return with_collection_permissions(
                info.context,
                gql_optimizer.query(
                    wagtailImage.objects.all(),
                    info
                )
            )

        def resolve_image(self, info: ResolveInfo, id: int):
            image = with_collection_permissions(
                info.context,
                gql_optimizer.query(
                    wagtailImage.objects.filter(id=id),
                    info
                )
            ).first()
            return image
    return Mixin 
开发者ID:tr11,项目名称:wagtail-graphql,代码行数:27,代码来源:images.py

示例7: handle

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.models import Image [as 别名]
def handle(self, *args, **options):
        # Get the only instance of Magazine Index Page
        magazine_index_page = MagazineIndexPage.objects.get()

        with open(options["file"]) as import_file:
            issues = csv.DictReader(import_file)

            for issue in issues:
                response = requests.get(issue["cover_image_url"])
                image_file = BytesIO(response.content)

                image = Image(
                    title=issue["title"] + " cover image",
                    file=ImageFile(image_file, name=issue["cover_image_file_name"]),
                )

                image.save()

                import_issue = MagazineIssue(
                    title=issue["title"],
                    publication_date=issue["publication_date"],
                    first_published_at=issue["publication_date"],
                    issue_number=issue["issue_number"],
                    cover_image=image,
                )

                # Add issue to site page hiererchy
                magazine_index_page.add_child(instance=import_issue)
                magazine_index_page.save()

        self.stdout.write("All done!") 
开发者ID:WesternFriend,项目名称:WF-website,代码行数:33,代码来源:import_issues.py

示例8: default

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.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().default(obj) 
开发者ID:neon-jungle,项目名称:wagtail-schema.org,代码行数:8,代码来源:encoder.py

示例9: set_featured_media

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.models import Image [as 别名]
def set_featured_media(self, page: BlogPage, post):
        featured_media_id: int = post.get("featured_media")
        if not featured_media_id:
            return
        featured_medias: list = post["_embedded"].get("wp:featuredmedia")
        if featured_medias is None:
            return
        for feature_media in featured_medias:
            if feature_media.get("id") == featured_media_id:
                source_url = feature_media["source_url"]
                try:  # Wordpress 5.3 API nests title in "rendered"
                    title = feature_media["title"]["rendered"]
                except TypeError:  # Fallback for older (or newer?) wordpress
                    title = feature_media["title"]
                details = feature_media["media_details"]
                resp = requests.get(source_url, stream=True)
                if resp.status_code != requests.codes.ok:
                    print("Unable to import " + source_url)
                    continue
                fp = BytesIO()
                fp.write(resp.content)
                image = Image(
                    title=title, width=details["width"], height=details["height"]
                )
                image.file.save(details["file"], File(fp))
                image.save()
                page.header_image = image 
开发者ID:thelabnyc,项目名称:wagtail_blog,代码行数:29,代码来源:wordpress_import.py

示例10: create_images_from_urls_in_content

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.models import Image [as 别名]
def create_images_from_urls_in_content(self, body):
        """create Image objects and transfer image files to media root"""
        from bs4 import BeautifulSoup

        soup = BeautifulSoup(body, "html5lib")
        for img in soup.findAll("img"):
            if "width" in img:
                width = img["width"]
            if "height" in img:
                height = img["height"]
            else:
                width = 100
                height = 100
            _, file_name = os.path.split(img["src"])
            if not img["src"]:
                continue  # Blank image
            if img["src"].startswith("data:"):
                continue  # Embedded image
            resp = requests.get(self.prepare_url(img["src"]), stream=True)
            if resp.status_code != requests.codes.ok:
                print("Unable to import " + img["src"])
                continue
            fp = BytesIO()
            fp.write(resp.content)
            image = Image(title=file_name, width=width, height=height)
            image.file.save(file_name, File(fp))
            image.save()
            if img.has_attr("srcset"):
                img["srcset"] = ""
            try:
                new_url = image.get_rendition("original").url
                img["src"] = new_url
            except OSError:
                # Avoid https://github.com/wagtail/wagtail/issues/1326 by not importing it
                logger.warning(f"image {image} is unable to be imported")
                image.delete()
        soup.body.hidden = True
        return soup.body 
开发者ID:thelabnyc,项目名称:wagtail_blog,代码行数:40,代码来源:wordpress_import.py

示例11: get_gallery_images

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.models import Image [as 别名]
def get_gallery_images(collection, page=None, tags=None):
    images = None
    try:
        images = Image.objects.filter(collection__name=collection)
        if page:
            if page.order_images_by == 0:
                images = images.order_by('title')
            elif page.order_images_by == 1:
                images = images.order_by('-created_at')
    except Exception as e:
        logging.exception(e)
    if images and tags:
        images = images.filter(tags__name__in=tags).distinct()
    return images 
开发者ID:chrisdev,项目名称:wagtail-cookiecutter-foundation,代码行数:16,代码来源:models.py

示例12: setUp

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.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(),
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:8,代码来源:tests.py

示例13: test_fields

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.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',
        ]) 
开发者ID:wagtail,项目名称:wagtail,代码行数:15,代码来源:tests.py

示例14: test_fill_filter

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.models import Image [as 别名]
def test_fill_filter(self):
        image = Image.objects.create(
            title="Test image",
            file=get_test_image_file(filename='test_rf2.png'),
        )
        rendition = image.get_rendition('fill-100x100')

        self.assertEqual(rendition.file.name, 'images/test_rf2.2e16d0ba.fill-100x100.png') 
开发者ID:wagtail,项目名称:wagtail,代码行数:10,代码来源:tests.py

示例15: test_fill_filter_with_focal_point

# 需要导入模块: from wagtail.images import models [as 别名]
# 或者: from wagtail.images.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') 
开发者ID:wagtail,项目名称:wagtail,代码行数:13,代码来源:tests.py


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