Remove unused form fields
This commit is contained in:
parent
b778942dd7
commit
f614a3ff83
@ -1,29 +1,4 @@
|
|||||||
from wtforms.fields import Field, FormField, StringField, SelectField as SelectField_
|
from wtforms.fields import FormField, SelectField as SelectField_
|
||||||
from wtforms.widgets import TextArea
|
|
||||||
|
|
||||||
|
|
||||||
class NewlineListField(Field):
|
|
||||||
widget = TextArea()
|
|
||||||
|
|
||||||
def _value(self):
|
|
||||||
if isinstance(self.data, list):
|
|
||||||
return "\n".join(self.data)
|
|
||||||
elif self.data:
|
|
||||||
return self.data
|
|
||||||
else:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
def process_formdata(self, valuelist):
|
|
||||||
if valuelist:
|
|
||||||
self.data = [l.strip() for l in valuelist[0].split("\n") if l]
|
|
||||||
else:
|
|
||||||
self.data = []
|
|
||||||
|
|
||||||
def process_data(self, value):
|
|
||||||
if isinstance(value, list):
|
|
||||||
self.data = "\n".join(value)
|
|
||||||
else:
|
|
||||||
self.data = value
|
|
||||||
|
|
||||||
|
|
||||||
class SelectField(SelectField_):
|
class SelectField(SelectField_):
|
||||||
@ -33,14 +8,6 @@ class SelectField(SelectField_):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class NumberStringField(StringField):
|
|
||||||
def process_data(self, value):
|
|
||||||
if isinstance(value, int):
|
|
||||||
self.data = str(value)
|
|
||||||
else:
|
|
||||||
self.data = value
|
|
||||||
|
|
||||||
|
|
||||||
class FormFieldWrapper(FormField):
|
class FormFieldWrapper(FormField):
|
||||||
def has_changes(self):
|
def has_changes(self):
|
||||||
if not self.object_data:
|
if not self.object_data:
|
||||||
|
@ -4,41 +4,7 @@ from wtforms.fields import StringField
|
|||||||
import pendulum
|
import pendulum
|
||||||
from werkzeug.datastructures import ImmutableMultiDict
|
from werkzeug.datastructures import ImmutableMultiDict
|
||||||
|
|
||||||
from atst.forms.fields import NewlineListField, FormFieldWrapper
|
from atst.forms.fields import FormFieldWrapper
|
||||||
|
|
||||||
|
|
||||||
class NewlineListForm(Form):
|
|
||||||
newline_list = NewlineListField()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"input_,expected",
|
|
||||||
[
|
|
||||||
("", []),
|
|
||||||
("hello", ["hello"]),
|
|
||||||
("hello\n", ["hello"]),
|
|
||||||
("hello\nworld", ["hello", "world"]),
|
|
||||||
("hello\nworld\n", ["hello", "world"]),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_newline_list_process(input_, expected):
|
|
||||||
form_data = ImmutableMultiDict({"newline_list": input_})
|
|
||||||
form = NewlineListForm(form_data)
|
|
||||||
|
|
||||||
assert form.validate()
|
|
||||||
assert form.data == {"newline_list": expected}
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"input_,expected",
|
|
||||||
[([], ""), (["hello"], "hello"), (["hello", "world"], "hello\nworld")],
|
|
||||||
)
|
|
||||||
def test_newline_list_value(input_, expected):
|
|
||||||
form_data = {"newline_list": input_}
|
|
||||||
form = NewlineListForm(data=form_data)
|
|
||||||
|
|
||||||
assert form.validate()
|
|
||||||
assert form.newline_list._value() == expected
|
|
||||||
|
|
||||||
|
|
||||||
class PersonForm(Form):
|
class PersonForm(Form):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user