diff --git a/yadc/bp/main.py b/yadc/bp/main.py index a66a022..c1b8d67 100644 --- a/yadc/bp/main.py +++ b/yadc/bp/main.py @@ -25,12 +25,12 @@ def index(): return redirect(url_for('main.posts')) # @bp.route('/') -@bp.route('/post', defaults={'page': 1} -) +@bp.route('/post', defaults={'page': 1}) @bp.route('/post/') def posts(page): def tags_prepare(posts): - tags = db.session.query(Tag, func.array_agg(posts.c.id)).join(posts, Tag.posts).group_by(Tag.id).all() + # tags = db.session.query(Tag, func.array_agg(posts.c.id)).join(posts, Tag.posts).group_by(Tag.id).all() + tags = db.session.query(Tag, func.array_agg(Post.id)).join(Tag.posts).filter(Post.id.in_([p.id for p in posts])).group_by(Tag.id).all() # tagset = set() # taglist = list() @@ -59,22 +59,22 @@ def posts(page): # page = int(args.get('page') or 1) return (tags, matched_ratings) - posts_on_page = 4 + posts_on_page = 1 f_tags, f_rating = parse_args() posts_query = Post.query if len(f_tags)>0: posts_query = posts_query.join(Post.tags).group_by(Post.id).filter(Tag.content.in_(f_tags)).having(func.count(Post.id)==len(f_tags)) - posts_query = posts_query.filter(Post.rating.in_(f_rating)).order_by(Post.created).offset((page-1)*posts_on_page).limit(posts_on_page) + posts_query = posts_query.filter(Post.rating.in_(f_rating)).order_by(Post.created) #.offset((page-1)*posts_on_page).limit(posts_on_page) - posts = posts_query.all() - tags = tags_prepare(posts_query.subquery()) + posts = posts_query.paginate(page, posts_on_page) + tags = tags_prepare(posts.items) flash(parse_args()) - # flash(posts) + # flash(posts.items) # flash(tags) - return render_template('index.html', posts=posts, tags=tags) + return render_template('index.html', posts=posts.items, tags=tags, pagination=posts, query_replace=query_replace) @bp.route('/post/show/') def post_show(id): diff --git a/yadc/static/default.scss b/yadc/static/default.scss index 4d40a48..06f0c00 100644 --- a/yadc/static/default.scss +++ b/yadc/static/default.scss @@ -354,7 +354,10 @@ header { .pagin { margin: 10px 0; - margin-right: calc(#{$side-panel-width}/2); + + @include media($bp-desktop) { + margin-right: calc(#{$side-panel-width}*3/4); + } display: flex; flex-flow: row nowrap; diff --git a/yadc/templates/_includes.html b/yadc/templates/_includes.html index 9dd616d..1e5cab3 100644 --- a/yadc/templates/_includes.html +++ b/yadc/templates/_includes.html @@ -1,4 +1,4 @@ -{% macro tags(tags) %} +{% macro render_tags() %}

Tags

@@ -14,6 +14,29 @@
{% endmacro %} + +{% macro render_pagination(endpoint) %} +
+ {% if pagination.has_prev %} + + {% endif %} + {% for page in pagination.iter_pages(left_edge=1, left_current=1, right_current=2, right_edge=1) %} + {% if page %} + {% if page != pagination.page %} + {{ page }} + {% else %} + {{ page }} + {% endif %} + {% else %} + + {% endif %} + {% endfor %} + {% if pagination.has_next %} + + {% endif %} +
+{% endmacro %} + -
- - 1 - 2 - 3 - 4 - 5 - -
+ {{ render_pagination('main.posts') }} {% endblock content %} \ No newline at end of file