Here are the examples of the python api django.forms.EmailField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
29 Examples
3
Source : __init__.py
with GNU General Public License v3.0
from Aghoreshwar
with GNU General Public License v3.0
from Aghoreshwar
def formfield(self, **kwargs):
# As with CharField, this will cause email validation to be performed
# twice.
defaults = {
'form_class': forms.EmailField,
}
defaults.update(kwargs)
return super().formfield(**defaults)
class FilePathField(Field):
3
Source : __init__.py
with MIT License
from Air-999
with MIT License
from Air-999
def formfield(self, **kwargs):
# As with CharField, this will cause email validation to be performed
# twice.
return super().formfield(**{
'form_class': forms.EmailField,
**kwargs,
})
class FilePathField(Field):
3
Source : __init__.py
with MIT License
from chunky2808
with MIT License
from chunky2808
def formfield(self, **kwargs):
# As with CharField, this will cause email validation to be performed
# twice.
defaults = {
'form_class': forms.EmailField,
}
defaults.update(kwargs)
return super(EmailField, self).formfield(**defaults)
class FilePathField(Field):
3
Source : snippet.py
with Apache License 2.0
from dockerizeme
with Apache License 2.0
from dockerizeme
def validate(self, value):
super(forms.EmailField, self).validate(value)
try:
User.objects.get(email = value)
raise forms.ValidationError("Email already exists")
except User.MultipleObjectsReturned:
raise forms.ValidationError("Email already exists")
except User.DoesNotExist:
pass
class ExtendedUserCreationForm(UserCreationForm):
3
Source : test_combofield.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_combofield_1(self):
f = ComboField(fields=[CharField(max_length=20), EmailField()])
self.assertEqual('[email protected]', f.clean('[email protected]'))
with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 28).'"):
f.clean('[email protected]')
with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('not an email')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None)
def test_combofield_2(self):
3
Source : test_combofield.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_combofield_2(self):
f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False)
self.assertEqual('[email protected]', f.clean('[email protected]'))
with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 28).'"):
f.clean('[email protected]')
with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('not an email')
self.assertEqual('', f.clean(''))
self.assertEqual('', f.clean(None))
3
Source : test_emailfield.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_emailfield_1(self):
f = EmailField()
self.assertWidgetRendersTo(f, ' < input type="email" name="f" id="id_f" required />')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('')
with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None)
self.assertEqual('[email protected]', f.clean('[email protected]'))
with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('foo')
self.assertEqual(
'[email protected]\xe4\xf6\xfc\xdfabc.part.com',
f.clean('[email protected]äöüßabc.part.com')
)
def test_email_regexp_for_performance(self):
3
Source : test_emailfield.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_email_regexp_for_performance(self):
f = EmailField()
# Check for runaway regex security problem. This will take a long time
# if the security fix isn't in place.
addr = '[email protected]'
self.assertEqual(addr, f.clean(addr))
def test_emailfield_not_required(self):
3
Source : test_emailfield.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_emailfield_not_required(self):
f = EmailField(required=False)
self.assertEqual('', f.clean(''))
self.assertEqual('', f.clean(None))
self.assertEqual('[email protected]', f.clean('[email protected]'))
self.assertEqual('[email protected]', f.clean(' [email protected] \t \t '))
with self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('foo')
def test_emailfield_min_max_length(self):
3
Source : test_emailfield.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_emailfield_min_max_length(self):
f = EmailField(min_length=10, max_length=15)
self.assertWidgetRendersTo(
f,
' < input id="id_f" type="email" name="f" maxlength="15" minlength="10" required />',
)
with self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'"):
f.clean('[email protected]')
self.assertEqual('[email protected]', f.clean('[email protected]'))
with self.assertRaisesMessage(ValidationError, "'Ensure this value has at most 15 characters (it has 20).'"):
f.clean('[email protected]')
def test_emailfield_strip_on_none_value(self):
3
Source : test_error_messages.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_emailfield(self):
e = {
'required': 'REQUIRED',
'invalid': 'INVALID',
'min_length': 'LENGTH %(show_value)s, MIN LENGTH %(limit_value)s',
'max_length': 'LENGTH %(show_value)s, MAX LENGTH %(limit_value)s',
}
f = EmailField(min_length=8, max_length=10, error_messages=e)
self.assertFormErrors(['REQUIRED'], f.clean, '')
self.assertFormErrors(['INVALID'], f.clean, 'abcdefgh')
self.assertFormErrors(['LENGTH 7, MIN LENGTH 8'], f.clean, '[email protected]')
self.assertFormErrors(['LENGTH 11, MAX LENGTH 10'], f.clean, '[email protected]')
def test_filefield(self):
3
Source : utils.py
with MIT License
from guidovranken
with MIT License
from guidovranken
def test_forms_EmailField(inp):
try:
forms.EmailField().clean(inp)
except:
pass
def test_forms_Field(inp):
3
Source : __init__.py
with Apache License 2.0
from lumanjiao
with Apache License 2.0
from lumanjiao
def formfield(self, **kwargs):
# As with CharField, this will cause email validation to be performed
# twice.
defaults = {
'form_class': forms.EmailField,
}
defaults.update(kwargs)
return super(EmailField, self).formfield(**defaults)
class FilePathField(Field):
3
Source : fields.py
with BSD 3-Clause "New" or "Revised" License
from Shahprogrammer
with BSD 3-Clause "New" or "Revised" License
from Shahprogrammer
def formfield(self, **kwargs):
# As with CharField, this will cause email validation to be performed
# twice.
return super().formfield(**{
'form_class': forms.EmailField,
**kwargs,
})
class FloatField(models.FloatField):
0
Source : utils.py
with MIT License
from askvortsov1
with MIT License
from askvortsov1
def _process_email(field_json):
return forms.EmailField()
def _process_hidden(field_json):
0
Source : forms.py
with GNU General Public License v3.0
from auto-mat
with GNU General Public License v3.0
from auto-mat
def __init__(self, user_attendance, success_url, *args, **kwargs):
self.user_attendance = user_attendance
if self.user_attendance.campaign.max_team_members and self.user_attendance.team:
self.free_capacity = (
self.user_attendance.campaign.max_team_members
- self.user_attendance.team.member_count
)
else:
self.free_capacity = 0
ret_val = super().__init__(*args, **kwargs)
fields = []
for i in range(1, min(self.free_capacity + 1, 11)):
field_name = "email%s" % i
self.fields[field_name] = forms.EmailField(
label=_("E-mail kolegy"),
required=False,
)
fields.append(field_name)
self.helper = FormHelper()
self.helper.form_class = "dirty-check"
self.helper.form_id = "invite-form"
self.helper.add_input(
Button(
"submit",
_("Přeskočit"),
css_class="btn-default",
onclick='window.location.href="{}"'.format(success_url),
),
)
self.helper.add_input(Submit("submit", _("Odeslat pozvánku")))
for field in self.fields.values():
field.widget.attrs["autocomplete"] = "new-password"
return ret_val
class TeamSettingsForm(InitialFieldsMixin, SubmitMixin, forms.ModelForm):
0
Source : snippet.py
with Apache License 2.0
from dockerizeme
with Apache License 2.0
from dockerizeme
def __init__(self, *args, **kwargs):
super(UserCreationFormExtended, self).__init__(*args, **kwargs)
self.fields['email'] = forms.EmailField(label=_("E-mail"), max_length=75)
UserAdmin.add_form = UserCreationFormExtended
0
Source : forms.py
with MIT License
from dtcooper
with MIT License
from dtcooper
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not self.instance.is_superuser:
# Make sure these fields are only editable by superusers
for field_name in (
"username",
"email",
"harbor_auth",
"gcal_entry_grace_minutes",
"gcal_exit_grace_minutes",
):
field = self.fields[field_name]
field.disabled = True
field.help_text += " (Read-only. You'll need an administrator to update this for you.)"
self.fields["timezone"].help_text = f'(Currently {date_format(timezone.localtime(), "SHORT_DATETIME_FORMAT")})'
remove_grace_fields = self.instance.harbor_auth != User.HarborAuth.GOOGLE_CALENDAR
if not config.GOOGLE_CALENDAR_ENABLED:
self.fields["harbor_auth"].choices = list(
filter(
lambda c: c[0] != User.HarborAuth.GOOGLE_CALENDAR,
User.HarborAuth.choices,
)
)
remove_grace_fields = True
if remove_grace_fields:
del self.fields["gcal_entry_grace_minutes"]
del self.fields["gcal_exit_grace_minutes"]
if not self.instance.get_sftp_allowable_models():
del self.fields["authorized_keys"]
if settings.EMAIL_ENABLED and not self.instance.is_superuser:
del self.fields["email"]
self.fields["update_email"] = forms.EmailField(
label="Email address",
required=True,
initial=self.instance.email,
max_length=User._meta.get_field("email").max_length,
)
if AudioAsset not in self.instance.get_sftp_allowable_models():
del self.fields["sftp_playlists_by_folder"]
self.order_fields(
(
"username",
"email",
"update_email",
"timezone",
"name",
"harbor_auth",
"gcal_entry_grace_minutes",
"gcal_exit_grace_minutes",
"sftp_playlists_by_folder",
"authorized_keys",
)
)
def clean_update_email(self):
0
Source : test_emailfield.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_emailfield_strip_on_none_value(self):
f = EmailField(required=False, empty_value=None)
self.assertIsNone(f.clean(None))
def test_emailfield_unable_to_set_strip_kwarg(self):
0
Source : test_emailfield.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_emailfield_unable_to_set_strip_kwarg(self):
msg = "__init__() got multiple values for keyword argument 'strip'"
with self.assertRaisesMessage(TypeError, msg):
EmailField(strip=False)
0
Source : test_forms.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_various_boolean_values(self):
class SignupForm(Form):
email = EmailField()
get_spam = BooleanField()
f = SignupForm(auto_id=False)
self.assertHTMLEqual(str(f['email']), ' < input type="email" name="email" required />')
self.assertHTMLEqual(str(f['get_spam']), ' < input type="checkbox" name="get_spam" required />')
f = SignupForm({'email': '[email protected]', 'get_spam': True}, auto_id=False)
self.assertHTMLEqual(str(f['email']), ' < input type="email" name="email" value="[email protected]" required />')
self.assertHTMLEqual(
str(f['get_spam']),
' < input checked type="checkbox" name="get_spam" required />',
)
# 'True' or 'true' should be rendered without a value attribute
f = SignupForm({'email': '[email protected]', 'get_spam': 'True'}, auto_id=False)
self.assertHTMLEqual(
str(f['get_spam']),
' < input checked type="checkbox" name="get_spam" required />',
)
f = SignupForm({'email': '[email protected]', 'get_spam': 'true'}, auto_id=False)
self.assertHTMLEqual(
str(f['get_spam']), ' < input checked type="checkbox" name="get_spam" required />')
# A value of 'False' or 'false' should be rendered unchecked
f = SignupForm({'email': '[email protected]', 'get_spam': 'False'}, auto_id=False)
self.assertHTMLEqual(str(f['get_spam']), ' < input type="checkbox" name="get_spam" required />')
f = SignupForm({'email': '[email protected]', 'get_spam': 'false'}, auto_id=False)
self.assertHTMLEqual(str(f['get_spam']), ' < input type="checkbox" name="get_spam" required />')
# A value of '0' should be interpreted as a True value (#16820)
f = SignupForm({'email': '[email protected]', 'get_spam': '0'})
self.assertTrue(f.is_valid())
self.assertTrue(f.cleaned_data.get('get_spam'))
def test_widget_output(self):
0
Source : test_forms.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_error_html_required_html_classes(self):
class Person(Form):
name = CharField()
is_cool = NullBooleanField()
email = EmailField(required=False)
age = IntegerField()
p = Person({})
p.error_css_class = 'error'
p.required_css_class = 'required'
self.assertHTMLEqual(
p.as_ul(),
""" < li class="required error"> < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< label class="required" for="id_name">Name: < /label> < input type="text" name="name" id="id_name" required /> < /li>
< li class="required"> < label class="required" for="id_is_cool">Is cool: < /label>
< select name="is_cool" id="id_is_cool">
< option value="1" selected>Unknown < /option>
< option value="2">Yes < /option>
< option value="3">No < /option>
< /select> < /li>
< li> < label for="id_email">Email: < /label> < input type="email" name="email" id="id_email" /> < /li>
< li class="required error"> < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< label class="required" for="id_age">Age: < /label> < input type="number" name="age" id="id_age" required /> < /li>"""
)
self.assertHTMLEqual(
p.as_p(),
""" < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< p class="required error"> < label class="required" for="id_name">Name: < /label>
< input type="text" name="name" id="id_name" required /> < /p>
< p class="required"> < label class="required" for="id_is_cool">Is cool: < /label>
< select name="is_cool" id="id_is_cool">
< option value="1" selected>Unknown < /option>
< option value="2">Yes < /option>
< option value="3">No < /option>
< /select> < /p>
< p> < label for="id_email">Email: < /label> < input type="email" name="email" id="id_email" /> < /p>
< ul class="errorlist"> < li>This field is required. < /li> < /ul>
< p class="required error"> < label class="required" for="id_age">Age: < /label>
< input type="number" name="age" id="id_age" required /> < /p>"""
)
self.assertHTMLEqual(
p.as_table(),
""" < tr class="required error">
< th> < label class="required" for="id_name">Name: < /label> < /th>
< td> < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< input type="text" name="name" id="id_name" required /> < /td> < /tr>
< tr class="required"> < th> < label class="required" for="id_is_cool">Is cool: < /label> < /th>
< td> < select name="is_cool" id="id_is_cool">
< option value="1" selected>Unknown < /option>
< option value="2">Yes < /option>
< option value="3">No < /option>
< /select> < /td> < /tr>
< tr> < th> < label for="id_email">Email: < /label> < /th> < td>
< input type="email" name="email" id="id_email" /> < /td> < /tr>
< tr class="required error"> < th> < label class="required" for="id_age">Age: < /label> < /th>
< td> < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< input type="number" name="age" id="id_age" required /> < /td> < /tr>"""
)
def test_label_has_required_css_class(self):
0
Source : test_forms.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_errorlist_override(self):
@python_2_unicode_compatible
class DivErrorList(ErrorList):
def __str__(self):
return self.as_divs()
def as_divs(self):
if not self:
return ''
return ' < div class="errorlist">%s < /div>' % ''.join(
' < div class="error">%s < /div>' % force_text(e) for e in self)
class CommentForm(Form):
name = CharField(max_length=50, required=False)
email = EmailField()
comment = CharField()
data = dict(email='invalid')
f = CommentForm(data, auto_id=False, error_class=DivErrorList)
self.assertHTMLEqual(f.as_p(), """ < p>Name: < input type="text" name="name" maxlength="50" /> < /p>
< div class="errorlist"> < div class="error">Enter a valid email address. < /div> < /div>
< p>Email: < input type="email" name="email" value="invalid" required /> < /p>
< div class="errorlist"> < div class="error">This field is required. < /div> < /div>
< p>Comment: < input type="text" name="comment" required /> < /p>""")
def test_baseform_repr(self):
0
Source : views.py
with GNU Lesser General Public License v3.0
from littlemo
with GNU Lesser General Public License v3.0
from littlemo
def post(self, request, format=None):
'''
用例::
{
"email": "[email protected]"
}
'''
email = request.data.get('email', None)
log.info('email: {}'.format(email))
if not email:
return Response(
_('email 字段为空'), status=status.HTTP_400_BAD_REQUEST)
f = forms.EmailField()
try:
email = f.clean(email)
except ValidationError as e:
return Response(
_('Email 值错误:{}'.format(', '.join(e))),
status=status.HTTP_400_BAD_REQUEST)
try:
invite = Invitation.create(email, inviter=self.request.user)
invite.save()
invite.send_invitation(self.request)
except Exception as e:
return Response(e, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(
_('已发送注册邀请邮件到【{email}】').format(email=email),
status=status.HTTP_200_OK)
0
Source : views.py
with GNU Lesser General Public License v3.0
from littlemo
with GNU Lesser General Public License v3.0
from littlemo
def post(self, request, format=None):
'''
用例::
{
"device_addr": "[email protected]"
}
'''
um_device_addr = request.data.get('device_addr', None)
log.info('um_device_addr: {}'.format(um_device_addr))
f = forms.EmailField(required=False)
try:
um_device_addr = f.clean(um_device_addr)
except ValidationError as e:
return Response({
'device_addr': {
'rc': False,
'msg': _('Email 值错误:{}').format(', '.join(e))
},
}, status=status.HTTP_200_OK)
try:
um, created = UserMeta.objects.get_or_create(
user=request.user,
name=UserMeta.MOEAR_DEVICE_ADDR,
defaults={
'value': um_device_addr,
})
if not created:
um.value = um_device_addr
um.save()
except Exception as e:
return Response(e, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response({
'device_addr': {
'rc': True,
}
}, status=status.HTTP_200_OK)
class DeliverLogAPIView(APIView):
0
Source : testcase.py
with GNU General Public License v2.0
from puncoder
with GNU General Public License v2.0
from puncoder
def _validate_cc_list(cc_list):
"""
Validate each email address given in argument. Called by
notification RPC methods.
:param cc_list: List of email addresses
:type cc_list: list
:return: None
:raises: TypeError or ValidationError if addresses are not valid.
"""
if not isinstance(cc_list, list):
raise TypeError('cc_list should be a list object.')
field = EmailField(required=True)
invalid_emails = []
for item in cc_list:
try:
field.clean(item)
except ValidationError:
invalid_emails.append(item)
if invalid_emails:
raise ValidationError(
field.error_messages['invalid'] % {
'value': ', '.join(invalid_emails)})
@permissions_required('testcases.change_testcase')
0
Source : django-tests-forms_tests-tests-test_forms.py
with Apache License 2.0
from SMAT-Lab
with Apache License 2.0
from SMAT-Lab
def test_various_boolean_values(self):
class SignupForm(Form):
email = EmailField()
get_spam = BooleanField()
f = SignupForm(auto_id=False)
self.assertHTMLEqual(str(f['email']), ' < input type="email" name="email" required>')
self.assertHTMLEqual(str(f['get_spam']), ' < input type="checkbox" name="get_spam" required>')
f = SignupForm({'email': '[email protected]', 'get_spam': True}, auto_id=False)
self.assertHTMLEqual(str(f['email']), ' < input type="email" name="email" value="[email protected]" required>')
self.assertHTMLEqual(
str(f['get_spam']),
' < input checked type="checkbox" name="get_spam" required>',
)
# 'True' or 'true' should be rendered without a value attribute
f = SignupForm({'email': '[email protected]', 'get_spam': 'True'}, auto_id=False)
self.assertHTMLEqual(
str(f['get_spam']),
' < input checked type="checkbox" name="get_spam" required>',
)
f = SignupForm({'email': '[email protected]', 'get_spam': 'true'}, auto_id=False)
self.assertHTMLEqual(
str(f['get_spam']), ' < input checked type="checkbox" name="get_spam" required>')
# A value of 'False' or 'false' should be rendered unchecked
f = SignupForm({'email': '[email protected]', 'get_spam': 'False'}, auto_id=False)
self.assertHTMLEqual(str(f['get_spam']), ' < input type="checkbox" name="get_spam" required>')
f = SignupForm({'email': '[email protected]', 'get_spam': 'false'}, auto_id=False)
self.assertHTMLEqual(str(f['get_spam']), ' < input type="checkbox" name="get_spam" required>')
# A value of '0' should be interpreted as a True value (#16820)
f = SignupForm({'email': '[email protected]', 'get_spam': '0'})
self.assertTrue(f.is_valid())
self.assertTrue(f.cleaned_data.get('get_spam'))
def test_widget_output(self):
0
Source : django-tests-forms_tests-tests-test_forms.py
with Apache License 2.0
from SMAT-Lab
with Apache License 2.0
from SMAT-Lab
def test_error_html_required_html_classes(self):
class Person(Form):
name = CharField()
is_cool = NullBooleanField()
email = EmailField(required=False)
age = IntegerField()
p = Person({})
p.error_css_class = 'error'
p.required_css_class = 'required'
self.assertHTMLEqual(
p.as_ul(),
""" < li class="required error"> < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< label class="required" for="id_name">Name: < /label> < input type="text" name="name" id="id_name" required> < /li>
< li class="required"> < label class="required" for="id_is_cool">Is cool: < /label>
< select name="is_cool" id="id_is_cool">
< option value="unknown" selected>Unknown < /option>
< option value="true">Yes < /option>
< option value="false">No < /option>
< /select> < /li>
< li> < label for="id_email">Email: < /label> < input type="email" name="email" id="id_email"> < /li>
< li class="required error"> < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< label class="required" for="id_age">Age: < /label> < input type="number" name="age" id="id_age" required> < /li>"""
)
self.assertHTMLEqual(
p.as_p(),
""" < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< p class="required error"> < label class="required" for="id_name">Name: < /label>
< input type="text" name="name" id="id_name" required> < /p>
< p class="required"> < label class="required" for="id_is_cool">Is cool: < /label>
< select name="is_cool" id="id_is_cool">
< option value="unknown" selected>Unknown < /option>
< option value="true">Yes < /option>
< option value="false">No < /option>
< /select> < /p>
< p> < label for="id_email">Email: < /label> < input type="email" name="email" id="id_email"> < /p>
< ul class="errorlist"> < li>This field is required. < /li> < /ul>
< p class="required error"> < label class="required" for="id_age">Age: < /label>
< input type="number" name="age" id="id_age" required> < /p>"""
)
self.assertHTMLEqual(
p.as_table(),
""" < tr class="required error">
< th> < label class="required" for="id_name">Name: < /label> < /th>
< td> < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< input type="text" name="name" id="id_name" required> < /td> < /tr>
< tr class="required"> < th> < label class="required" for="id_is_cool">Is cool: < /label> < /th>
< td> < select name="is_cool" id="id_is_cool">
< option value="unknown" selected>Unknown < /option>
< option value="true">Yes < /option>
< option value="false">No < /option>
< /select> < /td> < /tr>
< tr> < th> < label for="id_email">Email: < /label> < /th> < td>
< input type="email" name="email" id="id_email"> < /td> < /tr>
< tr class="required error"> < th> < label class="required" for="id_age">Age: < /label> < /th>
< td> < ul class="errorlist"> < li>This field is required. < /li> < /ul>
< input type="number" name="age" id="id_age" required> < /td> < /tr>"""
)
def test_label_has_required_css_class(self):
0
Source : django-tests-forms_tests-tests-test_forms.py
with Apache License 2.0
from SMAT-Lab
with Apache License 2.0
from SMAT-Lab
def test_errorlist_override(self):
class DivErrorList(ErrorList):
def __str__(self):
return self.as_divs()
def as_divs(self):
if not self:
return ''
return ' < div class="errorlist">%s < /div>' % ''.join(
' < div class="error">%s < /div>' % e for e in self)
class CommentForm(Form):
name = CharField(max_length=50, required=False)
email = EmailField()
comment = CharField()
data = {'email': 'invalid'}
f = CommentForm(data, auto_id=False, error_class=DivErrorList)
self.assertHTMLEqual(f.as_p(), """ < p>Name: < input type="text" name="name" maxlength="50"> < /p>
< div class="errorlist"> < div class="error">Enter a valid email address. < /div> < /div>
< p>Email: < input type="email" name="email" value="invalid" required> < /p>
< div class="errorlist"> < div class="error">This field is required. < /div> < /div>
< p>Comment: < input type="text" name="comment" required> < /p>""")
def test_error_escaping(self):