/
forms.py
78 lines (60 loc) · 2.2 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Forms
~~~~~
"""
from flask_wtf import Form
from wtforms import BooleanField
from wtforms import PasswordField
from wtforms import TextAreaField
from wtforms import TextField
from wtforms.validators import InputRequired
from wtforms.validators import ValidationError
from wiki.core import clean_url
from wiki.web import current_users
from wiki.web import current_wiki
class URLForm(Form):
url = TextField('', [InputRequired()])
def validate_url(form, field):
if current_wiki.exists(field.data):
raise ValidationError('The URL "%s" exists already.' % field.data)
def clean_url(self, url):
return clean_url(url)
class SearchForm(Form):
term = TextField('', [InputRequired()])
ignore_case = BooleanField(
description='Ignore Case',
# FIXME: default is not correctly populated
default=True)
class EditorForm(Form):
title = TextField('', [InputRequired()])
body = TextAreaField('', [InputRequired()])
tags = TextField('')
class LoginForm(Form):
name = TextField('', [InputRequired()])
password = PasswordField('', [InputRequired()])
def validate_name(form, field):
user = current_users.get_user(field.data)
if not user:
raise ValidationError('This username does not exist.')
def validate_password(form, field):
user = current_users.get_user(form.name.data)
if not user:
return
if not user.check_password(field.data):
raise ValidationError('Username and password do not match.')
class RegisterForm(Form):
#username = TextField('', [InputRequired()])
name = TextField('', [InputRequired()])
password = PasswordField('', [InputRequired()])
fullName = TextField('', [InputRequired()])
email = TextField('', [InputRequired()])
def validate_name(form, field):
user = current_users.get_user(field.data)
if user:
raise ValidationError('This username exists')
class UnregisterForm(Form):
name = TextField('', [InputRequired()])
def validate_name(form, field):
user = current_users.get_user(field.data)
if not user:
raise ValidationError('This username does not exist.')