本文整理汇总了Python中wagtail.admin.forms.WagtailAdminPageForm方法的典型用法代码示例。如果您正苦于以下问题:Python forms.WagtailAdminPageForm方法的具体用法?Python forms.WagtailAdminPageForm怎么用?Python forms.WagtailAdminPageForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.admin.forms
的用法示例。
在下文中一共展示了forms.WagtailAdminPageForm方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: base_form_class_check
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def base_form_class_check(app_configs, **kwargs):
from wagtail.admin.forms import WagtailAdminPageForm
from wagtail.core.models import get_page_models
errors = []
for cls in get_page_models():
if not issubclass(cls.base_form_class, WagtailAdminPageForm):
errors.append(Error(
"{}.base_form_class does not extend WagtailAdminPageForm".format(
cls.__name__),
hint="Ensure that {}.{} extends WagtailAdminPageForm".format(
cls.base_form_class.__module__,
cls.base_form_class.__name__),
obj=cls,
id='wagtailadmin.E001'))
return errors
示例2: get_form_class_check
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def get_form_class_check(app_configs, **kwargs):
from wagtail.admin.forms import WagtailAdminPageForm
from wagtail.core.models import get_page_models
errors = []
for cls in get_page_models():
edit_handler = cls.get_edit_handler()
if not issubclass(edit_handler.get_form_class(), WagtailAdminPageForm):
errors.append(Error(
"{cls}.get_edit_handler().get_form_class() does not extend WagtailAdminPageForm".format(
cls=cls.__name__),
hint="Ensure that the EditHandler for {cls} creates a subclass of WagtailAdminPageForm".format(
cls=cls.__name__),
obj=cls,
id='wagtailadmin.E002'))
return errors
示例3: test_get_form_for_model
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def test_get_form_for_model(self):
EventPageForm = get_form_for_model(EventPage, form_class=WagtailAdminPageForm)
form = EventPageForm()
# form should be a subclass of WagtailAdminModelForm
self.assertTrue(issubclass(EventPageForm, WagtailAdminModelForm))
# 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)
示例4: test_tag_widget_is_passed_tag_model
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def test_tag_widget_is_passed_tag_model(self):
RestaurantPageForm = get_form_for_model(
RestaurantPage, form_class=WagtailAdminPageForm
)
form_html = RestaurantPageForm().as_p()
self.assertIn('/admin/tag\\u002Dautocomplete/tests/restauranttag/', form_html)
# widget should pick up the free_tagging=False attribute on the tag model
# and set itself to autocomplete only
self.assertIn('"autocompleteOnly": true', form_html)
# Free tagging should also be disabled at the form field validation level
RestaurantTag.objects.create(name='Italian', slug='italian')
RestaurantTag.objects.create(name='Indian', slug='indian')
form = RestaurantPageForm({
'title': 'Buonasera',
'slug': 'buonasera',
'tags': "Italian, delicious",
})
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data['tags'], ["Italian"])
示例5: test_direct_form_field_overrides
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
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, form_class=WagtailAdminPageForm)
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, form_class=WagtailAdminPageForm)
event_form = EventPageForm()
self.assertEqual(type(event_form.fields['body'].widget), DraftailRichTextArea)
示例6: test_get_form_for_model_with_specific_fields
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def test_get_form_for_model_with_specific_fields(self):
EventPageForm = get_form_for_model(
EventPage, form_class=WagtailAdminPageForm, 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)
示例7: test_get_form_for_model_with_widget_overides_by_class
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
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)
示例8: test_get_form_for_model_with_widget_overides_by_instance
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def test_get_form_for_model_with_widget_overides_by_instance(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)
示例9: test_get_edit_handler
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def test_get_edit_handler(self):
"""
Forms for pages should have a base class of WagtailAdminPageForm.
"""
edit_handler = EventPage.get_edit_handler()
EventPageForm = edit_handler.get_form_class()
# The generated form should inherit from WagtailAdminPageForm
self.assertTrue(issubclass(EventPageForm, WagtailAdminPageForm))
示例10: test_check_invalid_base_form_class
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def test_check_invalid_base_form_class(self):
class BadFormClass:
pass
invalid_base_form = checks.Error(
"ValidatedPage.base_form_class does not extend WagtailAdminPageForm",
hint="Ensure that wagtail.admin.tests.test_edit_handlers.BadFormClass extends WagtailAdminPageForm",
obj=ValidatedPage,
id='wagtailadmin.E001')
invalid_edit_handler = checks.Error(
"ValidatedPage.get_edit_handler().get_form_class() does not extend WagtailAdminPageForm",
hint="Ensure that the EditHandler for ValidatedPage creates a subclass of WagtailAdminPageForm",
obj=ValidatedPage,
id='wagtailadmin.E002')
with mock.patch.object(ValidatedPage, 'base_form_class', new=BadFormClass):
errors = checks.run_checks()
# ignore CSS loading errors (to avoid spurious failures on CI servers that
# don't build the CSS)
errors = [e for e in errors if e.id != 'wagtailadmin.W001']
# Errors may appear out of order, so sort them by id
errors.sort(key=lambda e: e.id)
self.assertEqual(errors, [invalid_base_form, invalid_edit_handler])
示例11: setUp
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def setUp(self):
self.request = RequestFactory().get('/')
user = AnonymousUser() # technically, Anonymous users cannot access the admin
self.request.user = user
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.end_date_panel = (FieldPanel('date_to', classname='full-width')
.bind_to(model=EventPage, request=self.request))
示例12: __str__
# 需要导入模块: from wagtail.admin import forms [as 别名]
# 或者: from wagtail.admin.forms import WagtailAdminPageForm [as 别名]
def __str__(self):
return self.name
# Override the standard WagtailAdminPageForm to add validation on start/end dates
# that appears as a non-field error