убрал навиг гет запросы, зафиксил навигацию пашинации
parent
18724c455a
commit
3bc178f2cc
|
@ -15,7 +15,7 @@ from .blog import bp
|
||||||
locale.setlocale(locale.LC_ALL, "")
|
locale.setlocale(locale.LC_ALL, "")
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/", methods=["GET"], defaults={"page": 1})
|
@bp.route("/")
|
||||||
@bp.route("/<int:page>")
|
@bp.route("/<int:page>")
|
||||||
def index(page=1):
|
def index(page=1):
|
||||||
per_page = current_app.config.get("POSTS_ON_PAGE")
|
per_page = current_app.config.get("POSTS_ON_PAGE")
|
||||||
|
@ -23,7 +23,9 @@ def index(page=1):
|
||||||
posts, total = get_paginated_posts(page, per_page)
|
posts, total = get_paginated_posts(page, per_page)
|
||||||
total_pages = total // per_page + [0, 1][total % per_page != 0]
|
total_pages = total // per_page + [0, 1][total % per_page != 0]
|
||||||
|
|
||||||
list_pages = [x for x in range(1, total_pages + 1)]
|
list_pages = [
|
||||||
|
x for x in range(1, total_pages + 1) if x >= page - 2 and x <= page + 2
|
||||||
|
]
|
||||||
return render_template(
|
return render_template(
|
||||||
"blog/index.html",
|
"blog/index.html",
|
||||||
title=f'{current_app.config.get("BRAND")} - разговоры про питон',
|
title=f'{current_app.config.get("BRAND")} - разговоры про питон',
|
||||||
|
@ -84,14 +86,9 @@ def get_all_tags():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/tag/", methods=["GET"], defaults={"page": 1})
|
@bp.route("/tag/")
|
||||||
@bp.route("/tag/<path:tag>")
|
@bp.route("/tag/<path:tag>/<int:page>")
|
||||||
def get_posts_by_tag(page=1, tag=None):
|
def get_posts_by_tag(page=1, tag=None):
|
||||||
if tag is None:
|
|
||||||
tag = request.args.get("tag")
|
|
||||||
if tag is None:
|
|
||||||
return redirect(url_for(".get_all_tags"))
|
|
||||||
|
|
||||||
per_page = current_app.config.get("POSTS_ON_PAGE")
|
per_page = current_app.config.get("POSTS_ON_PAGE")
|
||||||
posts, total = get_all_posts_by_tag(tag, page, per_page)
|
posts, total = get_all_posts_by_tag(tag, page, per_page)
|
||||||
|
|
||||||
|
@ -105,13 +102,14 @@ def get_posts_by_tag(page=1, tag=None):
|
||||||
]
|
]
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"blog/index.html",
|
"blog/tagget_posts.html",
|
||||||
title=f'{current_app.config.get("BRAND")} - посты по {tag}',
|
title=f'{current_app.config.get("BRAND")} - посты по {tag}',
|
||||||
headers=current_app.config.get("SITE_HEADERS"),
|
headers=current_app.config.get("SITE_HEADERS"),
|
||||||
menu_title=current_app.config.get("BRAND"),
|
menu_title=current_app.config.get("BRAND"),
|
||||||
menu_items=current_app.config.get("MENU_ITEMS"),
|
menu_items=current_app.config.get("MENU_ITEMS"),
|
||||||
posts=posts,
|
posts=posts,
|
||||||
page=page,
|
page=page,
|
||||||
|
tag=tag,
|
||||||
total_pages=total_pages,
|
total_pages=total_pages,
|
||||||
list_pages=list_pages,
|
list_pages=list_pages,
|
||||||
mylinks=current_app.config.get("MYLINKS"),
|
mylinks=current_app.config.get("MYLINKS"),
|
||||||
|
|
|
@ -40,7 +40,6 @@ def get_all_posts_by_tag(tag, page, per_page):
|
||||||
)
|
)
|
||||||
if posts_query.total == 0:
|
if posts_query.total == 0:
|
||||||
return None, False
|
return None, False
|
||||||
print(posts_query.total)
|
|
||||||
return posts_query, posts_query.total
|
return posts_query, posts_query.total
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
</a>
|
</a>
|
||||||
<small>
|
<small>
|
||||||
{% for t in p.Post.tags %}
|
{% for t in p.Post.tags %}
|
||||||
<a class="link-offset-2 link-offset-3-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover" href="{{url_for(".get_posts_by_tag", tag=t.tag )}}">
|
<a class="link-offset-2 link-offset-3-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover" href="/tag/{{t.tag}}/1">
|
||||||
#{{t.tag}}
|
#{{t.tag}}
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}<br>
|
{% endfor %}<br>
|
||||||
|
@ -33,25 +33,27 @@
|
||||||
|
|
||||||
<nav class="container p-3">
|
<nav class="container p-3">
|
||||||
<ul class="pagination justify-content-center"
|
<ul class="pagination justify-content-center"
|
||||||
|
{% block nav_pages %}
|
||||||
{% if posts.has_prev %}
|
{% if posts.has_prev %}
|
||||||
<li class="page-item"><a class="page-link" href="{{ url_for(".index", page=posts.prev_num)}}"><<</a></li>
|
<li class="page-item"><a class="page-link" href="/1"><<</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item disabled"><a class="page-link" ><<</a></li>
|
<li class="page-item disabled"><a class="page-link" ><<</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for i in list_pages %}
|
{% for i in list_pages %}
|
||||||
{% if i == page %}
|
{% if i == page %}
|
||||||
<li class="page-item active"><a class="page-link" href="{{ url_for(".index", page=i)}}">{{ i }}</a></li>
|
<li class="page-item active"><a class="page-link" href="/{{i}}">{{ i }}</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item"><a class="page-link" href="{{ url_for(".index", page=i)}}">{{ i }}</a></li>
|
<li class="page-item"><a class="page-link" href="/{{i}}">{{ i }}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
{% if posts.has_next %}
|
{% if posts.has_next %}
|
||||||
<li class="page-item"><a class="page-link" href="{{ url_for(".index", page=posts.next_num)}}">>></a></li>
|
<li class="page-item"><a class="page-link" href="/{{total_pages}}">>></a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item disabled"><a class="page-link" >>></a></li>
|
<li class="page-item disabled"><a class="page-link" >>></a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endblock nav_pages %}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
{% extends 'blog/index.html' %}
|
||||||
|
|
||||||
|
{% block nav_pages %}
|
||||||
|
{% if posts.has_prev %}
|
||||||
|
<li class="page-item"><a class="page-link" href="/tag/{{tag}}/1"><<</a></li>
|
||||||
|
{% else %}
|
||||||
|
<li class="page-item disabled"><a class="page-link"><<</a></li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for i in list_pages %}
|
||||||
|
{% if i == page %}
|
||||||
|
<li class="page-item active"><a class="page-link" href="/tag/{{tag}}/{{i}}">{{ i }}</a></li>
|
||||||
|
{% else %}
|
||||||
|
<li class="page-item"><a class="page-link" href="/tag/{{tag}}/{{i}}">{{ i }}</a></li>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if posts.has_next %}
|
||||||
|
<li class="page-item"><a class="page-link" href="/tag/{{tag}}/{{total_pages}}">>></a></li>
|
||||||
|
{% else %}
|
||||||
|
<li class="page-item disabled"><a class="page-link">>></a></li>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock nav_pages %}
|
|
@ -15,7 +15,7 @@
|
||||||
<h4>Тэги статей:</h4>
|
<h4>Тэги статей:</h4>
|
||||||
{% for t in tags %}
|
{% for t in tags %}
|
||||||
<li>
|
<li>
|
||||||
<a class="link-offset-2 link-offset-3-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover" href="{{url_for(".get_posts_by_tag", tag=t.tag )}}">
|
<a class="link-offset-2 link-offset-3-hover link-underline link-underline-opacity-0 link-underline-opacity-75-hover" href="/tag/{{t.tag}}/1">
|
||||||
#{{t.tag}}
|
#{{t.tag}}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
Loading…
Reference in New Issue