From bdb756fdc7e8391a786cf9e896ac78400b2d925e Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 18 Nov 2014 05:45:16 +0100 Subject: forms: use models_form from wtfpeewee for CreateGroup --- forms.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/forms.py b/forms.py index a2c36fb..1944eaa 100644 --- a/forms.py +++ b/forms.py @@ -1,17 +1,19 @@ -from wtforms import Form, BooleanField, TextField, HiddenField, validators +from wtforms import From, HiddenField, validators from utils import Unique from models import Group +from wtfpeewee.orm import model_form -class CreateGroup(Form): - name = TextField('group name', [ + +CreateGroup = model_form(Group, 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.')]) - public = BooleanField('public') + 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.')]}}) + class DeleteGroup(Form): id = HiddenField('group id', [validators.Required()]); -- cgit v1.2.3-1-g7c22