Skip to content

Commit

Permalink
Added forbidden words to validation error to help users fix validatio…
Browse files Browse the repository at this point in the history
…n errors.
  • Loading branch information
shirblc committed Sep 19, 2020
1 parent f8a8386 commit b6ebe7b
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,14 @@ def add_post(token_payload):
# If there's a blacklisted word / phrase, alert the user
else:
num_issues = len(blacklist_check['indexes'])
forbidden_words = ''.join([str(word['badword']) + ', ' for word in blacklist_check['indexes']])
raise ValidationError({
'code': 400,
'description': 'Your text contains ' + str(num_issues) + ' \
forbidden term(s). Please fix your post\'s \
forbidden term(s). The following word(s) is/ \
are not allowed: ' +
forbidden_words[0:-2]
+ '. Please fix your post\'s \
text and try again.'
}, 400)

Expand Down Expand Up @@ -295,11 +299,15 @@ def edit_post(token_payload, post_id):
# If there's a blacklisted word / phrase, alert the user
else:
num_issues = len(blacklist_check['indexes'])
forbidden_words = ''.join([str(word['badword']) + ', ' for word in blacklist_check['indexes']])
raise ValidationError({
'code': 400,
'description': 'Your text contains ' +
str(num_issues) + ' forbidden \
term(s). Please fix your post\'s \
term(s). The following word(s) is/ \
are not allowed: ' +
forbidden_words[0:-2]
+ '. Please fix your post\'s \
text and try again.'
}, 400)
# Otherwise, the user is allowed to edit any post, and thus text
Expand All @@ -318,11 +326,15 @@ def edit_post(token_payload, post_id):
# If there's a blacklisted word / phrase, alert the user
else:
num_issues = len(blacklist_check['indexes'])
forbidden_words = ''.join([str(word['badword']) + ', ' for word in blacklist_check['indexes']])
raise ValidationError({
'code': 400,
'description': 'Your text contains ' +
str(num_issues) + ' forbidden \
term(s). Please fix your post\'s \
term(s). The following word(s) is/ \
are not allowed: ' +
forbidden_words[0:-2]
+ '. Please fix your post\'s \
text and try again.'
}, 400)

Expand Down Expand Up @@ -1020,10 +1032,14 @@ def add_message(token_payload):
# If there's a blacklisted word / phrase, alert the user
if(blacklist_check['blacklisted'] is True):
num_issues = len(blacklist_check['indexes'])
forbidden_words = ''.join([str(word['badword']) + ', ' for word in blacklist_check['indexes']])
raise ValidationError({
'code': 400,
'description': 'Your message contains ' + str(num_issues) + ' \
forbidden term(s). Please fix your post\'s \
forbidden term(s). The following word(s) is/ \
are not allowed: ' +
forbidden_words[0:-2]
+ '. Please fix your post\'s \
text and try again.'
}, 400)

Expand Down

0 comments on commit b6ebe7b

Please sign in to comment.