Skip to content

Commit 8a0daec

Browse files
committed
operate on str instead of field.data
1 parent 54772cf commit 8a0daec

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

qiita_pet/handlers/user_handlers.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525

2626
class UserProfile(Form):
27-
def validate_general(field: StringField, infomsg: str, url_prefix: str):
27+
def validate_general(value: str, infomsg: str, url_prefix: str):
2828
"""Validate basic user inputs, i.e. check for leading/trailing
2929
whitespaces and leading URL prefix, like http://scholar.google.com/
3030
3131
Parameters
3232
----------
33-
field : wtforms.StringField
34-
The WTform user input field.
33+
value : str
34+
The WTform user input string.
3535
infomsg : str
3636
An error message to inform the user how to extract the correct
3737
value.
@@ -48,8 +48,7 @@ def validate_general(field: StringField, infomsg: str, url_prefix: str):
4848
a) input has leading or trailing whitespaces
4949
b) input starts with the given url_prefix
5050
"""
51-
value = field.data
52-
if value == "":
51+
if (value is None) or (value == ""):
5352
# nothing to complain, as input is empty
5453
return None
5554

@@ -58,11 +57,12 @@ def validate_general(field: StringField, infomsg: str, url_prefix: str):
5857
'Please remove all leading and trailing whitespaces from your '
5958
'input.<br/>%s' % infomsg)
6059

61-
isPrefix = re.search("^%s" % url_prefix, value)
62-
if isPrefix is not None:
63-
raise ValidationError(
64-
'Please remove the "%s" part from your input.<br/>%s' % (
65-
isPrefix[0], infomsg))
60+
if len(url_prefix) > 0:
61+
isPrefix = re.search("^%s" % url_prefix, value)
62+
if isPrefix is not None:
63+
raise ValidationError(
64+
'Please remove the "%s" part from your input.<br/>%s' % (
65+
isPrefix[0], infomsg))
6666

6767
# if there is still no error raised, we return the actual value of the
6868
# user input
@@ -90,7 +90,7 @@ def validator_orcid_id(form: Form, field: StringField):
9090
' every four digits are separated with a dash "-". An '
9191
'example is: 0000-0002-0975-9019')
9292
value = UserProfile.validate_general(
93-
field, infomsg, 'https://orcid.org')
93+
field.data, infomsg, 'https://orcid.org')
9494
if value is None:
9595
return True
9696

@@ -129,7 +129,7 @@ def validator_gscholar_id(form, field):
129129
# we need a regex here, since we don't know the TLD the user is
130130
# presenting to us
131131
value = UserProfile.validate_general(
132-
field, infomsg, r'https://scholar.google.\w{1,3}/citations\?')
132+
field.data, infomsg, r'https://scholar.google.\w{1,3}/citations\?')
133133
if value is None:
134134
return True
135135

@@ -171,7 +171,7 @@ def validator_rgate_id(form, field):
171171
'Your ID is the part right of the last "/", in the example:'
172172
' "Rob-Knight"')
173173
value = UserProfile.validate_general(
174-
field, infomsg, 'https://www.researchgate.net/profile/')
174+
field.data, infomsg, 'https://www.researchgate.net/profile/')
175175
if value is None:
176176
return True
177177

0 commit comments

Comments
 (0)