本文整理汇总了Python中wagtail.wagtailadmin.edit_handlers.get_form_for_model函数的典型用法代码示例。如果您正苦于以下问题:Python get_form_for_model函数的具体用法?Python get_form_for_model怎么用?Python get_form_for_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_form_for_model函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_direct_form_field_overrides
def test_direct_form_field_overrides(self):
# Test that field overrides defined through DIRECT_FORM_FIELD_OVERRIDES
# are applied
SimplePageForm = get_form_for_model(SimplePage)
simple_form = SimplePageForm()
# plain TextFields should use AdminAutoHeightTextInput as the widget
self.assertEqual(type(simple_form.fields['content'].widget), AdminAutoHeightTextInput)
# This override should NOT be applied to subclasses of TextField such as
# RichTextField - they should retain their default widgets
EventPageForm = get_form_for_model(EventPage)
event_form = EventPageForm()
self.assertEqual(type(event_form.fields['body'].widget), RichTextArea)
示例2: setUp
def setUp(self):
self.EventPageForm = get_form_for_model(
EventPage, form_class=WagtailAdminPageForm, formsets=[])
self.event = EventPage(title='Abergavenny sheepdog trials',
date_from=date(2014, 7, 20), date_to=date(2014, 7, 21))
self.EndDatePanel = FieldPanel('date_to', classname='full-width').bind_to_model(EventPage)
示例3: test_get_form_for_model_with_widget_overides_by_class
def test_get_form_for_model_with_widget_overides_by_class(self):
EventPageForm = get_form_for_model(
EventPage, form_class=WagtailAdminPageForm,
widgets={'date_from': forms.PasswordInput})
form = EventPageForm()
self.assertEqual(type(form.fields['date_from']), forms.DateField)
self.assertEqual(type(form.fields['date_from'].widget), forms.PasswordInput)
示例4: setUp
def setUp(self):
self.form_page = make_form_page()
self.FormPageForm = get_form_for_model(
FormPage, form_class=WagtailAdminPageForm
)
submissions_panel = FormSubmissionsPanel().bind_to_model(FormPage)
self.panel = submissions_panel(self.form_page, self.FormPageForm())
示例5: setUp
def setUp(self):
self.EventPageForm = get_form_for_model(
EventPage, form_class=WagtailAdminPageForm, formsets=[])
self.event = EventPage(title='Abergavenny sheepdog trials',
date_from=date(2014, 7, 20), date_to=date(2014, 7, 21))
self.DatesPanel = FieldRowPanel([
FieldPanel('date_from', classname='col4'),
FieldPanel('date_to', classname='coltwo'),
]).bind_to_model(EventPage)
示例6: test_get_form_for_model
def test_get_form_for_model(self):
form = get_form_for_model(self.FakeClass,
fields=[],
exclude=[self.mock_exclude],
formsets=['baz'],
exclude_formsets=['quux'],
widgets=['bacon'])
self.assertEqual(form.Meta.exclude, [self.mock_exclude])
self.assertEqual(form.Meta.formsets, ['baz'])
self.assertEqual(form.Meta.exclude_formsets, ['quux'])
self.assertEqual(form.Meta.widgets, ['bacon'])
示例7: test_get_form_for_model_with_specific_fields
def test_get_form_for_model_with_specific_fields(self):
EventPageForm = get_form_for_model(EventPage, fields=['date_from'], formsets=['speakers'])
form = EventPageForm()
# form should contain date_from but not title
self.assertEqual(type(form.fields['date_from']), forms.DateField)
self.assertEqual(type(form.fields['date_from'].widget), AdminDateInput)
self.assertNotIn('title', form.fields)
# formsets should include speakers but not related_links
self.assertIn('speakers', form.formsets)
self.assertNotIn('related_links', form.formsets)
示例8: setUp
def setUp(self):
model = PageChooserModel
self.chosen_page = Page.objects.get(pk=2)
test_instance = model.objects.create(page=self.chosen_page)
self.dotted_model = model._meta.app_label + '.' + model._meta.model_name
self.page_chooser_panel_class = PageChooserPanel('page', model)
form_class = get_form_for_model(model, widgets=self.page_chooser_panel_class.widget_overrides())
form = form_class(instance=test_instance)
form.errors['page'] = form.error_class(['errors'])
self.page_chooser_panel = self.page_chooser_panel_class(instance=test_instance,
form=form)
示例9: get_form_class
def get_form_class(cls, model):
# def clean(form):
# if form.__class__.__name__ == 'ProgramSectionPageForm':
# form.data['title'] = 'TEST - TITLE'
# form.data['slug'] = "{0}-{1}".format(form.data['start_time'], form.data['end_time'])
# return form.clean()
if cls._form_class is None:
cls._form_class = get_form_for_model(
model,
formsets=cls.required_formsets(), widgets=cls.widget_overrides())
# cls._form_class.clean = clean
return cls._form_class
示例10: test_get_form_for_model_with_excluded_fields
def test_get_form_for_model_with_excluded_fields(self):
EventPageForm = get_form_for_model(EventPage, exclude=['title'], exclude_formsets=['related_links'])
form = EventPageForm()
# form should contain date_from but not title
self.assertEqual(type(form.fields['date_from']), forms.DateField)
self.assertEqual(type(form.fields['date_from'].widget), AdminDateInput)
self.assertNotIn('title', form.fields)
# 'path' should still be excluded even though it isn't explicitly in the exclude list
self.assertNotIn('path', form.fields)
# formsets should include speakers but not related_links
self.assertIn('speakers', form.formsets)
self.assertNotIn('related_links', form.formsets)
示例11: test_get_form_for_model
def test_get_form_for_model(self):
EventPageForm = get_form_for_model(EventPage)
form = EventPageForm()
# form should contain a title field (from the base Page)
self.assertEqual(type(form.fields['title']), forms.CharField)
# and 'date_from' from EventPage
self.assertEqual(type(form.fields['date_from']), forms.DateField)
# the widget should be overridden with AdminDateInput as per FORM_FIELD_OVERRIDES
self.assertEqual(type(form.fields['date_from'].widget), AdminDateInput)
# treebeard's 'path' field should be excluded
self.assertNotIn('path', form.fields)
# all child relations become formsets by default
self.assertIn('speakers', form.formsets)
self.assertIn('related_links', form.formsets)
示例12: test_get_form_for_model_with_excluded_fields
def test_get_form_for_model_with_excluded_fields(self):
EventPageForm = get_form_for_model(
EventPage, form_class=WagtailAdminPageForm,
exclude=['title'], exclude_formsets=['related_links'])
form = EventPageForm()
# form should contain date_from but not title
self.assertEqual(type(form.fields['date_from']), forms.DateField)
self.assertEqual(type(form.fields['date_from'].widget), AdminDateInput)
self.assertNotIn('title', form.fields)
# 'path' is not excluded any more, as the excluded fields were overridden
self.assertIn('path', form.fields)
# formsets should include speakers but not related_links
self.assertIn('speakers', form.formsets)
self.assertNotIn('related_links', form.formsets)
示例13: test_get_form_for_model_with_widget_overides_by_instance
def test_get_form_for_model_with_widget_overides_by_instance(self):
EventPageForm = get_form_for_model(EventPage, widgets={'date_from': forms.PasswordInput()})
form = EventPageForm()
self.assertEqual(type(form.fields['date_from']), forms.DateField)
self.assertEqual(type(form.fields['date_from'].widget), forms.PasswordInput)