summaryrefslogtreecommitdiffstats
path: root/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'forms.py')
-rw-r--r--forms.py88
1 files changed, 57 insertions, 31 deletions
diff --git a/forms.py b/forms.py
index 969ea73..9a2ea85 100644
--- a/forms.py
+++ b/forms.py
@@ -1,43 +1,57 @@
-from wtforms import HiddenField, PasswordField, validators, ValidationError
-from wtfpeewee.orm import model_form, ModelConverter
from flask.ext.wtf import Form
-from utils import Unique, ReadonlyField
+from wtforms import StringField, HiddenField, PasswordField, BooleanField, \
+ validators, ValidationError
+from wtforms.ext.sqlalchemy.orm import model_form, ModelConverter
+
+from app import db
from models import Group, Pad
-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.')]
+from utils.forms import Unique, ReadonlyField, RedirectMixin
+from utils.widgets import TextArea
+
+
+CreateGroup = model_form(
+ Group, base_class=Form, only=['name', 'description', 'public', 'browsable'],
+ 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)},
+ 'public': {'validators': []},
+ 'browsable': {'validators': []},
},
- 'description': {'widget': TextArea(rows=7)}})
+ db_session=db.session)
-ChangeGroup = model_form(Group, base_class=Form, exclude=['api_id'], field_args={
- 'description': {'widget': TextArea(rows=7)}},
- converter=ModelConverter(overrides={'name': ReadonlyField}))
+ChangeGroup = model_form(
+ Group, base_class=Form, only=['name', 'description', 'public', 'browsable'],
+ field_args={
+ 'description': {'widget': TextArea(rows=7)},
+ 'public': {'validators': []},
+ 'browsable': {'validators': []},
+ },
+ converter=ModelConverter({'name': ReadonlyField}),
+ db_session=db.session)
_CreatePad = model_form(
- Pad, base_class=Form, exclude=['api_id', 'created', 'group'], field_args={
+ Pad, base_class=Form, exclude=['api_id', 'created', 'group'],
+ field_args={
'name': {'validators': [
validators.Required(),
validators.Regexp('^[a-zA-Z1-9_-]+$', message=u'Invalid pad name '
'(only simple characters, numbers, - and _).'),
validators.Regexp('^[a-zA-Z1-9]', message=u'Pad name should not '
- 'start with a special character.')]}},
- converter=ModelConverter(overrides={'password': PasswordField}))
-
-
-ChangePad = model_form(
- Pad, base_class=Form, exclude=['api_id', 'created', 'group'],
- converter=ModelConverter(overrides={'password': PasswordField, 'name': ReadonlyField}))
+ 'start with a special character.')]},
+ 'public': {'validators': []},
+ },
+ converter=ModelConverter({'password': PasswordField}),
+ db_session=db.session)
class CreatePad(_CreatePad):
@@ -47,13 +61,25 @@ class CreatePad(_CreatePad):
def validate_name(self, field):
if self.group is not None:
- try:
- Pad.get(Pad.name == field.data, Pad.group == self.group)
+ pad_query = Pad.query.filter_by(name=field.data, group=self.group)
+ if pad_query.count() > 0:
raise ValidationError(u'A pad with this name already '
'exists in this group.')
- except Pad.DoesNotExist:
- pass
+ChangePad = model_form(
+ Pad, base_class=Form, exclude=['api_id', 'created', 'group'],
+ field_args={
+ 'public': {'validators': []},
+ },
+ converter=ModelConverter({'password': PasswordField,
+ 'name': ReadonlyField}),
+ db_session=db.session)
+
+
+class LoginForm(RedirectMixin, Form):
+ user = StringField('login', [validators.Required()])
+ password = PasswordField('password', [validators.Required()])
+
class DeleteForm(Form):
sure = HiddenField('are you sure', default='yes')