##// END OF EJS Templates
Added '-' to invalid tag characters because it causes problems.
neko259 -
r51:24368e91 default
parent child Browse files
Show More
@@ -1,62 +1,62 b''
1 1 from django import forms
2 2 from neboard import settings
3 3
4 4
5 5 class PostForm(forms.Form):
6 6 MAX_TEXT_LENGTH = 10000
7 7 MAX_IMAGE_SIZE = 8 * 1024 * 1024
8 8
9 9 title = forms.CharField(max_length=50, required=False)
10 10 text = forms.CharField(widget=forms.Textarea, required=False)
11 11 image = forms.ImageField(required=False)
12 12
13 13 def clean_text(self):
14 14 text = self.cleaned_data['text']
15 15 if text:
16 16 if len(text) > self.MAX_TEXT_LENGTH:
17 17 raise forms.ValidationError('Too many text')
18 18 return text
19 19
20 20 def clean_image(self):
21 21 image = self.cleaned_data['image']
22 22 if image:
23 23 if image._size > self.MAX_IMAGE_SIZE:
24 24 raise forms.ValidationError('Too large image: more than ' +
25 25 str(self.MAX_IMAGE_SIZE) + ' bytes')
26 26 return image
27 27
28 28 def clean(self):
29 29 cleaned_data = super(PostForm, self).clean()
30 30
31 31 text = cleaned_data.get('text')
32 32 image = cleaned_data.get('image')
33 33
34 34 if (not text) and (not image):
35 35 raise forms.ValidationError('Enter either text or image')
36 36
37 37 return cleaned_data
38 38
39 39
40 40 class ThreadForm(PostForm):
41 INVALID_TAG_CHARACTERS = ['+', '/', '&', '=', '?']
41 INVALID_TAG_CHARACTERS = ['+', '/', '&', '=', '?', '-']
42 42
43 43 tags = forms.CharField(max_length=100)
44 44
45 45 def clean_tags(self):
46 46 tags = self.cleaned_data['tags']
47 47 if tags:
48 48 for character in tags:
49 49 if character in self.INVALID_TAG_CHARACTERS:
50 50 raise forms.ValidationError(
51 51 'Inappropriate characters in tags')
52 52
53 53 return tags
54 54
55 55 def clean(self):
56 56 cleaned_data = super(ThreadForm, self).clean()
57 57
58 58 return cleaned_data
59 59
60 60
61 61 class SettingsForm(forms.Form):
62 62 theme = forms.ChoiceField(choices=settings.THEMES, widget=forms.RadioSelect) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now