From cb81d058e5738bd9d5a0fab3334dec2371ca5013 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 21 Sep 2016 08:19:09 +0200 Subject: add column webpage in the user table --- ...c3cf0cc_add_column_webpage_in_the_user_table.py | 25 ++++++++++++++++++++++ src/web/forms.py | 3 ++- src/web/models/user.py | 3 +++ src/web/templates/profile.html | 3 +++ src/web/templates/profile_public.html | 7 ++++-- src/web/views/user.py | 3 ++- 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/16f8fc3cf0cc_add_column_webpage_in_the_user_table.py diff --git a/migrations/versions/16f8fc3cf0cc_add_column_webpage_in_the_user_table.py b/migrations/versions/16f8fc3cf0cc_add_column_webpage_in_the_user_table.py new file mode 100644 index 00000000..4ff875b7 --- /dev/null +++ b/migrations/versions/16f8fc3cf0cc_add_column_webpage_in_the_user_table.py @@ -0,0 +1,25 @@ +"""add column webpage in the user table + +Revision ID: 16f8fc3cf0cc +Revises: 957d4c5b8ac9 +Create Date: 2016-09-21 08:00:27.160357 + +""" + +# revision identifiers, used by Alembic. +revision = '16f8fc3cf0cc' +down_revision = '957d4c5b8ac9' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('user', sa.Column('webpage', + sa.String(), default="")) + + +def downgrade(): + op.drop_column('user', 'webpage') diff --git a/src/web/forms.py b/src/web/forms.py index 4770f70c..905a0b2a 100644 --- a/src/web/forms.py +++ b/src/web/forms.py @@ -32,7 +32,7 @@ from flask_babel import lazy_gettext from werkzeug.exceptions import NotFound from wtforms import TextField, TextAreaField, PasswordField, BooleanField, \ SubmitField, IntegerField, SelectField, validators, HiddenField -from flask_wtf.html5 import EmailField +from flask_wtf.html5 import EmailField, URLField from web.lib import misc_utils from web.controllers import UserController @@ -159,6 +159,7 @@ class ProfileForm(Form): validators.Required(lazy_gettext("Please enter your email."))]) password = PasswordField(lazy_gettext("Password")) password_conf = PasswordField(lazy_gettext("Password Confirmation")) + webpage = URLField(lazy_gettext("Webpage")) refresh_rate = IntegerField(lazy_gettext("Feeds refresh frequency " "(in minutes)"), default=60) diff --git a/src/web/models/user.py b/src/web/models/user.py index 3e4ffcac..2e5d2f55 100644 --- a/src/web/models/user.py +++ b/src/web/models/user.py @@ -45,7 +45,10 @@ class User(db.Model, UserMixin, RightMixin): nickname = db.Column(db.String(), unique=True) email = db.Column(db.String(254), index=True, unique=True) pwdhash = db.Column(db.String()) + is_public_profile = db.Column(db.Boolean(), default=False) + webpage = db.Column(db.String(), default="") + date_created = db.Column(db.DateTime(), default=datetime.now) last_seen = db.Column(db.DateTime(), default=datetime.now) refresh_rate = db.Column(db.Integer, default=60) # in minutes diff --git a/src/web/templates/profile.html b/src/web/templates/profile.html index 8751446f..9b5db48a 100644 --- a/src/web/templates/profile.html +++ b/src/web/templates/profile.html @@ -37,6 +37,9 @@ {{ form.is_public_profile.label }} {{ form.is_public_profile(class_="form-control") }} {% for error in form.is_public_profile.errors %} {{ error }}
{% endfor %} + + {{ form.webpage.label }} + {{ form.webpage(class_="form-control") }} {% for error in form.webpage.errors %} {{ error }}
{% endfor %}
{{ form.submit(class_="btn") }} diff --git a/src/web/templates/profile_public.html b/src/web/templates/profile_public.html index c67a4e91..eac36441 100644 --- a/src/web/templates/profile_public.html +++ b/src/web/templates/profile_public.html @@ -4,8 +4,11 @@

{{ user.nickname }}

-

{{ _('Member since') }} {{ user.date_created | datetime }}.

-

{{ _('Last seen:') }} {{ user.last_seen | datetime }}.

+

{{ _('Member since:') }} {{ user.date_created | datetime }}

+

{{ _('Last seen:') }} {{ user.last_seen | datetime }}

+ {% if user.webpage %} +

{{ _('Webpage:') }} {{ user.webpage | safe }}

+ {% endif %}
diff --git a/src/web/views/user.py b/src/web/views/user.py index c7c318e3..df6508f5 100644 --- a/src/web/views/user.py +++ b/src/web/views/user.py @@ -107,7 +107,8 @@ def profile(): 'email': form.email.data, 'password': form.password.data, 'refresh_rate': form.refresh_rate.data, - 'is_public_profile': form.is_public_profile.data}) + 'is_public_profile': form.is_public_profile.data, + 'webpage': form.webpage.data}) flash(gettext('User %(nick)s successfully updated', nick=user.nickname), 'success') -- cgit