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. --- 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 +++++++++++++++--- 6 files changed, 71 insertions(+), 25 deletions(-) create mode 100644 src/web/templates/profile_public.html (limited to 'src') 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