fix: profanity detector

This commit is contained in:
Gerard Gascón 2025-04-23 16:00:09 +02:00
parent 0dc6a34832
commit e97e204a5e
3 changed files with 14 additions and 2 deletions

View file

@ -1,5 +1,7 @@
asgiref==3.8.1 asgiref==3.8.1
Django==5.1.7 Django==5.1.7
django-profanity-filter==0.2.1
inflection==0.5.1
python-dotenv==1.0.1
sqlparse==0.5.3 sqlparse==0.5.3
tzdata==2025.2 tzdata==2025.2
python-dotenv==1.0.1

View file

@ -1,6 +1,7 @@
import json import json
import random import random
import profanity.templatetags.profanity
from django.db import IntegrityError from django.db import IntegrityError
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
@ -15,6 +16,14 @@ def add(request, origin, name, color, shirt, hat, decor):
hat = int(hat.strip()) hat = int(hat.strip())
decor = int(decor.strip()) decor = int(decor.strip())
if profanity.templatetags.profanity.is_profane(name):
print("profanity detected")
return HttpResponse("profanity detected")
if profanity.templatetags.profanity.is_profane(origin):
print("profanity detected")
return HttpResponse("profanity detected")
try: try:
dragon = Dragon.objects.create(origin=origin, name=name, color=color, shirt=shirt, hat=hat, decor=decor) dragon = Dragon.objects.create(origin=origin, name=name, color=color, shirt=shirt, hat=hat, decor=decor)
print(f'Received dragon ({dragon})') print(f'Received dragon ({dragon})')

View file

@ -46,7 +46,8 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'server' 'server',
'profanity'
] ]
MIDDLEWARE = [ MIDDLEWARE = [