summaryrefslogtreecommitdiffstats
path: root/forms.py
blob: ef8ab651f2aae1091834a36c4b08bc4694fd19af (plain)
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
from wtforms import HiddenField, validators
from models import Group
from wtfpeewee.orm import model_form, ModelConverter
from flask.ext.wtf import Form
from utils import Unique, ReadonlyField
from widgets import TextArea


CreateGroup = model_form(Group, base_class=Form, exclude=['api_id'], field_args={
    'name': {'validators': [
        validators.Required(),
        validators.Regexp('^[a-zA-Z1-9_-]+$', message=u'Invalid group name '
            '(only simple characters, numbers, - and _).'),
        validators.Regexp('^[a-zA-Z1-9]', message=u'Group name should not '
            'start with a special character.'),
        Unique(Group, Group.name, message=u'A group with this name '
            'already exists.')]
    },
    'description': {'widget': TextArea(rows=7)}})


ChangeGroup = model_form(Group, base_class=Form, exclude=['api_id'], field_args={
    'description': {'widget': TextArea(rows=7)}},
    converter=ModelConverter(overrides={'name': ReadonlyField}))


class DeleteGroup(Form):
    id = HiddenField('group id', [validators.Required()]);
    sure = HiddenField('are you sure');