Commit 3a60d1dad8c2e0a31f14425bd5eb0d466acc2022
1 parent
0e9ec36b
Exists in
master
and in
2 other branches
Included news content validation
Showing
1 changed file
with
11 additions
and
0 deletions
Show diff stats
news/forms.py
... | ... | @@ -7,6 +7,7 @@ from os.path import join |
7 | 7 | from PIL import Image |
8 | 8 | import os |
9 | 9 | from amadeus import settings |
10 | +from django.utils.html import strip_tags | |
10 | 11 | |
11 | 12 | class NewsForm(forms.ModelForm): |
12 | 13 | MAX_UPLOAD_SIZE = 5*1024*1024 |
... | ... | @@ -78,3 +79,13 @@ class NewsForm(forms.ModelForm): |
78 | 79 | return ValueError |
79 | 80 | |
80 | 81 | return image |
82 | + def clean_content(self): | |
83 | + content = self.cleaned_data.get('content', '') | |
84 | + cleaned_content = strip_tags(content) | |
85 | + | |
86 | + if cleaned_content == '': | |
87 | + self._errors['content'] = [_('This field is required.')] | |
88 | + | |
89 | + return ValueError | |
90 | + | |
91 | + return content | ... | ... |