This repository has been archived by the owner on Apr 13, 2019. It is now read-only.
/
forms.py
49 lines (40 loc) · 1.67 KB
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from flaskext.wtf import Form
from flaskext.wtf import TextField
from flaskext.wtf import TextAreaField
from flaskext.wtf import Required
from flaskext.wtf import Length
from flaskext.wtf import BooleanField
from flaskext.wtf import HiddenField
from helpers import slugify
class TopicForm(Form):
body = TextAreaField('Body', [Required()])
excerpt = TextAreaField('Excerpt', [Required()])
meta_description = TextAreaField('Meta Description')
category = TextField('Category', [Required()])
name = TextField('Name', [Required()])
published = BooleanField('Published')
login_required = BooleanField('Login Required')
system = HiddenField()
def __init__(self, *args, **kwargs):
kwargs['csrf_enabled'] = False
super(TopicForm, self).__init__(*args, **kwargs)
def validate_category(form, field):
return slugify(field.data)
class SystemForm(Form):
name = TextField('Name', [Required()])
description = TextAreaField('Description', [Required()])
meta_description = TextAreaField('Meta Description', [Required(), Length(min=90, max=170)])
icon_url = TextField('Icon URL')
def __init__(self, *args, **kwargs):
kwargs['csrf_enabled'] = False
super(SystemForm, self).__init__(*args, **kwargs)
# def validate_icon_url(form, field):
# if field.data:
# print 'herefasdfasd'
# import urllib2
# try:
# req = urllib2.Request(field.data, None, None)
# urllib2.urlopen(req)
# except Exception, e:
# logging.info("exception %s" % e)
# raise ValidationError('Invalid URL')