##// END OF EJS Templates
Merged with the old validation changes.
Merged with the old validation changes.

File last commit:

r75:bb74538a merge default
r75:bb74538a merge default
Show More
forms.py
61 lines | 1.7 KiB | text/x-python | PythonLexer
neko259
Added a regex for validation of tags. This refs #10
r69 import re
Ilyas
Added creating new thread form...
r14 from django import forms
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 from neboard import settings
Ilyas
Added creating new thread form...
r14
neko259
Added a text area to the posting form. Added a basic CSS style. Changed threads list a bit.
r16
neko259
Implemented form validation. When the form fails validation, showing the index page.
r29 class PostForm(forms.Form):
MAX_TEXT_LENGTH = 10000
MAX_IMAGE_SIZE = 8 * 1024 * 1024
title = forms.CharField(max_length=50, required=False)
text = forms.CharField(widget=forms.Textarea, required=False)
Ilyas
Added checkinf form fields when creating a new thread.
r18 image = forms.ImageField(required=False)
neko259
Implemented form validation. When the form fails validation, showing the index page.
r29
def clean_text(self):
text = self.cleaned_data['text']
if text:
if len(text) > self.MAX_TEXT_LENGTH:
raise forms.ValidationError('Too many text')
return text
def clean_image(self):
image = self.cleaned_data['image']
if image:
if image._size > self.MAX_IMAGE_SIZE:
raise forms.ValidationError('Too large image: more than ' +
str(self.MAX_IMAGE_SIZE) + ' bytes')
return image
def clean(self):
cleaned_data = super(PostForm, self).clean()
text = cleaned_data.get('text')
image = cleaned_data.get('image')
if (not text) and (not image):
raise forms.ValidationError('Enter either text or image')
return cleaned_data
class ThreadForm(PostForm):
neko259
Fixed unicode tags validation. Moved constants from classes to modules. Added error 404 when trying to get the non-existent thread. This fixes #19
r71 regex_tags = re.compile(ur'^[\w\s\d]+$', re.UNICODE)
Ilyas
Added creating new thread form...
r14 tags = forms.CharField(max_length=100)
neko259
Changed metadata design. Make space split tags.
r31
def clean_tags(self):
tags = self.cleaned_data['tags']
neko259
Added a regex for validation of tags. This refs #10
r69
neko259
Changed metadata design. Make space split tags.
r31 if tags:
neko259
Added a regex for validation of tags. This refs #10
r69 if not self.regex_tags.match(tags):
raise forms.ValidationError(
'Inappropriate characters in tags')
neko259
Changed metadata design. Make space split tags.
r31
return tags
def clean(self):
cleaned_data = super(ThreadForm, self).clean()
neko259
Added themes support. Added 'snow white' theme by Mystra_x64.
r35 return cleaned_data
class SettingsForm(forms.Form):
theme = forms.ChoiceField(choices=settings.THEMES, widget=forms.RadioSelect)