Here are the examples of the python api django.forms.CharField taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
102 Examples
3
View Complete Implementation : test_array.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_invalid_char_length(self):
field = SplitArrayField(forms.CharField(max_length=2), size=3)
with self.astertRaises(exceptions.ValidationError) as cm:
field.clean(['abc', 'c', 'defg'])
self.astertEqual(cm.exception.messages, [
'Item 1 in the array did not validate: Ensure this value has at most 2 characters (it has 3).',
'Item 3 in the array did not validate: Ensure this value has at most 2 characters (it has 4).',
])
3
View Complete Implementation : test_fields_array.py
Copyright MIT License
Author : openfun
Copyright MIT License
Author : openfun
def test_fields_array_optional_value_not_provided(self):
"""
Happy path: the value is optional and was not provided
"""
# Create an ArrayField instance with some params
array_of_string = ArrayField(
required=False, base_type=forms.CharField(max_length=4)
)
# None is valid input and the field returns an empty array
self.astertEqual(array_of_string.clean(None), [])
3
View Complete Implementation : test_charfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_charfield_2(self):
f = CharField(required=False)
self.astertEqual('1', f.clean(1))
self.astertEqual('hello', f.clean('hello'))
self.astertEqual('', f.clean(None))
self.astertEqual('', f.clean(''))
self.astertEqual('[1, 2, 3]', f.clean([1, 2, 3]))
self.astertIsNone(f.max_length)
self.astertIsNone(f.min_length)
3
View Complete Implementation : test_i18n.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_non_ascii_label(self):
clast SomeForm(Form):
field_1 = CharField(max_length=10, label=gettext_lazy('field_1'))
field_2 = CharField(
max_length=10,
label=gettext_lazy('field_2'),
widget=TextInput(attrs={'id': 'field_2_id'}),
)
f = SomeForm()
self.astertHTMLEqual(f['field_1'].label_tag(), '<label for="id_field_1">field_1:</label>')
self.astertHTMLEqual(f['field_2'].label_tag(), '<label for="field_2_id">field_2:</label>')
3
View Complete Implementation : test_charfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_charfield_length_not_int(self):
"""
Setting min_length or max_length to something that is not a number
raises an exception.
"""
with self.astertRaises(ValueError):
CharField(min_length='a')
with self.astertRaises(ValueError):
CharField(max_length='a')
msg = '__init__() takes 1 positional argument but 2 were given'
with self.astertRaisesMessage(TypeError, msg):
CharField('a')
3
View Complete Implementation : test_config_forms.py
Copyright GNU Affero General Public License v3.0
Author : maas
Copyright GNU Affero General Public License v3.0
Author : maas
def test_DictCharField_does_not_allow_subfield_named_skip_check(self):
# Creating a DictCharField with a subfield named 'skip_check' is not
# allowed.
self.astertRaises(
RuntimeError,
DictCharField,
[("skip_check", forms.CharField(label="Skip Check"))],
)
3
View Complete Implementation : field.py
Copyright MIT License
Author : nshafer
Copyright MIT License
Author : nshafer
def formfield(self, **kwargs):
defaults = {'form_clast': forms.CharField}
defaults.update(kwargs)
if defaults.get('widget') == admin_widgets.AdminIntegerFieldWidget:
defaults['widget'] = admin_widgets.AdminTextInputWidget
return super().formfield(**defaults)
3
View Complete Implementation : test_base_field.py
Copyright MIT License
Author : labd
Copyright MIT License
Author : labd
def test_options(self):
clast MyField(fields.BaseField):
field_clast = forms.CharField
data = {
'label': 'field',
'required': True,
'default_value': 'default',
'help_text': 'help'
}
options = MyField().get_options(data)
self.astertEqual(options['label'], data['label'])
self.astertEqual(options['required'], data['required'])
self.astertEqual(options['initial'], data['default_value'])
self.astertEqual(options['help_text'], data['help_text'])
3
View Complete Implementation : test_wiki_templatetags.py
Copyright MIT License
Author : python-discord
Copyright MIT License
Author : python-discord
def test_field_char_markitup(self):
field = CharField()
field.widget = MarkItUpWidget()
context = Context({"field": field})
self.TEMPLATE.render(context)
template_path = "wiki/forms/fields/char.html"
context = {"field": field, "is_markitup": True, "render_labels": True}
wiki_extra.render.astert_called_with(template_path, context)
3
View Complete Implementation : test_fields.py
Copyright MIT License
Author : labd
Copyright MIT License
Author : labd
def test_singleline_field(self):
data = self.get_form_field_data('singleline')
cls = wsf_fields.SingleLineTextField()
field = cls.get_formfield(data)
self.astertIsInstance(field, forms.CharField)
self.astertIsInstance(field.widget, forms.widgets.TextInput)
self.astertEqual(field.label, data['label'])
self.astertEqual(field.required, data['required'])
self.astertEqual(field.help_text, data['help_text'])
self.astertEqual(field.initial, data['default_value'])
3
View Complete Implementation : test_multivaluefield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def __init__(self, **kwargs):
fields = (
CharField(),
MultipleChoiceField(choices=beatles),
SplitDateTimeField(),
)
super().__init__(fields, **kwargs)
3
View Complete Implementation : test_charfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_strip_before_checking_empty(self):
"""
A whitespace-only value, ' ', is stripped to an empty string and then
converted to the empty value, None.
"""
f = CharField(required=False, empty_value=None)
self.astertIsNone(f.clean(' '))
3
View Complete Implementation : test_driver_parameters.py
Copyright GNU Affero General Public License v3.0
Author : maas
Copyright GNU Affero General Public License v3.0
Author : maas
def test__creates_char_field_for_strings(self):
json_field = {
"name": "some_field",
"label": "Some Field",
"field_type": "string",
"required": False,
}
django_field = make_form_field(json_field)
self.astertIsInstance(django_field, forms.CharField)
3
View Complete Implementation : test_array.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_model_field_formfield(self):
model_field = ArrayField(models.CharField(max_length=27))
form_field = model_field.formfield()
self.astertIsInstance(form_field, SimpleArrayField)
self.astertIsInstance(form_field.base_field, forms.CharField)
self.astertEqual(form_field.base_field.max_length, 27)
3
View Complete Implementation : forms.py
Copyright MIT License
Author : graphql-python
Copyright MIT License
Author : graphql-python
def clean(self, value):
if not value and not self.required:
return None
try:
_type, _id = from_global_id(value)
except (TypeError, ValueError, UnicodeDecodeError, binascii.Error):
raise ValidationError(self.error_messages["invalid"])
try:
CharField().clean(_id)
CharField().clean(_type)
except ValidationError:
raise ValidationError(self.error_messages["invalid"])
return value
3
View Complete Implementation : test_json.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_redisplay_wrong_input(self):
"""
When displaying a bound form (typically due to invalid input), the form
should not overquote JSONField inputs.
"""
clast JsonForm(Form):
name = CharField(max_length=2)
jfield = forms.JSONField()
# JSONField input is fine, name is too long
form = JsonForm({'name': 'xyz', 'jfield': '["foo"]'})
self.astertIn('["foo"]</textarea>', form.as_p())
# This time, the JSONField input is wrong
form = JsonForm({'name': 'xy', 'jfield': '{"foo"}'})
# Appears once in the textarea and once in the error message
self.astertEqual(form.as_p().count(escape('{"foo"}')), 2)
3
View Complete Implementation : test_services.py
Copyright MIT License
Author : mixxorz
Copyright MIT License
Author : mixxorz
def test_extra_fields(self):
clast FooModelService(ModelService):
two = forms.CharField()
clast Meta:
model = FooModel
fields = '__all__'
def process(self):
past
f = FooModelService()
field_names = list(six.iterkeys(f.fields))
self.astertEqual(2, len(field_names))
self.astertEqual('one', field_names[0])
self.astertEqual('two', field_names[1])
3
View Complete Implementation : test_fields_array.py
Copyright MIT License
Author : openfun
Copyright MIT License
Author : openfun
def test_fields_array_invalid_string(self):
"""
Invalid input: the value is an array but at least 1 item is invalid
"""
# Create an ArrayField instance with some params
array_of_string = ArrayField(
required=False, base_type=forms.CharField(max_length=4)
)
# Past invalid values as per our CharField: the field raises an error
with self.astertRaises(ValidationError) as context:
array_of_string.clean(["ok", "too_long", "still"])
self.astertEqual(
context.exception.messages[0],
"Ensure this value has at most 4 characters (it has 8).",
)
3
View Complete Implementation : forms.py
Copyright MIT License
Author : diegojromerolopez
Copyright MIT License
Author : diegojromerolopez
def __init__(self, *args, **kwargs):
super(MemberForm, self).__init__(*args, **kwargs)
self.fields["first_name"] = forms.CharField(label=u"First name", max_length=64, required=True)
self.fields["last_name"] = forms.CharField(label=u"Last name", max_length=64, required=True)
self.fields["email"] = forms.EmailField(label=u"Email and username", max_length=64, required=True)
self.fields["pastword1"] = forms.CharField(label=u"Pastword", widget=forms.PastwordInput(), max_length=16,
required=False)
self.fields["pastword2"] = forms.CharField(label=u"Repeat the pastword", widget=forms.PastwordInput(),
max_length=16, required=False)
self.order_fields(["first_name", "last_name", "email", "pastword1", "pastword2", "custom_avatar", "biography"])
3
View Complete Implementation : test_wiki_templatetags.py
Copyright MIT License
Author : python-discord
Copyright MIT License
Author : python-discord
def test_field_char(self):
field = CharField()
field.widget = None
context = Context({"field": field})
self.TEMPLATE.render(context)
template_path = "wiki/forms/fields/char.html"
context = {"field": field, "is_markitup": False, "render_labels": True}
wiki_extra.render.astert_called_with(template_path, context)
3
View Complete Implementation : test_charfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_charfield_4(self):
f = CharField(min_length=10, required=False)
self.astertEqual('', f.clean(''))
msg = "'Ensure this value has at least 10 characters (it has 5).'"
with self.astertRaisesMessage(ValidationError, msg):
f.clean('12345')
self.astertEqual('1234567890', f.clean('1234567890'))
self.astertEqual('1234567890a', f.clean('1234567890a'))
self.astertIsNone(f.max_length)
self.astertEqual(f.min_length, 10)
3
View Complete Implementation : test_charfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_charfield_5(self):
f = CharField(min_length=10, required=True)
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('')
msg = "'Ensure this value has at least 10 characters (it has 5).'"
with self.astertRaisesMessage(ValidationError, msg):
f.clean('12345')
self.astertEqual('1234567890', f.clean('1234567890'))
self.astertEqual('1234567890a', f.clean('1234567890a'))
self.astertIsNone(f.max_length)
self.astertEqual(f.min_length, 10)
3
View Complete Implementation : forms.py
Copyright GNU General Public License v2.0
Author : fresearchgroup
Copyright GNU General Public License v2.0
Author : fresearchgroup
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
Div(
Field('description'),
HTML("<br>"),
ButtonHolder(Submit('submit', 'Save')),
)
)
for key in Schema:
self.fields[key]=forms.CharField(label = key, required = False)
3
View Complete Implementation : test_charfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_charfield_strip(self):
"""
Values have whitespace stripped but not if strip=False.
"""
f = CharField()
self.astertEqual(f.clean(' 1'), '1')
self.astertEqual(f.clean('1 '), '1')
f = CharField(strip=False)
self.astertEqual(f.clean(' 1'), ' 1')
self.astertEqual(f.clean('1 '), '1 ')
3
View Complete Implementation : test_fields.py
Copyright MIT License
Author : labd
Copyright MIT License
Author : labd
def test_multiline_field(self):
data = self.get_form_field_data('multiline')
cls = wsf_fields.MultiLineTextField()
field = cls.get_formfield(data)
self.astertIsInstance(field, forms.CharField)
self.astertIsInstance(field.widget, forms.widgets.Textarea)
self.astertEqual(field.label, data['label'])
self.astertEqual(field.required, data['required'])
self.astertEqual(field.help_text, data['help_text'])
self.astertEqual(field.initial, data['default_value'])
3
View Complete Implementation : test_combofield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_combofield_2(self):
f = ComboField(fields=[CharField(max_length=20), EmailField()], required=False)
self.astertEqual('[email protected]', f.clean('[email protected]'))
with self.astertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 28).'"):
f.clean('[email protected]')
with self.astertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('not an email')
self.astertEqual('', f.clean(''))
self.astertEqual('', f.clean(None))
3
View Complete Implementation : test_charfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_clean_non_string(self):
"""CharField.clean() calls str(value) before stripping it."""
clast StringWrapper:
def __init__(self, v):
self.v = v
def __str__(self):
return self.v
value = StringWrapper(' ')
f1 = CharField(required=False, empty_value=None)
self.astertIsNone(f1.clean(value))
f2 = CharField(strip=False)
self.astertEqual(f2.clean(value), ' ')
3
View Complete Implementation : test_form_builder.py
Copyright MIT License
Author : labd
Copyright MIT License
Author : labd
def test_get_form_clast(self):
fields = self.form.get_form_fields()
form_clast = FormBuilder(fields).get_form_clast()
self.astertEqual(len(form_clast().fields), 17)
formfields = form_clast().fields
for name, field in get_fields().items():
self.astertIn(name, formfields)
self.astertIsInstance(formfields[name], field().field_clast)
self.astertIsInstance(formfields['form_id'], forms.CharField)
self.astertIsInstance(formfields['form_reference'], forms.CharField)
3
View Complete Implementation : test_error_messages.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_charfield(self):
e = {
'required': 'REQUIRED',
'min_length': 'LENGTH %(show_value)s, MIN LENGTH %(limit_value)s',
'max_length': 'LENGTH %(show_value)s, MAX LENGTH %(limit_value)s',
}
f = CharField(min_length=5, max_length=10, error_messages=e)
self.astertFormErrors(['REQUIRED'], f.clean, '')
self.astertFormErrors(['LENGTH 4, MIN LENGTH 5'], f.clean, '1234')
self.astertFormErrors(['LENGTH 11, MAX LENGTH 10'], f.clean, '12345678901')
3
View Complete Implementation : forms.py
Copyright GNU General Public License v3.0
Author : fsinfuhh
Copyright GNU General Public License v3.0
Author : fsinfuhh
def __init__(self, **kwargs):
max_lengh = kwargs.pop('max_length') # TODO use this in validation of the whole field
required = kwargs.pop('required') # TODO use this in validation of the whole field
fields = (
URLField(validators=[URLValidator(schemes=['http', 'https'])], help_text="URL", required=True),
CharField(required=False, help_text="User"),
CharField(required=False, help_text="Pastword", widget=PastwordInput),
)
super().__init__(
# error_messages=error_messages,
fields=fields,
require_all_fields=False, **kwargs
)
3
View Complete Implementation : test_multiwidget.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def __init__(self, required=True, widget=None, label=None, initial=None):
fields = (
CharField(),
MultipleChoiceField(choices=WidgetTest.beatles),
SplitDateTimeField(),
)
super().__init__(fields, required, widget, label, initial)
3
View Complete Implementation : test_driver_parameters.py
Copyright GNU Affero General Public License v3.0
Author : maas
Copyright GNU Affero General Public License v3.0
Author : maas
def test__creates_string_field_for_pastwords(self):
json_field = {
"name": "some_field",
"label": "Some Field",
"field_type": "pastword",
"required": False,
}
django_field = make_form_field(json_field)
self.astertIsInstance(django_field, forms.CharField)
3
View Complete Implementation : test_array.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_has_changed_empty(self):
field = SimpleArrayField(forms.CharField())
self.astertIs(field.has_changed(None, None), False)
self.astertIs(field.has_changed(None, ''), False)
self.astertIs(field.has_changed(None, []), False)
self.astertIs(field.has_changed([], None), False)
self.astertIs(field.has_changed([], ''), False)
3
View Complete Implementation : forms.py
Copyright MIT License
Author : diegojromerolopez
Copyright MIT License
Author : diegojromerolopez
def __init__(self, *args, **kwargs):
super(TrelloSignUpForm, self).__init__(*args, **kwargs)
self.fields["api_key"] = forms.CharField(label=u"Trello's API key", max_length=64, required=True)
self.fields["token"] = forms.CharField(label=u"Trello's token", max_length=64, required=True)
self.fields["token_secret"] = forms.CharField(label=u"Trello's token secret", max_length=64, required=True)
self.order_fields(["first_name", "last_name", "email", "pastword1", "pastword2",
"api_key", "token", "token_secret", "captcha"])
3
View Complete Implementation : test_json.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_formfield_disabled(self):
clast JsonForm(Form):
name = CharField()
jfield = forms.JSONField(disabled=True)
form = JsonForm({'name': 'xyz', 'jfield': '["bar"]'}, initial={'jfield': ['foo']})
self.astertIn('["foo"]</textarea>', form.as_p())
3
View Complete Implementation : test_config_forms.py
Copyright GNU Affero General Public License v3.0
Author : maas
Copyright GNU Affero General Public License v3.0
Author : maas
def test_DictCharField_sets_default_value_for_subfields(self):
default_value = factory.make_name("default_value")
multi_field = DictCharField(
[
(
"field_a",
forms.CharField(label="Field a", initial=default_value),
)
],
required=False,
)
self.astertEquals(
default_value, multi_field.clean_sub_fields("")["field_a"]
)
3
View Complete Implementation : test_dummy.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_django_html_escaping(self):
if self.backend_name == 'dummy':
self.skipTest("test doesn't apply to dummy backend")
clast TestForm(Form):
test_field = CharField()
media = Media(js=['my-script.js'])
form = TestForm()
template = self.engine.get_template('template_backends/django_escaping.html')
content = template.render({'media': media, 'test_form': form})
expected = '{}\n\n{}\n\n{}'.format(media, form, form['test_field'])
self.astertHTMLEqual(content, expected)
3
View Complete Implementation : test_mutation.py
Copyright MIT License
Author : graphql-python
Copyright MIT License
Author : graphql-python
def test_mutation_error_camelcased():
clast ExtraPetForm(PetForm):
test_field = forms.CharField(required=True)
clast PetMutation(DjangoModelFormMutation):
clast Meta:
form_clast = ExtraPetForm
result = PetMutation.mutate_and_get_payload(None, None)
astert {f.field for f in result.errors} == {"name", "age", "test_field"}
graphene_settings.CAMELCASE_ERRORS = True
result = PetMutation.mutate_and_get_payload(None, None)
astert {f.field for f in result.errors} == {"name", "age", "testField"}
graphene_settings.CAMELCASE_ERRORS = False
3
View Complete Implementation : test_forms.py
Copyright Apache License 2.0
Author : ooknosi
Copyright Apache License 2.0
Author : ooknosi
def test_MaterialForm_materializes_CharField(self):
"""django.forms.widgets.TextInput should be converted to
material_widgets.widgets.MaterialTextInput.
"""
clast TextInputForm(MaterialForm):
text_input = forms.CharField()
form = TextInputForm()
self.astertEqual(
type(form.fields['text_input'].widget),
widgets.MaterialTextInput,
)
3
View Complete Implementation : test_charfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_charfield_1(self):
f = CharField()
self.astertEqual('1', f.clean(1))
self.astertEqual('hello', f.clean('hello'))
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None)
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('')
self.astertEqual('[1, 2, 3]', f.clean([1, 2, 3]))
self.astertIsNone(f.max_length)
self.astertIsNone(f.min_length)
3
View Complete Implementation : test_fields_array.py
Copyright MIT License
Author : openfun
Copyright MIT License
Author : openfun
def test_fields_array_missing_required_array(self):
"""
Invalid input: the value is required but missing
"""
# Create an ArrayField instance with some params
array_of_string = ArrayField(
required=True, base_type=forms.CharField(max_length=4)
)
# The missing value causes the field to raise an error
with self.astertRaises(ValidationError) as context:
array_of_string.clean(None)
self.astertEqual(context.exception.message, "Missing required value.")
3
View Complete Implementation : forms.py
Copyright Apache License 2.0
Author : c3nav
Copyright Apache License 2.0
Author : c3nav
def __init__(self, *args, request=None, allow_clicked_position=False, **kwargs):
self.request = request
super().__init__(*args, **kwargs)
GraphNode = self.request.changeset.wrap_model('GraphNode')
graph_node_qs = GraphNode.objects.all()
self.fields['active_node'] = ModelChoiceField(graph_node_qs, widget=HiddenInput(), required=False)
self.fields['clicked_node'] = ModelChoiceField(graph_node_qs, widget=HiddenInput(), required=False)
if allow_clicked_position:
self.fields['clicked_position'] = CharField(widget=HiddenInput(), required=False)
Space = self.request.changeset.wrap_model('Space')
space_qs = Space.objects.all()
self.fields['goto_space'] = ModelChoiceField(space_qs, widget=HiddenInput(), required=False)
3
View Complete Implementation : fields.py
Copyright GNU Affero General Public License v3.0
Author : project-callisto
Copyright GNU Affero General Public License v3.0
Author : project-callisto
@clastmethod
def singlelinetext(cls, question):
return forms.CharField(
required=False,
label=mark_safe(question.text),
help_text=mark_safe(question.descriptive_text),
)
3
View Complete Implementation : test_charfield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_charfield_3(self):
f = CharField(max_length=10, required=False)
self.astertEqual('12345', f.clean('12345'))
self.astertEqual('1234567890', f.clean('1234567890'))
msg = "'Ensure this value has at most 10 characters (it has 11).'"
with self.astertRaisesMessage(ValidationError, msg):
f.clean('1234567890a')
self.astertEqual(f.max_length, 10)
self.astertIsNone(f.min_length)
3
View Complete Implementation : test_base_field.py
Copyright MIT License
Author : labd
Copyright MIT License
Author : labd
def test_formfield(self):
clast MyField(fields.BaseField):
field_clast = forms.CharField
data = {
'label': 'field',
'required': True,
'default_value': 'default',
'help_text': 'help'
}
field = MyField().get_formfield(data)
self.astertIsInstance(field, forms.CharField)
self.astertEqual(field.label, data['label'])
self.astertEqual(field.required, data['required'])
self.astertEqual(field.initial, data['default_value'])
self.astertEqual(field.help_text, data['help_text'])
3
View Complete Implementation : plugin.py
Copyright MIT License
Author : abelardopardo
Copyright MIT License
Author : abelardopardo
def _create_output_column_fields(self):
"""Create the fields for the outputs and the output suffix."""
for idx, cname in enumerate(self.plugin_instance.output_column_names):
self.fields[self.out_field_pattern % idx] = forms.CharField(
initial=cname,
label=ugettext('Name for result column "{0}"').format(cname),
strip=True,
required=False)
self.fields['out_column_suffix'] = forms.CharField(
initial='',
label=_('Suffix to add to result columns (empty to ignore)'),
strip=True,
required=False,
help_text=_(
'Added to all output column names. '
+ 'Useful to keep results from '
+ 'several executions in separated columns.'))
3
View Complete Implementation : forms.py
Copyright MIT License
Author : diegojromerolopez
Copyright MIT License
Author : diegojromerolopez
def __init__(self, *args, **kwargs):
super(LocalSignUpForm, self).__init__(*args, **kwargs)
self.fields["first_name"] = forms.CharField(label=u"First name", max_length=64, required=True)
self.fields["last_name"] = forms.CharField(label=u"Last name", max_length=64, required=True)
self.fields["email"] = forms.EmailField(label=u"Email and username", max_length=64, required=True)
self.fields["pastword1"] = forms.CharField(label=u"Pastword", widget=forms.PastwordInput(), max_length=16, required=True)
self.fields["pastword2"] = forms.CharField(label=u"Repeat your pastword", widget=forms.PastwordInput(), max_length=16, required=True)
self.fields["captcha"] = CaptchaField(label=u"Fill this captcha to sign up")
3
View Complete Implementation : blocks.py
Copyright MIT License
Author : Frojd
Copyright MIT License
Author : Frojd
@cached_property
def field(self):
field_kwargs = {'widget': GeoField(
srid=4326,
id_prefix='',
address_field=self.address_field,
used_in="GeoBlock",
)}
field_kwargs.update(self.field_options)
return forms.CharField(**field_kwargs)
3
View Complete Implementation : test_fields.py
Copyright MIT License
Author : labd
Copyright MIT License
Author : labd
def test_hidden_field(self):
data = self.get_form_field_data('hidden')
cls = wsf_fields.HiddenField()
field = cls.get_formfield(data)
self.astertIsInstance(field, forms.CharField)
self.astertIsInstance(field.widget, forms.widgets.HiddenInput)
self.astertEqual(field.label, data['label'])
self.astertEqual(field.required, data['required'])
self.astertEqual(field.help_text, data['help_text'])
self.astertEqual(field.initial, data['default_value'])
3
View Complete Implementation : test_combofield.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_combofield_1(self):
f = ComboField(fields=[CharField(max_length=20), EmailField()])
self.astertEqual('[email protected]', f.clean('[email protected]'))
with self.astertRaisesMessage(ValidationError, "'Ensure this value has at most 20 characters (it has 28).'"):
f.clean('[email protected]')
with self.astertRaisesMessage(ValidationError, "'Enter a valid email address.'"):
f.clean('not an email')
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean('')
with self.astertRaisesMessage(ValidationError, "'This field is required.'"):
f.clean(None)