diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2016-02-02 23:15:37 +0100 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2016-02-02 23:15:37 +0100 |
commit | 082bf39a7dd7296d4f51b6b124d185135dc00989 (patch) | |
tree | 6e12cf2b67b016aff38874c389b5bf8b5242749a /src/web/forms.py | |
parent | fixing logging (diff) | |
parent | reload and fold all button (diff) | |
download | newspipe-082bf39a7dd7296d4f51b6b124d185135dc00989.tar.gz newspipe-082bf39a7dd7296d4f51b6b124d185135dc00989.tar.bz2 newspipe-082bf39a7dd7296d4f51b6b124d185135dc00989.zip |
Merge branch 'feature/categories'
close #22
close #23
Diffstat (limited to 'src/web/forms.py')
-rw-r--r-- | src/web/forms.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/web/forms.py b/src/web/forms.py index 447a54e9..9dbf1b5f 100644 --- a/src/web/forms.py +++ b/src/web/forms.py @@ -27,17 +27,18 @@ __copyright__ = "Copyright (c) Cedric Bonhomme" __license__ = "GPLv3" -from flask import flash, request, url_for, redirect +from flask import flash, url_for, redirect from flask.ext.wtf import Form from flask.ext.babel import lazy_gettext from wtforms import TextField, TextAreaField, PasswordField, BooleanField, \ - SubmitField, IntegerField, validators, HiddenField + SubmitField, IntegerField, SelectField, validators, HiddenField from flask.ext.wtf.html5 import EmailField from flask_wtf import RecaptchaField from web import utils from web.models import User + class SignupForm(Form): """ Sign up form (registration to jarr). @@ -57,10 +58,13 @@ class SignupForm(Form): def validate(self): validated = super(SignupForm, self).validate() if self.nickname.data != User.make_valid_nickname(self.nickname.data): - self.nickname.errors.append(lazy_gettext('This nickname has invalid characters. Please use letters, numbers, dots and underscores only.')) + self.nickname.errors.append(lazy_gettext( + 'This nickname has invalid characters. ' + 'Please use letters, numbers, dots and underscores only.')) validated = False return validated + class RedirectForm(Form): """ Secure back redirects with WTForms. @@ -78,6 +82,7 @@ class RedirectForm(Form): target = utils.get_redirect_target() return redirect(target or url_for(endpoint, **values)) + class SigninForm(RedirectForm): """ Sign in form (connection to jarr). @@ -102,7 +107,6 @@ class SigninForm(RedirectForm): return False else: flash(lazy_gettext('Invalid email or password'), 'danger') - #self.email.errors.append("Invalid email or password") return False @@ -124,7 +128,9 @@ class UserForm(Form): def validate(self): validated = super(UserForm, self).validate() if self.nickname.data != User.make_valid_nickname(self.nickname.data): - self.nickname.errors.append(lazy_gettext('This nickname has invalid characters. Please use letters, numbers, dots and underscores only.')) + self.nickname.errors.append(lazy_gettext( + 'This nickname has invalid characters. ' + 'Please use letters, numbers, dots and underscores only.')) validated = False return validated @@ -167,11 +173,18 @@ class AddFeedForm(Form): site_link = TextField(lazy_gettext("Site link"), [validators.Optional()]) enabled = BooleanField(lazy_gettext("Check for updates"), default=True) submit = SubmitField(lazy_gettext("Save")) + category_id = SelectField(lazy_gettext("Category of the feed"), + [validators.Optional()]) - def validate(self): - if not super(AddFeedForm, self).validate(): - return False - return True + def set_category_choices(self, categories): + self.category_id.choices = [('0', 'No Category')] + self.category_id.choices += [(str(cat.id), cat.name) + for cat in categories] + + +class CategoryForm(Form): + name = TextField(lazy_gettext("Name")) + submit = SubmitField(lazy_gettext("Submit")) class InformationMessageForm(Form): @@ -201,5 +214,4 @@ class RecoverPasswordForm(Form): return False else: flash(lazy_gettext('Invalid email.'), 'danger') - #self.email.errors.append("Invalid email") return False |