4
4
5
5
import croniter
6
6
from profanity_check import predict as is_profane
7
+ from profanity_check import predict_prob as how_profane
7
8
8
9
from django .conf import settings
9
10
from django .contrib .auth import get_user_model
24
25
25
26
26
27
def validate_profanity (value ):
28
+ logger .debug (f"Validating profanity for value: { value } " )
27
29
if is_profane ([value ])[0 ] == 1 :
30
+ logger .debug ("Profanity detected!" )
28
31
raise ValidationError ("Profanity is not allowed" )
32
+ logger .debug (f"Value { value } is OK - profanity score: { how_profane ([value ])[0 ]} " )
29
33
30
34
31
35
class Household (models .Model ):
@@ -332,7 +336,7 @@ class ScheduledTaskSerializer(serializers.ModelSerializer):
332
336
next_due = serializers .SerializerMethodField ()
333
337
last_due = serializers .SerializerMethodField ()
334
338
mean_completion_time = serializers .SerializerMethodField ()
335
- description = serializers .CharField (required = False , allow_blank = True )
339
+ description = serializers .CharField (required = False , allow_blank = True , validators = [ validate_profanity ] )
336
340
337
341
class Meta :
338
342
model = ScheduledTask
@@ -354,7 +358,7 @@ def get_mean_completion_time(self, obj):
354
358
class FlexibleTaskSerializer (serializers .ModelSerializer ):
355
359
staleness = serializers .SerializerMethodField ()
356
360
mean_completion_time = serializers .SerializerMethodField ()
357
- description = serializers .CharField (required = False , allow_blank = True )
361
+ description = serializers .CharField (required = False , allow_blank = True , validators = [ validate_profanity ] )
358
362
359
363
class Meta :
360
364
model = FlexibleTask
@@ -484,7 +488,7 @@ class Meta:
484
488
485
489
class CreateHouseholdSerializer (serializers .ModelSerializer ):
486
490
name = serializers .CharField (
487
- max_length = 255 , validators = [UniqueValidator (queryset = Household .objects .all ())]
491
+ max_length = 255 , validators = [UniqueValidator (queryset = Household .objects .all ()), validate_profanity ]
488
492
)
489
493
490
494
class Meta :
0 commit comments