From 3a60d1dad8c2e0a31f14425bd5eb0d466acc2022 Mon Sep 17 00:00:00 2001 From: Gustavo Date: Thu, 20 Apr 2017 00:10:16 -0300 Subject: [PATCH] Included news content validation --- news/forms.py | 11 +++++++++++ 1 file changed, 11 insertions(+), 0 deletions(-) diff --git a/news/forms.py b/news/forms.py index 895aa57..02ded06 100644 --- a/news/forms.py +++ b/news/forms.py @@ -7,6 +7,7 @@ from os.path import join from PIL import Image import os from amadeus import settings +from django.utils.html import strip_tags class NewsForm(forms.ModelForm): MAX_UPLOAD_SIZE = 5*1024*1024 @@ -78,3 +79,13 @@ class NewsForm(forms.ModelForm): return ValueError return image + def clean_content(self): + content = self.cleaned_data.get('content', '') + cleaned_content = strip_tags(content) + + if cleaned_content == '': + self._errors['content'] = [_('This field is required.')] + + return ValueError + + return content -- libgit2 0.21.2