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


Python ObjectList.bind_to方法代码示例

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


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

示例1: get_edit_handler

# 需要导入模块: from wagtail.admin.edit_handlers import ObjectList [as 别名]
# 或者: from wagtail.admin.edit_handlers.ObjectList import bind_to [as 别名]
 def get_edit_handler(self):
     if hasattr(self.model, 'edit_handler'):
         edit_handler = self.model.edit_handler
     else:
         fields_to_exclude = self.model_admin.get_form_fields_exclude(request=self.request)
         panels = extract_panel_definitions_from_model_class(self.model, exclude=fields_to_exclude)
         edit_handler = ObjectList(panels)
     return edit_handler.bind_to(model=self.model)
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:10,代码来源:views.py

示例2: get_snippet_edit_handler

# 需要导入模块: from wagtail.admin.edit_handlers import ObjectList [as 别名]
# 或者: from wagtail.admin.edit_handlers.ObjectList import bind_to [as 别名]
def get_snippet_edit_handler(model):
    if model not in SNIPPET_EDIT_HANDLERS:
        if hasattr(model, 'edit_handler'):
            # use the edit handler specified on the page class
            edit_handler = model.edit_handler
        else:
            panels = extract_panel_definitions_from_model_class(model)
            edit_handler = ObjectList(panels)

        SNIPPET_EDIT_HANDLERS[model] = edit_handler.bind_to(model=model)

    return SNIPPET_EDIT_HANDLERS[model]
开发者ID:Proper-Job,项目名称:wagtail,代码行数:14,代码来源:snippets.py

示例3: TestObjectList

# 需要导入模块: from wagtail.admin.edit_handlers import ObjectList [as 别名]
# 或者: from wagtail.admin.edit_handlers.ObjectList import bind_to [as 别名]
class TestObjectList(TestCase):
    def setUp(self):
        self.request = RequestFactory().get('/')
        user = AnonymousUser()  # technically, Anonymous users cannot access the admin
        self.request.user = user
        # a custom ObjectList for EventPage
        self.event_page_object_list = ObjectList([
            FieldPanel('title', widget=forms.Textarea),
            FieldPanel('date_from'),
            FieldPanel('date_to'),
            InlinePanel('speakers', label="Speakers"),
        ], heading='Event details', classname="shiny").bind_to(
            model=EventPage, request=self.request)

    def test_get_form_class(self):
        EventPageForm = self.event_page_object_list.get_form_class()
        form = EventPageForm()

        # form must include the 'speakers' formset required by the speakers InlinePanel
        self.assertIn('speakers', form.formsets)

        # form must respect any overridden widgets
        self.assertEqual(type(form.fields['title'].widget), forms.Textarea)

    def test_render(self):
        EventPageForm = self.event_page_object_list.get_form_class()
        event = EventPage(title='Abergavenny sheepdog trials')
        form = EventPageForm(instance=event)

        object_list = self.event_page_object_list.bind_to(
            instance=event,
            form=form,
        )

        result = object_list.render()

        # result should contain ObjectList furniture
        self.assertIn('<ul class="objects">', result)

        # result should contain h2 headings (including labels) for children
        self.assertInHTML('<h2><label for="id_date_from">Start date</label></h2>', result)

        # result should include help text for children
        self.assertIn('<div class="object-help help"><span class="icon-help-inverse" aria-hidden="true"></span>Not required if event is on a single day</div>', result)

        # result should contain rendered content from descendants
        self.assertIn('Abergavenny sheepdog trials</textarea>', result)

        # this result should not include fields that are not covered by the panel definition
        self.assertNotIn('signup_link', result)
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:52,代码来源:test_edit_handlers.py

示例4: test_render

# 需要导入模块: from wagtail.admin.edit_handlers import ObjectList [as 别名]
# 或者: from wagtail.admin.edit_handlers.ObjectList import bind_to [as 别名]
    def test_render(self):
        """
        Check that the inline panel renders the panels set on the model
        when no 'panels' parameter is passed in the InlinePanel definition
        """
        speaker_object_list = ObjectList([
            InlinePanel('speakers', label="Speakers", classname="classname-for-speakers")
        ]).bind_to(model=EventPage, request=self.request)
        EventPageForm = speaker_object_list.get_form_class()

        # SpeakerInlinePanel should instruct the form class to include a 'speakers' formset
        self.assertEqual(['speakers'], list(EventPageForm.formsets.keys()))

        event_page = EventPage.objects.get(slug='christmas')

        form = EventPageForm(instance=event_page)
        panel = speaker_object_list.bind_to(instance=event_page, form=form)

        result = panel.render_as_field()

        self.assertIn('<li class="object classname-for-speakers">', result)
        self.assertIn('<label for="id_speakers-0-first_name">Name:</label>', result)
        self.assertIn('value="Father"', result)
        self.assertIn('<label for="id_speakers-0-last_name">Surname:</label>', result)
        self.assertIn('<label for="id_speakers-0-image">Image:</label>', result)
        self.assertIn('Choose an image', result)

        # rendered panel must also contain hidden fields for id, DELETE and ORDER
        self.assertTagInHTML(
            '<input id="id_speakers-0-id" name="speakers-0-id" type="hidden">',
            result, allow_extra_attrs=True
        )
        self.assertTagInHTML(
            '<input id="id_speakers-0-DELETE" name="speakers-0-DELETE" type="hidden">',
            result, allow_extra_attrs=True
        )
        self.assertTagInHTML(
            '<input id="id_speakers-0-ORDER" name="speakers-0-ORDER" type="hidden">',
            result, allow_extra_attrs=True
        )

        # rendered panel must contain maintenance form for the formset
        self.assertTagInHTML(
            '<input id="id_speakers-TOTAL_FORMS" name="speakers-TOTAL_FORMS" type="hidden">',
            result, allow_extra_attrs=True
        )

        # rendered panel must include the JS initializer
        self.assertIn('var panel = InlinePanel({', result)
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:51,代码来源:test_edit_handlers.py


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