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


Python fields.StreamField方法代码示例

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


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

示例1: test_lazy_load

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def test_lazy_load(self):
        """
        Getting a single item should lazily load the StreamField, only
        accessing the database once the StreamField is accessed
        """
        with self.assertNumQueries(1):
            # Get the instance. The StreamField should *not* load the image yet
            instance = StreamModel.objects.get(pk=self.with_image.pk)

        with self.assertNumQueries(0):
            # Access the body. The StreamField should still not get the image.
            body = instance.body

        with self.assertNumQueries(1):
            # Access the image item from the stream. The image is fetched now
            body[0].value

        with self.assertNumQueries(0):
            # Everything has been fetched now, no further database queries.
            self.assertEqual(body[0].value, self.image)
            self.assertEqual(body[1].value, 'foo') 
开发者ID:wagtail,项目名称:wagtail,代码行数:23,代码来源:test_streamfield.py

示例2: editor_css

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def editor_css():
    # Make 'heading' StreamField blocks look like h2 in RichTextBlocks in the
    # Wagtail Admin.
    return (
        '''
        <style>
            .fieldname-heading input {
                color: #666;
                font-family: Roboto Slab, Georgia, serif;
                font-size: 2.4em;
                font-weight: bold;
            }
        </style>
        '''
    ) 
开发者ID:freedomofpress,项目名称:securethenews,代码行数:17,代码来源:models.py

示例3: test_lazy_load_no_images

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def test_lazy_load_no_images(self):
        """
        Getting a single item whose StreamField never accesses the database
        should behave as expected.
        """
        with self.assertNumQueries(1):
            # Get the instance, nothing else
            instance = StreamModel.objects.get(pk=self.no_image.pk)

        with self.assertNumQueries(0):
            # Access the body. The StreamField has no images, so nothing should
            # happen
            body = instance.body
            self.assertEqual(body[0].value, 'foo') 
开发者ID:wagtail,项目名称:wagtail,代码行数:16,代码来源:test_streamfield.py

示例4: test_lazy_load_queryset

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def test_lazy_load_queryset(self):
        """
        Ensure that lazy loading StreamField works when gotten as part of a
        queryset list
        """
        with self.assertNumQueries(1):
            instances = StreamModel.objects.filter(
                pk__in=[self.with_image.pk, self.no_image.pk])
            instances_lookup = {instance.pk: instance for instance in instances}

        with self.assertNumQueries(1):
            instances_lookup[self.with_image.pk].body[0]

        with self.assertNumQueries(0):
            instances_lookup[self.no_image.pk].body[0] 
开发者ID:wagtail,项目名称:wagtail,代码行数:17,代码来源:test_streamfield.py

示例5: test_lazy_load_queryset_bulk

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def test_lazy_load_queryset_bulk(self):
        """
        Ensure that lazy loading StreamField works when gotten as part of a
        queryset list
        """
        file_obj = get_test_image_file()
        image_1 = Image.objects.create(title='Test image 1', file=file_obj)
        image_3 = Image.objects.create(title='Test image 3', file=file_obj)

        with_image = StreamModel.objects.create(body=json.dumps([
            {'type': 'image', 'value': image_1.pk},
            {'type': 'image', 'value': None},
            {'type': 'image', 'value': image_3.pk},
            {'type': 'text', 'value': 'foo'}]))

        with self.assertNumQueries(1):
            instance = StreamModel.objects.get(pk=with_image.pk)

        # Prefetch all image blocks
        with self.assertNumQueries(1):
            instance.body[0]

        # 1. Further image block access should not execute any db lookups
        # 2. The blank block '1' should be None.
        # 3. The values should be in the original order.
        with self.assertNumQueries(0):
            assert instance.body[0].value.title == 'Test image 1'
            assert instance.body[1].value is None
            assert instance.body[2].value.title == 'Test image 3' 
开发者ID:wagtail,项目名称:wagtail,代码行数:31,代码来源:test_streamfield.py

示例6: test_lazy_load_get_prep_value

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def test_lazy_load_get_prep_value(self):
        """
        Saving a lazy StreamField that hasn't had its data accessed should not
        cause extra database queries by loading and then re-saving block values.
        Instead the initial JSON stream data should be written back for any
        blocks that have not been accessed.
        """
        with self.assertNumQueries(1):
            instance = StreamModel.objects.get(pk=self.with_image.pk)

        # Expect a single UPDATE to update the model, without any additional
        # SELECT related to the image block that has not been accessed.
        with self.assertNumQueries(1):
            instance.save() 
开发者ID:wagtail,项目名称:wagtail,代码行数:16,代码来源:test_streamfield.py

示例7: test_can_read_non_json_content

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def test_can_read_non_json_content(self):
        """StreamField columns should handle non-JSON database content gracefully"""
        self.assertIsInstance(self.nonjson_body.body, StreamValue)
        # the main list-like content of the StreamValue should be blank
        self.assertFalse(self.nonjson_body.body)
        # the unparsed text content should be available in raw_text
        self.assertEqual(self.nonjson_body.body.raw_text, "<h1>hello world</h1>") 
开发者ID:wagtail,项目名称:wagtail,代码行数:9,代码来源:test_streamfield.py

示例8: test_non_blank_field_is_required

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def test_non_blank_field_is_required(self):
        field = StreamField([('paragraph', blocks.CharBlock())], blank=False)
        self.assertTrue(field.stream_block.required) 
开发者ID:wagtail,项目名称:wagtail,代码行数:5,代码来源:test_streamfield.py

示例9: test_blank_field_is_not_required

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def test_blank_field_is_not_required(self):
        field = StreamField([('paragraph', blocks.CharBlock())], blank=True)
        self.assertFalse(field.stream_block.required) 
开发者ID:wagtail,项目名称:wagtail,代码行数:5,代码来源:test_streamfield.py

示例10: _add_streamfields

# 需要导入模块: from wagtail.core import fields [as 别名]
# 或者: from wagtail.core.fields import StreamField [as 别名]
def _add_streamfields(cls: wagtailPage, node: str, dict_params: dict, app: str, prefix: str) -> None:
    from .types.streamfield import (
        block_handler,
        stream_field_handler,
    )

    for field in cls._meta.fields:
        if isinstance(field, StreamField):
            field_name = field.name
            stream_field_name = f"{node}{string.capwords(field_name, sep='_').replace('_', '')}"
            blocks = field.stream_block.child_blocks

            handlers = dict(
                (name, block_handler(block, app, prefix))
                for name, block in blocks.items()
            )

            f, resolve = stream_field_handler(
                stream_field_name,
                field_name,
                handlers
            )

            dict_params.update({
                field.name: f,
                "resolve_" + field.name: resolve
            }) 
开发者ID:tr11,项目名称:wagtail-graphql,代码行数:29,代码来源:actions.py


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