本文整理匯總了Python中django.views.generic.edit.FormMixin方法的典型用法代碼示例。如果您正苦於以下問題:Python edit.FormMixin方法的具體用法?Python edit.FormMixin怎麽用?Python edit.FormMixin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.views.generic.edit
的用法示例。
在下文中一共展示了edit.FormMixin方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_get_prefix
# 需要導入模塊: from django.views.generic import edit [as 別名]
# 或者: from django.views.generic.edit import FormMixin [as 別名]
def test_get_prefix(self):
""" Test prefix can be set (see #18872) """
test_string = 'test'
rf = RequestFactory()
get_request = rf.get('/')
class TestFormMixin(FormMixin):
request = get_request
default_kwargs = TestFormMixin().get_form_kwargs()
self.assertIsNone(default_kwargs.get('prefix'))
set_mixin = TestFormMixin()
set_mixin.prefix = test_string
set_kwargs = set_mixin.get_form_kwargs()
self.assertEqual(test_string, set_kwargs.get('prefix'))
示例2: test_get_form
# 需要導入模塊: from django.views.generic import edit [as 別名]
# 或者: from django.views.generic.edit import FormMixin [as 別名]
def test_get_form(self):
class TestFormMixin(FormMixin):
request = RequestFactory().get('/')
self.assertIsInstance(
TestFormMixin().get_form(forms.Form), forms.Form,
'get_form() should use provided form class.'
)
class FormClassTestFormMixin(TestFormMixin):
form_class = forms.Form
self.assertIsInstance(
FormClassTestFormMixin().get_form(), forms.Form,
'get_form() should fallback to get_form_class() if none is provided.'
)
示例3: test_initial_data
# 需要導入模塊: from django.views.generic import edit [as 別名]
# 或者: from django.views.generic.edit import FormMixin [as 別名]
def test_initial_data(self):
""" Test instance independence of initial data dict (see #16138) """
initial_1 = FormMixin().get_initial()
initial_1['foo'] = 'bar'
initial_2 = FormMixin().get_initial()
self.assertNotEqual(initial_1, initial_2)
示例4: test_get_context_data
# 需要導入模塊: from django.views.generic import edit [as 別名]
# 或者: from django.views.generic.edit import FormMixin [as 別名]
def test_get_context_data(self):
class FormContext(FormMixin):
request = RequestFactory().get('/')
form_class = forms.Form
self.assertIsInstance(FormContext().get_context_data()['form'], forms.Form)