本文整理汇总了Python中wagtail.admin.edit_handlers.ObjectList类的典型用法代码示例。如果您正苦于以下问题:Python ObjectList类的具体用法?Python ObjectList怎么用?Python ObjectList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_get_form_without_model
def test_get_form_without_model(self):
edit_handler = ObjectList()
with self.assertRaisesMessage(
AttributeError,
'ObjectList is not bound to a model yet. '
'Use `.bind_to(model=model)` before using this method.'):
edit_handler.get_form_class()
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:7,代码来源:test_edit_handlers.py
示例2: get_edit_handler
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,代码行数:8,代码来源:views.py
示例3: test_render_with_panel_overrides
def test_render_with_panel_overrides(self):
"""
Check that inline panel renders the panels listed in the InlinePanel definition
where one is specified
"""
speaker_object_list = ObjectList([
InlinePanel('speakers', label="Speakers", panels=[
FieldPanel('first_name', widget=forms.Textarea),
ImageChooserPanel('image'),
]),
]).bind_to_model(EventPage)
speaker_inline_panel = speaker_object_list.children[0]
EventPageForm = speaker_object_list.get_form_class()
# speaker_inline_panel 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_inline_panel.bind_to_instance(
instance=event_page, form=form, request=self.request)
result = panel.render_as_field()
# rendered panel should contain first_name rendered as a text area, but no last_name field
self.assertIn('<label for="id_speakers-0-first_name">Name:</label>', result)
self.assertIn('Father</textarea>', result)
self.assertNotIn('<label for="id_speakers-0-last_name">Surname:</label>', result)
# test for #338: surname field should not be rendered as a 'stray' label-less field
self.assertTagInHTML('<input id="id_speakers-0-last_name">', result, count=0, allow_extra_attrs=True)
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
)
# render_js_init must provide the JS initializer
self.assertIn('var panel = InlinePanel({', panel.render_js_init())
开发者ID:springload,项目名称:wagtail,代码行数:58,代码来源:test_edit_handlers.py
示例4: get_snippet_edit_handler
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:kaedroho,项目名称:wagtail,代码行数:12,代码来源:snippets.py
示例5: get_edit_handler
def get_edit_handler(self):
if hasattr(self.model, 'edit_handler'):
edit_handler = self.model.edit_handler
elif hasattr(self.model, 'panels'):
edit_handler = ObjectList(self.model.panels)
else:
edit_handler = TabbedInterface([
ObjectList(self.model.content_panels, heading=_("Content")),
ObjectList(self.model.settings_panels, heading=_("Settings"),
classname="settings"),
])
return edit_handler.bind_to_model(self.model)
开发者ID:ababic,项目名称:wagtailmenus,代码行数:12,代码来源:views.py
示例6: test_render
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)
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(instance=event_page,
form=form,
request=self.request)
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:springload,项目名称:wagtail,代码行数:51,代码来源:test_edit_handlers.py
示例7: TestObjectList
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,代码行数:50,代码来源:test_edit_handlers.py
示例8: _patch_other_models
def _patch_other_models(self, model):
if hasattr(model, 'edit_handler'):
edit_handler = model.edit_handler
for tab in edit_handler:
tab.children = self._patch_panels(tab.children)
elif hasattr(model, 'panels'):
model.panels = self._patch_panels(model.panels)
else:
panels = extract_panel_definitions_from_model_class(model)
translation_registered_fields = translator.get_options_for_model(model).fields
panels = filter(lambda field: field.field_name not in translation_registered_fields, panels)
edit_handler = ObjectList(panels)
SNIPPET_EDIT_HANDLERS[model] = edit_handler.bind_to_model(model)
开发者ID:infoportugal,项目名称:wagtail-modeltranslation,代码行数:14,代码来源:patch_wagtailadmin.py
示例9: test_autodetect_page_type
def test_autodetect_page_type(self):
# Model has a foreign key to EventPage, which we want to autodetect
# instead of specifying the page type in PageChooserPanel
MyPageObjectList = ObjectList([PageChooserPanel('page')]).bind_to_model(EventPageChooserModel)
MyPageChooserPanel = MyPageObjectList.children[0]
PageChooserForm = MyPageObjectList.get_form_class(EventPageChooserModel)
form = PageChooserForm(instance=self.test_instance)
page_chooser_panel = MyPageChooserPanel(instance=self.test_instance, form=form)
result = page_chooser_panel.render_as_field()
expected_js = 'createPageChooser("{id}", ["{model}"], {parent}, false, null);'.format(
id="id_page", model="tests.eventpage", parent=self.events_index_page.id)
self.assertIn(expected_js, result)
开发者ID:morris-tech,项目名称:wagtail,代码行数:14,代码来源:test_edit_handlers.py
示例10: test_override_page_type
def test_override_page_type(self):
# Model has a foreign key to Page, but we specify EventPage in the PageChooserPanel
# to restrict the chooser to that page type
MyPageObjectList = ObjectList([
PageChooserPanel('page', 'tests.EventPage')
]).bind_to_model(EventPageChooserModel)
MyPageChooserPanel = MyPageObjectList.children[0]
PageChooserForm = MyPageObjectList.get_form_class(EventPageChooserModel)
form = PageChooserForm(instance=self.test_instance)
page_chooser_panel = MyPageChooserPanel(instance=self.test_instance, form=form)
result = page_chooser_panel.render_as_field()
expected_js = 'createPageChooser("{id}", ["{model}"], {parent}, false, null);'.format(
id="id_page", model="tests.eventpage", parent=self.events_index_page.id)
self.assertIn(expected_js, result)
开发者ID:morris-tech,项目名称:wagtail,代码行数:16,代码来源:test_edit_handlers.py
示例11: test_render_js_init_with_can_choose_root_true
def test_render_js_init_with_can_choose_root_true(self):
# construct an alternative page chooser panel object, with can_choose_root=True
MyPageObjectList = ObjectList([
PageChooserPanel('page', can_choose_root=True)
]).bind_to_model(PageChooserModel)
MyPageChooserPanel = MyPageObjectList.children[0]
PageChooserForm = MyPageObjectList.get_form_class(EventPageChooserModel)
form = PageChooserForm(instance=self.test_instance)
page_chooser_panel = MyPageChooserPanel(instance=self.test_instance, form=form)
result = page_chooser_panel.render_as_field()
# the canChooseRoot flag on createPageChooser should now be true
expected_js = 'createPageChooser("{id}", ["{model}"], {parent}, true, null);'.format(
id="id_page", model="wagtailcore.page", parent=self.events_index_page.id)
self.assertIn(expected_js, result)
开发者ID:morris-tech,项目名称:wagtail,代码行数:17,代码来源:test_edit_handlers.py
示例12: setUp
def setUp(self):
# a custom ObjectList for EventPage
self.EventPageObjectList = 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)
开发者ID:morris-tech,项目名称:wagtail,代码行数:8,代码来源:test_edit_handlers.py
示例13: test_no_thousand_separators_in_js
def test_no_thousand_separators_in_js(self):
"""
Test that the USE_THOUSAND_SEPARATOR setting does not screw up the rendering of numbers
(specifically maxForms=1000) in the JS initializer:
https://github.com/wagtail/wagtail/pull/2699
https://github.com/wagtail/wagtail/issues/3227
"""
speaker_object_list = ObjectList([
InlinePanel('speakers', label="Speakers", panels=[
FieldPanel('first_name', widget=forms.Textarea),
ImageChooserPanel('image'),
]),
]).bind_to(model=EventPage, request=self.request)
speaker_inline_panel = speaker_object_list.children[0]
EventPageForm = speaker_object_list.get_form_class()
event_page = EventPage.objects.get(slug='christmas')
form = EventPageForm(instance=event_page)
panel = speaker_inline_panel.bind_to(instance=event_page, form=form)
self.assertIn('maxForms: 1000', panel.render_js_init())
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:20,代码来源:test_edit_handlers.py
示例14: setUp
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)
开发者ID:springload,项目名称:wagtail,代码行数:11,代码来源:test_edit_handlers.py
示例15: TestPageChooserPanel
class TestPageChooserPanel(TestCase):
fixtures = ['test.json']
def setUp(self):
model = PageChooserModel # a model with a foreign key to Page which we want to render as a page chooser
# a PageChooserPanel class that works on PageChooserModel's 'page' field
self.EditHandler = ObjectList([PageChooserPanel('page')]).bind_to_model(PageChooserModel)
self.MyPageChooserPanel = self.EditHandler.children[0]
# build a form class containing the fields that MyPageChooserPanel wants
self.PageChooserForm = self.EditHandler.get_form_class(PageChooserModel)
# a test instance of PageChooserModel, pointing to the 'christmas' page
self.christmas_page = Page.objects.get(slug='christmas')
self.events_index_page = Page.objects.get(slug='events')
self.test_instance = model.objects.create(page=self.christmas_page)
self.form = self.PageChooserForm(instance=self.test_instance)
self.page_chooser_panel = self.MyPageChooserPanel(instance=self.test_instance, form=self.form)
def test_page_chooser_uses_correct_widget(self):
self.assertEqual(type(self.form.fields['page'].widget), AdminPageChooser)
def test_render_js_init(self):
result = self.page_chooser_panel.render_as_field()
expected_js = 'createPageChooser("{id}", ["{model}"], {parent}, false, null);'.format(
id="id_page", model="wagtailcore.page", parent=self.events_index_page.id)
self.assertIn(expected_js, result)
def test_render_js_init_with_can_choose_root_true(self):
# construct an alternative page chooser panel object, with can_choose_root=True
MyPageObjectList = ObjectList([
PageChooserPanel('page', can_choose_root=True)
]).bind_to_model(PageChooserModel)
MyPageChooserPanel = MyPageObjectList.children[0]
PageChooserForm = MyPageObjectList.get_form_class(EventPageChooserModel)
form = PageChooserForm(instance=self.test_instance)
page_chooser_panel = MyPageChooserPanel(instance=self.test_instance, form=form)
result = page_chooser_panel.render_as_field()
# the canChooseRoot flag on createPageChooser should now be true
expected_js = 'createPageChooser("{id}", ["{model}"], {parent}, true, null);'.format(
id="id_page", model="wagtailcore.page", parent=self.events_index_page.id)
self.assertIn(expected_js, result)
def test_get_chosen_item(self):
result = self.page_chooser_panel.get_chosen_item()
self.assertEqual(result, self.christmas_page)
def test_render_as_field(self):
result = self.page_chooser_panel.render_as_field()
self.assertIn('<p class="help">help text</p>', result)
self.assertIn('<span class="title">Christmas</span>', result)
self.assertIn(
'<a href="/admin/pages/%d/edit/" class="edit-link button button-small button-secondary" target="_blank">'
'Edit this page</a>' % self.christmas_page.id,
result)
def test_render_as_empty_field(self):
test_instance = PageChooserModel()
form = self.PageChooserForm(instance=test_instance)
page_chooser_panel = self.MyPageChooserPanel(instance=test_instance, form=form)
result = page_chooser_panel.render_as_field()
self.assertIn('<p class="help">help text</p>', result)
self.assertIn('<span class="title"></span>', result)
self.assertIn('Choose a page', result)
def test_render_error(self):
form = self.PageChooserForm({'page': ''}, instance=self.test_instance)
self.assertFalse(form.is_valid())
page_chooser_panel = self.MyPageChooserPanel(instance=self.test_instance, form=form)
self.assertIn('<span>This field is required.</span>', page_chooser_panel.render_as_field())
def test_override_page_type(self):
# Model has a foreign key to Page, but we specify EventPage in the PageChooserPanel
# to restrict the chooser to that page type
MyPageObjectList = ObjectList([
PageChooserPanel('page', 'tests.EventPage')
]).bind_to_model(EventPageChooserModel)
MyPageChooserPanel = MyPageObjectList.children[0]
PageChooserForm = MyPageObjectList.get_form_class(EventPageChooserModel)
form = PageChooserForm(instance=self.test_instance)
page_chooser_panel = MyPageChooserPanel(instance=self.test_instance, form=form)
result = page_chooser_panel.render_as_field()
expected_js = 'createPageChooser("{id}", ["{model}"], {parent}, false, null);'.format(
id="id_page", model="tests.eventpage", parent=self.events_index_page.id)
self.assertIn(expected_js, result)
def test_autodetect_page_type(self):
# Model has a foreign key to EventPage, which we want to autodetect
# instead of specifying the page type in PageChooserPanel
MyPageObjectList = ObjectList([PageChooserPanel('page')]).bind_to_model(EventPageChooserModel)
#.........这里部分代码省略.........
开发者ID:morris-tech,项目名称:wagtail,代码行数:101,代码来源:test_edit_handlers.py
注:本文中的wagtail.admin.edit_handlers.ObjectList类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论