Coverage for portality/forms/fields.py: 78%
32 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-20 16:12 +0100
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-20 16:12 +0100
1from wtforms import Field, SelectField, FormField, RadioField
2from wtforms import widgets
5class DOAJSelectField(SelectField):
6 def __init__(self, *args, **kwargs):
7 if 'default' not in kwargs:
8 kwargs['default'] = ''
9 super(DOAJSelectField, self).__init__(*args, **kwargs)
12class TagListField(Field):
13 widget = widgets.TextInput()
15 def _value(self):
16 if self.data:
17 return ', '.join(self.data)
18 else:
19 return ''
21 def get_list(self):
22 return self.data
24 def process_formdata(self, valuelist):
25 if valuelist:
26 self.data = []
27 for v in valuelist:
28 self.data += [c for c in [x.strip() for x in v.split(",") if x]]
29 else:
30 self.data = []
33class NestedFormField(FormField):
34 def validate(self, form, extra_validators=tuple()):
35 self.form.meta.parent_form = form
36 return super().validate(form, extra_validators)
39class UnconstrainedRadioField(RadioField):
40 def pre_validate(self, form):
41 return
43 def process_data(self, value):
44 if value:
45 super(UnconstrainedRadioField, self).process_data(value)
46 else:
47 self.data = None