本文整理汇总了Python中registration.forms.RegistrationForm方法的典型用法代码示例。如果您正苦于以下问题:Python forms.RegistrationForm方法的具体用法?Python forms.RegistrationForm怎么用?Python forms.RegistrationForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类registration.forms
的用法示例。
在下文中一共展示了forms.RegistrationForm方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from registration import forms [as 别名]
# 或者: from registration.forms import RegistrationForm [as 别名]
def __init__(self, *args, **kwargs):
super(RegistrationForm, self).__init__(*args, **kwargs)
self.fields['username'].label = _(u"Логин")
self.fields['first_name'].label = _(u"Имя")
self.fields['last_name'].label = _(u"Фамилия")
self.fields['show_email'].label = _(u"Показывать мой e-mail всем пользователям")
self.fields.keyOrder = [
'username',
'first_name',
'last_name',
'email',
'show_email',
'password1',
'password2',
#'invite',
]
示例2: test_form_class
# 需要导入模块: from registration import forms [as 别名]
# 或者: from registration.forms import RegistrationForm [as 别名]
def test_form_class(self):
"""
Test that the default form class returned is
``registration.forms.RegistrationForm``.
"""
self.failUnless(self.backend.get_form_class(_mock_request()) is forms.RegistrationForm)
示例3: test_registration_view_initial
# 需要导入模块: from registration import forms [as 别名]
# 或者: from registration.forms import RegistrationForm [as 别名]
def test_registration_view_initial(self):
"""
A ``GET`` to the ``register`` view uses the appropriate
template and populates the registration form into the context.
"""
response = self.client.get(reverse('registration_register'))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response,
'registration/registration_form.html')
self.failUnless(isinstance(response.context['form'],
forms.RegistrationForm))
示例4: __init__
# 需要导入模块: from registration import forms [as 别名]
# 或者: from registration.forms import RegistrationForm [as 别名]
def __init__(self, *args, **kwargs):
super(RegistrationForm, self).__init__(*args, **kwargs)
self.fields['username'].error_messages['required'] = 'Please enter a username.'
self.fields['email'].error_messages['required'] = 'Please enter your email address.'
self.fields['email'].error_messages['invalid'] = 'Please enter a valid email address.'
self.fields['password1'].error_messages['required'] = 'Please enter a password.'
self.fields['password2'].error_messages['required'] = 'Please enter a password.'
示例5: test_is_registration_form
# 需要导入模块: from registration import forms [as 别名]
# 或者: from registration.forms import RegistrationForm [as 别名]
def test_is_registration_form(self):
form = DirigibleRegistrationForm()
self.assertTrue(isinstance(form, RegistrationForm))
示例6: register
# 需要导入模块: from registration import forms [as 别名]
# 或者: from registration.forms import RegistrationForm [as 别名]
def register(self, form):
"""
Save all the fields not included in the standard `RegistrationForm`
into the JSON `data` field of an `ExtraUserDetail` object
"""
standard_fields = set(RegistrationForm().fields.keys())
extra_fields = set(form.fields.keys()).difference(standard_fields)
# Don't save the user unless we successfully store the extra data
with transaction.atomic():
new_user = super().register(form)
extra_data = {k: form.cleaned_data[k] for k in extra_fields}
new_user.extra_details.data.update(extra_data)
new_user.extra_details.save()
return new_user
示例7: test_registration_form
# 需要导入模块: from registration import forms [as 别名]
# 或者: from registration.forms import RegistrationForm [as 别名]
def test_registration_form(self):
"""
Test that ``RegistrationForm`` enforces username constraints
and matching passwords.
"""
# Create a user so we can verify that duplicate usernames aren't
# permitted.
User.objects.create_user('alice', 'alice@example.com', 'secret')
invalid_data_dicts = [
# Non-alphanumeric username.
{'data': {'username': 'foo/bar',
'email': 'foo@example.com',
'password1': 'foo',
'password2': 'foo'},
'error': ('username', [u"This value may contain only letters, numbers and @/./+/-/_ characters."])},
# Already-existing username.
{'data': {'username': 'alice',
'email': 'alice@example.com',
'password1': 'secret',
'password2': 'secret'},
'error': ('username', [u"A user with that username already exists."])},
# Mismatched passwords.
{'data': {'username': 'foo',
'email': 'foo@example.com',
'password1': 'foo',
'password2': 'bar'},
'error': ('__all__', [u"The two password fields didn't match."])},
]
for invalid_dict in invalid_data_dicts:
with translation.override('en'):
form = forms.RegistrationForm(data=invalid_dict['data'])
self.failIf(form.is_valid())
self.assertEqual(form.errors[invalid_dict['error'][0]],
invalid_dict['error'][1])
form = forms.RegistrationForm(data={'username': 'foo',
'email': 'foo@example.com',
'password1': 'foo',
'password2': 'foo'})
self.failUnless(form.is_valid())
示例8: test_registration_form
# 需要导入模块: from registration import forms [as 别名]
# 或者: from registration.forms import RegistrationForm [as 别名]
def test_registration_form(self):
"""
Test that ``RegistrationForm`` enforces username constraints
and matching passwords.
"""
invalid_data_dicts = [
# Non-alphanumeric username.
{
'data':
{ 'username': 'foo/bar',
'email': 'foo@example.com',
'password1': 'foo',
'password2': 'foo' },
'error':
('username', [u"Enter a valid value."])
},
# Already-existing username.
{
'data':
{ 'username': 'alice',
'email': 'alice@example.com',
'password1': 'secret',
'password2': 'secret' },
'error':
('username', [u"This username is already taken. Please choose another."])
},
# Mismatched passwords.
{
'data':
{ 'username': 'foo',
'email': 'foo@example.com',
'password1': 'foo',
'password2': 'bar' },
'error':
('__all__', [u"You must type the same password each time"])
},
]
for invalid_dict in invalid_data_dicts:
form = forms.RegistrationForm(data=invalid_dict['data'])
self.failIf(form.is_valid())
self.assertEqual(form.errors[invalid_dict['error'][0]], invalid_dict['error'][1])
form = forms.RegistrationForm(data={ 'username': 'foo',
'email': 'foo@example.com',
'password1': 'foo',
'password2': 'foo' })
self.failUnless(form.is_valid())