From c7cb022db471d75b2daba6c72e51abdc033f6ea7 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 28 Oct 2018 14:38:46 +0100 Subject: Proposition for the new stream page. --- src/web/templates/user_stream.html | 51 ++++++++++++++++++++++++++++++++++++++ src/web/views/user.py | 36 ++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/web/templates/user_stream.html (limited to 'src') diff --git a/src/web/templates/user_stream.html b/src/web/templates/user_stream.html new file mode 100644 index 00000000..3c20b241 --- /dev/null +++ b/src/web/templates/user_stream.html @@ -0,0 +1,51 @@ +{% extends "layout.html" %} +{% block content %} +
+ {% if category %} +
+
+

Articles from the category {{ category.name }}

+
+
+ {% endif %} + +
+
+ {{ pagination.info }} +
+
+ +
+
+ {{ pagination.links }} +
+
+ +
+ + + + + + + + + + {% for article in articles %} + + + + + + {% endfor %} + +
#{{ _('Title') }}{{ _('Published at') }}
{{ loop.index }}{{ article.title }}{{ article.date }}
+
+ +
+
+ {{ pagination.links }} +
+
+
+{% endblock %} diff --git a/src/web/views/user.py b/src/web/views/user.py index ceee6928..a697eb5b 100644 --- a/src/web/views/user.py +++ b/src/web/views/user.py @@ -5,6 +5,7 @@ from flask import (Blueprint, g, render_template, redirect, flash, url_for, request) from flask_babel import gettext from flask_login import login_required, current_user +from flask_paginate import Pagination, get_page_args import conf from notifications import notifications @@ -37,12 +38,45 @@ def profile_public(nickname=None): filters['private'] = False if category_id: filters['category_id'] = category_id - feeds = FeedController(user.id).read(**filters).order_by('title') + feeds = FeedController(user.id).read(**filters) return render_template('profile_public.html', user=user, feeds=feeds, selected_category_id=category_id) +@user_bp.route('//stream', defaults={'per_page': '25'}, methods=['GET']) +def user_stream(per_page, nickname=None): + """ + Display the public profile of the user. + """ + filters = {} + category_id = int(request.args.get('category_id', 0)) + category = CategoryController(current_user.id).read(id=category_id).first() + if category: + filters['category_id'] = category_id + + user_contr = UserController() + user = user_contr.get(nickname=nickname) + if not user.is_public_profile: + if current_user.is_authenticated and current_user.id == user.id: + flash(gettext('You must set your profile to public.'), 'info') + return redirect(url_for('user.profile')) + + articles = ArticleController(user.id).read_light(**filters) + + page, per_page, offset = get_page_args(per_page_parameter='per_page') + pagination = Pagination(page=page, total=articles.count(), + css_framework='bootstrap3', + search=False, record_name='articles', + per_page=per_page) + + return render_template('user_stream.html', user=user, + articles=articles.offset(offset).limit(per_page), + category=category, + pagination=pagination, + nickname=nickname) + + @user_bp.route('/management', methods=['GET', 'POST']) @login_required def management(): -- cgit