本文整理汇总了Python中wagtail.wagtailadmin.edit_handlers.ObjectList类的典型用法代码示例。如果您正苦于以下问题:Python ObjectList类的具体用法?Python ObjectList怎么用?Python ObjectList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
"""
SpeakerObjectList = ObjectList([InlinePanel('speakers', label="Speakers")]).bind_to_model(EventPage)
SpeakerInlinePanel = SpeakerObjectList.children[0]
EventPageForm = SpeakerObjectList.get_form_class(EventPage)
# 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 = SpeakerInlinePanel(instance=event_page, form=form)
result = panel.render_as_field()
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.assertIn('<input id="id_speakers-0-id" name="speakers-0-id" type="hidden"', result)
self.assertIn('<input id="id_speakers-0-DELETE" name="speakers-0-DELETE" type="hidden"', result)
self.assertIn('<input id="id_speakers-0-ORDER" name="speakers-0-ORDER" type="hidden"', result)
# rendered panel must contain maintenance form for the formset
self.assertIn('<input id="id_speakers-TOTAL_FORMS" name="speakers-TOTAL_FORMS" type="hidden"', result)
# render_js_init must provide the JS initializer
self.assertIn('var panel = InlinePanel({', panel.render_js_init())
开发者ID:DjangoBD,项目名称:wagtail,代码行数:35,代码来源:test_edit_handlers.py
示例2: test_is_multipart
def test_is_multipart(self):
"""
Check whether is_multipart returns True when an InlinePanel contains
a FileInput and False otherwise
"""
SpeakerObjectList = ObjectList([
InlinePanel('speakers', label="Speakers", panels=[
FieldPanel('first_name', widget=forms.FileInput),
]),
]).bind_to_model(EventPage)
SpeakerInlinePanel = SpeakerObjectList.children[0]
EventPageForm = SpeakerObjectList.get_form_class(EventPage)
event_page = EventPage.objects.get(slug='christmas')
form = EventPageForm(instance=event_page)
panel = SpeakerInlinePanel(instance=event_page, form=form)
self.assertTrue(panel.is_multipart())
SpeakerObjectList = ObjectList([
InlinePanel('speakers', label="Speakers", panels=[
FieldPanel('first_name', widget=forms.Textarea),
]),
]).bind_to_model(EventPage)
SpeakerInlinePanel = SpeakerObjectList.children[0]
EventPageForm = SpeakerObjectList.get_form_class(EventPage)
event_page = EventPage.objects.get(slug='christmas')
form = EventPageForm(instance=event_page)
panel = SpeakerInlinePanel(instance=event_page, form=form)
self.assertFalse(panel.is_multipart())
开发者ID:thenewguy,项目名称:wagtail,代码行数:32,代码来源:test_edit_handlers.py
示例3: get_edit_handler_class
def get_edit_handler_class(self):
if hasattr(self.model, 'edit_handler'):
edit_handler = self.model.edit_handler
else:
panels = extract_panel_definitions_from_model_class(self.model)
edit_handler = ObjectList(panels)
return edit_handler.bind_to_model(self.model)
开发者ID:potatolondon,项目名称:wagtail-gae,代码行数:7,代码来源:views.py
示例4: get_edit_handler_class
def get_edit_handler_class(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:kapito,项目名称:wagtail,代码行数:8,代码来源:views.py
示例5: 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
"""
SpeakerObjectList = ObjectList([
InlinePanel('speakers', label="Speakers", panels=[
FieldPanel('first_name', widget=forms.Textarea),
ImageChooserPanel('image'),
]),
]).bind_to_model(EventPage)
SpeakerInlinePanel = SpeakerObjectList.children[0]
EventPageForm = SpeakerObjectList.get_form_class(EventPage)
# 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 = SpeakerInlinePanel(instance=event_page, form=form)
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:thenewguy,项目名称:wagtail,代码行数:57,代码来源:test_edit_handlers.py
示例6: 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:FannyFlores,项目名称:wagtail,代码行数:12,代码来源:snippets.py
示例7: 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);'.format(
id="id_page", model="tests.eventpage", parent=self.events_index_page.id)
self.assertIn(expected_js, result)
开发者ID:DjangoBD,项目名称:wagtail,代码行数:14,代码来源:test_edit_handlers.py
示例8: 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);'.format(
id="id_page", model="tests.eventpage", parent=self.events_index_page.id)
self.assertIn(expected_js, result)
开发者ID:DjangoBD,项目名称:wagtail,代码行数:16,代码来源:test_edit_handlers.py
示例9: 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:Fluxflashor,项目名称:wagtail,代码行数:8,代码来源:test_edit_handlers.py
示例10: 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);'.format(
id="id_page", model="wagtailcore.page", parent=self.events_index_page.id)
self.assertIn(expected_js, result)
开发者ID:DjangoBD,项目名称:wagtail,代码行数:17,代码来源:test_edit_handlers.py
示例11: TestObjectList
class TestObjectList(TestCase):
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)
def test_get_form_class(self):
EventPageForm = self.EventPageObjectList.get_form_class(EventPage)
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.EventPageObjectList.get_form_class(EventPage)
event = EventPage(title='Abergavenny sheepdog trials')
form = EventPageForm(instance=event)
object_list = self.EventPageObjectList(
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">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:DjangoBD,项目名称:wagtail,代码行数:46,代码来源:test_edit_handlers.py
示例12: 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/torchbox/wagtail/pull/2699
"""
SpeakerObjectList = ObjectList([
InlinePanel('speakers', label="Speakers", panels=[
FieldPanel('first_name', widget=forms.Textarea),
ImageChooserPanel('image'),
]),
]).bind_to_model(EventPage)
SpeakerInlinePanel = SpeakerObjectList.children[0]
EventPageForm = SpeakerObjectList.get_form_class(EventPage)
event_page = EventPage.objects.get(slug='christmas')
form = EventPageForm(instance=event_page)
panel = SpeakerInlinePanel(instance=event_page, form=form)
self.assertIn('maxForms: 1000', panel.render_js_init())
开发者ID:chrxr,项目名称:wagtail,代码行数:19,代码来源:test_edit_handlers.py
示例13: setUp
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)
开发者ID:DjangoBD,项目名称:wagtail,代码行数:17,代码来源:test_edit_handlers.py
示例14: 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);'.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);'.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);'.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:DjangoBD,项目名称:wagtail,代码行数:101,代码来源:test_edit_handlers.py
示例15: edit_handler_class
def edit_handler_class(self, model):
"""A GenericModelChooserPanel class that works on
PageChooserModel's 'page' field
"""
object_list = ObjectList([GenericModelChooserPanel('page')])
return object_list.bind_to_model(model)
开发者ID:kinaklub,项目名称:next.filmfest.by,代码行数:6,代码来源:test_edit_handlers.py
注:本文中的wagtail.wagtailadmin.edit_handlers.ObjectList类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论