Implement new Profanity Checker on Form Validation

Why am I still up doing this at 3am
This commit is contained in:
Xevion
2022-03-29 03:00:12 -05:00
parent 820ecf3d74
commit 8cf2f02772
2 changed files with 23 additions and 5 deletions

16
validators.py Normal file
View File

@@ -0,0 +1,16 @@
from typing import Optional
from profanity_filter import ProfanityFilter
from wtforms.validators import ValidationError
pf = ProfanityFilter()
class NoProfanity(object):
def __init__(self, message: Optional[str] = None):
if not message:
message = 'Profanity is not acceptable on Runnerspace'
self.message = message
def __call__(self, form, field):
if pf.is_profane(field.data):
raise ValidationError(self.message)