From 8bb831a4c3ce3a2e9c0d61a5a058db87a9e408a0 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Tue, 20 Sep 2016 14:48:25 +0200 Subject: Draft for a public user profile page. --- ...c5b8ac9_add_column_is_public_profile_to_the_.py | 25 +++++++++++ src/web/forms.py | 1 + src/web/models/user.py | 1 + src/web/templates/feed_list.html | 50 +++++++++++++--------- src/web/templates/profile.html | 3 ++ src/web/templates/profile_public.html | 16 +++++++ src/web/views/user.py | 25 +++++++++-- 7 files changed, 96 insertions(+), 25 deletions(-) create mode 100644 migrations/versions/957d4c5b8ac9_add_column_is_public_profile_to_the_.py create mode 100644 src/web/templates/profile_public.html diff --git a/migrations/versions/957d4c5b8ac9_add_column_is_public_profile_to_the_.py b/migrations/versions/957d4c5b8ac9_add_column_is_public_profile_to_the_.py new file mode 100644 index 00000000..4e967121 --- /dev/null +++ b/migrations/versions/957d4c5b8ac9_add_column_is_public_profile_to_the_.py @@ -0,0 +1,25 @@ +"""add column is_public_profile to the user table + +Revision ID: 957d4c5b8ac9 +Revises: 2472eddbf44b +Create Date: 2016-09-20 14:35:31.302555 + +""" + +# revision identifiers, used by Alembic. +revision = '957d4c5b8ac9' +down_revision = '2472eddbf44b' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('user', sa.Column('is_public_profile', + sa.Boolean(), default=False)) + + +def downgrade(): + op.drop_column('user', 'is_public_profile') diff --git a/src/web/forms.py b/src/web/forms.py index e73cfb98..4770f70c 100644 --- a/src/web/forms.py +++ b/src/web/forms.py @@ -162,6 +162,7 @@ class ProfileForm(Form): refresh_rate = IntegerField(lazy_gettext("Feeds refresh frequency " "(in minutes)"), default=60) + is_public_profile = BooleanField(lazy_gettext("Public profile"), default=True) submit = SubmitField(lazy_gettext("Save")) def validate(self): diff --git a/src/web/models/user.py b/src/web/models/user.py index e8ac1d3b..3e4ffcac 100644 --- a/src/web/models/user.py +++ b/src/web/models/user.py @@ -45,6 +45,7 @@ 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) 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/feed_list.html b/src/web/templates/feed_list.html index 093ed631..04543e4c 100644 --- a/src/web/templates/feed_list.html +++ b/src/web/templates/feed_list.html @@ -4,36 +4,44 @@ # - {{ _('Status') }} + {% if current_user.is_authenticated and current_user.id == user.id %} + {{ _('Status') }} + {% endif %} {{ _('Title') }} {{ _('Site') }} - {{ _('Articles') }} - {{ _('Actions') }} + {% if current_user.is_authenticated and current_user.id == user.id %} + {{ _('Articles') }} + {{ _('Actions') }} + {% endif %} {% for feed in feeds %} - + {{ loop.index }} - - {% if feed.enabled %} - - {% else %} - - {% endif %} - {% if feed.error_count >= conf.DEFAULT_MAX_ERROR %} - - {% endif %} - + {% if current_user.is_authenticated and current_user.id == user.id %} + + {% if feed.enabled %} + + {% else %} + + {% endif %} + {% if feed.error_count >= conf.DEFAULT_MAX_ERROR %} + + {% endif %} + + {% endif %} {% if feed.icon_url %} {% endif %}{{ feed.title }} {{ feed.site_link }} - ( {{ unread_article_count.get(feed.id, 0) }} ) {{ article_count.get(feed.id, 0) }} - - - - - - + {% if current_user.is_authenticated and current_user.id == user.id %} + ( {{ unread_article_count.get(feed.id, 0) }} ) {{ article_count.get(feed.id, 0) }} + + + + + + + {% endif %} {% endfor %} diff --git a/src/web/templates/profile.html b/src/web/templates/profile.html index acd593b2..8751446f 100644 --- a/src/web/templates/profile.html +++ b/src/web/templates/profile.html @@ -34,6 +34,9 @@ {{ form.refresh_rate.label }} {{ form.refresh_rate(class_="form-control") }} {% for error in form.refresh_rate.errors %} {{ error }}
{% endfor %} + + {{ form.is_public_profile.label }} + {{ form.is_public_profile(class_="form-control") }} {% for error in form.is_public_profile.errors %} {{ error }}
{% endfor %}
{{ form.submit(class_="btn") }} diff --git a/src/web/templates/profile_public.html b/src/web/templates/profile_public.html new file mode 100644 index 00000000..04beee8e --- /dev/null +++ b/src/web/templates/profile_public.html @@ -0,0 +1,16 @@ +{% extends "layout.html" %} +{% block content %} +
+

{{ user.nickname }}

+
+
+

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

+

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

+
+
+ +

Feeds

+ {% include "feed_list.html" %} + +
+{% endblock %} diff --git a/src/web/views/user.py b/src/web/views/user.py index 229530d1..bd12010c 100644 --- a/src/web/views/user.py +++ b/src/web/views/user.py @@ -18,6 +18,22 @@ users_bp = Blueprint('users', __name__, url_prefix='/users') user_bp = Blueprint('user', __name__, url_prefix='/user') +@user_bp.route('/', methods=['GET']) +def profile_public(nickname=None): + """ + Display the public profile of the user. + """ + user_contr = UserController() + user = user_contr.get(nickname=nickname) + if not user.is_public_profile: + return redirect(url_for('home')) + art_contr = ArticleController(user.id) + return render_template('profile_public.html', + user=user, + feeds=user.feeds, + unread_article_count=art_contr.count_by_category(readed=False), + article_count=art_contr.count_by_category()) + @user_bp.route('/management', methods=['GET', 'POST']) @login_required def management(): @@ -80,10 +96,11 @@ def profile(): if request.method == 'POST': if form.validate(): user_contr.update({'id': current_user.id}, - {'nickname': form.nickname.data, - 'email': form.email.data, - 'password': form.password.data, - 'refresh_rate': form.refresh_rate.data}) + {'nickname': form.nickname.data, + 'email': form.email.data, + 'password': form.password.data, + 'refresh_rate': form.refresh_rate.data, + 'is_public_profile': form.is_public_profile.data}) flash(gettext('User %(nick)s successfully updated', nick=user.nickname), 'success') -- cgit