diff options
-rw-r--r-- | migrations/versions/4b5c161e1ced_.py | 2 | ||||
-rw-r--r-- | pyaggr3g470r/forms.py | 97 | ||||
-rw-r--r-- | pyaggr3g470r/templates/edit_feed.html | 1 | ||||
-rw-r--r-- | pyaggr3g470r/templates/profile.html | 5 | ||||
-rw-r--r-- | pyaggr3g470r/views/views.py | 6 |
5 files changed, 64 insertions, 47 deletions
diff --git a/migrations/versions/4b5c161e1ced_.py b/migrations/versions/4b5c161e1ced_.py index 32cfe8c8..6f591e7e 100644 --- a/migrations/versions/4b5c161e1ced_.py +++ b/migrations/versions/4b5c161e1ced_.py @@ -27,7 +27,7 @@ def upgrade(): nullable=True, default=unix_start, server_default=str(unix_start))) op.add_column('feed', sa.Column('etag', sa.String(), nullable=True)) op.add_column('user', sa.Column('refresh_rate', sa.Integer(), - nullable=True)) + nullable=True, default=60)) # end Alembic commands ### diff --git a/pyaggr3g470r/forms.py b/pyaggr3g470r/forms.py index 58abb864..e385c4e2 100644 --- a/pyaggr3g470r/forms.py +++ b/pyaggr3g470r/forms.py @@ -29,47 +29,52 @@ __license__ = "GPLv3" from flask import flash from flask.ext.wtf import Form from flask.ext.babel import lazy_gettext -from wtforms import TextField, TextAreaField, PasswordField, BooleanField, SubmitField, validators +from wtforms import TextField, TextAreaField, PasswordField, BooleanField, \ + SubmitField, IntegerField, validators from flask.ext.wtf.html5 import EmailField from flask_wtf import RecaptchaField from pyaggr3g470r.models import User class SignupForm(Form): - nickname = TextField(lazy_gettext("Nickname"), [validators.Required(lazy_gettext("Please enter your nickname."))]) - email = EmailField(lazy_gettext("Email"), [validators.Length(min=6, max=35), validators.Required(lazy_gettext("Please enter your email address."))]) - password = PasswordField(lazy_gettext("Password"), [validators.Required(lazy_gettext("Please enter a password.")), validators.Length(min=6, max=100)]) + nickname = TextField(lazy_gettext("Nickname"), + [validators.Required(lazy_gettext("Please enter your nickname."))]) + email = EmailField(lazy_gettext("Email"), + [validators.Length(min=6, max=35), + validators.Required( + lazy_gettext("Please enter your email address."))]) + password = PasswordField(lazy_gettext("Password"), + [validators.Required(lazy_gettext("Please enter a password.")), + validators.Length(min=6, max=100)]) recaptcha = RecaptchaField() submit = SubmitField(lazy_gettext("Sign up")) - def __init__(self, *args, **kwargs): - Form.__init__(self, *args, **kwargs) - def validate(self): - if not Form.validate(self): - return False + 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.')) - return False - return True + validated = False + return validated + class SigninForm(Form): """ Sign in form. """ - email = EmailField("Email", [validators.Length(min=6, max=35), validators.Required(lazy_gettext("Please enter your email address."))]) - password = PasswordField(lazy_gettext('Password'), [validators.Required(lazy_gettext("Please enter a password.")), validators.Length(min=6, max=100)]) + email = EmailField("Email", [validators.Length(min=6, max=35), + validators.Required(lazy_gettext("Please enter your email address."))]) + password = PasswordField(lazy_gettext('Password'), + [validators.Required(lazy_gettext("Please enter a password.")), + validators.Length(min=6, max=100)]) submit = SubmitField(lazy_gettext("Log In")) - def __init__(self, *args, **kwargs): - Form.__init__(self, *args, **kwargs) - def validate(self): - if not Form.validate(self): + if not super(SigninForm, self).validate(): return False user = User.query.filter(User.email == self.email.data).first() - if user and user.check_password(self.password.data) and user.activation_key == "": + if user and user.check_password(self.password.data) \ + and user.activation_key == "": return True elif user and user.activation_key != "": flash(lazy_gettext('Account not confirmed'), 'danger') @@ -79,6 +84,7 @@ class SigninForm(Form): #self.email.errors.append("Invalid email or password") return False + class AddFeedForm(Form): title = TextField(lazy_gettext("Title"), [validators.Optional()]) link = TextField(lazy_gettext("Feed link"), [validators.Optional()]) @@ -86,45 +92,52 @@ class AddFeedForm(Form): enabled = BooleanField(lazy_gettext("Check for updates"), default=True) submit = SubmitField(lazy_gettext("Save")) - def __init__(self, *args, **kwargs): - Form.__init__(self, *args, **kwargs) - - def validate(self): - if not Form.validate(self): - return False - return True class ProfileForm(Form): - nickname = TextField(lazy_gettext("Nickname"), [validators.Required(lazy_gettext("Please enter your nickname."))]) - email = EmailField(lazy_gettext("Email"), [validators.Length(min=6, max=35), validators.Required(lazy_gettext("Please enter your email."))]) + nickname = TextField(lazy_gettext("Nickname"), + [validators.Required(lazy_gettext("Please enter your nickname."))]) + email = EmailField(lazy_gettext("Email"), + [validators.Length(min=6, max=35), + validators.Required(lazy_gettext("Please enter your email."))]) password = PasswordField(lazy_gettext("Password")) + password_conf = PasswordField(lazy_gettext("Password Confirmation")) + refresh_rate = IntegerField(lazy_gettext("Feeds refresh frequency " + "(in minutes)"), + default=60) submit = SubmitField(lazy_gettext("Save")) - def __init__(self, *args, **kwargs): - Form.__init__(self, *args, **kwargs) - def validate(self): - if not Form.validate(self): - return False + validated = super(ProfileForm, self).validate() + if self.password.data != self.password_conf.data: + message = lazy_gettext("Passwords aren't the same.") + self.password.errors.append(message) + self.password_conf.errors.append(message) + validated = False 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.')) - return False - return True + self.nickname.errors.append(lazy_gettext('This nickname has ' + 'invalid characters. Please use letters, numbers, dots and' + ' underscores only.')) + validated = False + return validated + class InformationMessageForm(Form): - subject = TextField(lazy_gettext("Subject"), [validators.Required(lazy_gettext("Please enter a subject."))]) - message = TextAreaField(lazy_gettext("Message"), [validators.Required(lazy_gettext("Please enter a content."))]) + subject = TextField(lazy_gettext("Subject"), + [validators.Required(lazy_gettext("Please enter a subject."))]) + message = TextAreaField(lazy_gettext("Message"), + [validators.Required(lazy_gettext("Please enter a content."))]) submit = SubmitField(lazy_gettext("Send")) + class RecoverPasswordForm(Form): - email = EmailField(lazy_gettext("Email"), [validators.Length(min=6, max=35), validators.Required(lazy_gettext("Please enter your email address."))]) + email = EmailField(lazy_gettext("Email"), + [validators.Length(min=6, max=35), + validators.Required( + lazy_gettext("Please enter your email address."))]) submit = SubmitField(lazy_gettext("Recover")) - def __init__(self, *args, **kwargs): - Form.__init__(self, *args, **kwargs) - def validate(self): - if not Form.validate(self): + if not super(RecoverPasswordForm, self).validate(): return False user = User.query.filter(User.email == self.email.data).first() diff --git a/pyaggr3g470r/templates/edit_feed.html b/pyaggr3g470r/templates/edit_feed.html index 1238e257..a6b28ded 100644 --- a/pyaggr3g470r/templates/edit_feed.html +++ b/pyaggr3g470r/templates/edit_feed.html @@ -17,7 +17,6 @@ {{ form.enabled.label }} {{ form.enabled(class_="checkbox") }} - <br /> {{ form.submit(class_="btn btn-default") }} </form> diff --git a/pyaggr3g470r/templates/profile.html b/pyaggr3g470r/templates/profile.html index 6f22857c..f879b054 100644 --- a/pyaggr3g470r/templates/profile.html +++ b/pyaggr3g470r/templates/profile.html @@ -14,7 +14,10 @@ {{ form.password.label }} {{ form.password(class_="form-control") }} {% for error in form.password.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} - + {{ form.password_conf.label }} + {{ form.password_conf(class_="form-control") }} {% for error in form.password_conf.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} + {{ form.refresh_rate.label }} + {{ form.refresh_rate(class_="form-control") }} {% for error in form.refresh_rate.errors %} <span style="color: red;">{{ error }}<br /></span>{% endfor %} <br /> {{ form.submit(class_="btn") }} </form> diff --git a/pyaggr3g470r/views/views.py b/pyaggr3g470r/views/views.py index d42d5db8..5279d7fe 100644 --- a/pyaggr3g470r/views/views.py +++ b/pyaggr3g470r/views/views.py @@ -554,7 +554,7 @@ def edit_feed(feed_id=None): """ Add or edit a feed. """ - feed = Feed.query.filter(Feed.id == feed_id).first() + feed = FeedController(g.user.id).get(id=feed_id) form = AddFeedForm() if request.method == 'POST': @@ -632,7 +632,9 @@ def profile(): if form.password.data != "": user.set_password(form.password.data) db.session.commit() - flash(gettext('User') + ' ' + user.nickname + ' ' + gettext('successfully updated.'), 'success') + flash("%s %s %s" % (gettext('User'), user.nickname, + gettext('successfully updated.')), + 'success') return redirect(url_for('profile')) else: return render_template('profile.html', form=form) |