From 3bc178f2cc4ceb8d38f318642eac886b1b54f55a Mon Sep 17 00:00:00 2001 From: pi3c Date: Mon, 16 Oct 2023 19:24:14 +0300 Subject: [PATCH] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=B3=20=D0=B3=D0=B5=D1=82=20=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=81=D1=8B,=20=D0=B7=D0=B0=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81=D0=B8=D0=BB=20=D0=BD=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8E=20=D0=BF=D0=B0=D1=88=D0=B8=D0=BD=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproger/blog/urls.py | 18 ++++++++---------- pyproger/dbase/database.py | 1 - pyproger/templates/blog/index.html | 14 ++++++++------ pyproger/templates/blog/tagget_posts.html | 23 +++++++++++++++++++++++ pyproger/templates/blog/tags.html | 2 +- 5 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 pyproger/templates/blog/tagget_posts.html diff --git a/pyproger/blog/urls.py b/pyproger/blog/urls.py index c33a2bd..03fea0b 100644 --- a/pyproger/blog/urls.py +++ b/pyproger/blog/urls.py @@ -15,7 +15,7 @@ from .blog import bp locale.setlocale(locale.LC_ALL, "") -@bp.route("/", methods=["GET"], defaults={"page": 1}) +@bp.route("/") @bp.route("/") def index(page=1): 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) 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( "blog/index.html", 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/") +@bp.route("/tag//") 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") 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( - "blog/index.html", + "blog/tagget_posts.html", title=f'{current_app.config.get("BRAND")} - посты по {tag}', headers=current_app.config.get("SITE_HEADERS"), menu_title=current_app.config.get("BRAND"), menu_items=current_app.config.get("MENU_ITEMS"), posts=posts, page=page, + tag=tag, total_pages=total_pages, list_pages=list_pages, mylinks=current_app.config.get("MYLINKS"), diff --git a/pyproger/dbase/database.py b/pyproger/dbase/database.py index 1e2d109..c6190a1 100644 --- a/pyproger/dbase/database.py +++ b/pyproger/dbase/database.py @@ -40,7 +40,6 @@ def get_all_posts_by_tag(tag, page, per_page): ) if posts_query.total == 0: return None, False - print(posts_query.total) return posts_query, posts_query.total diff --git a/pyproger/templates/blog/index.html b/pyproger/templates/blog/index.html index 5dea970..a6e5347 100644 --- a/pyproger/templates/blog/index.html +++ b/pyproger/templates/blog/index.html @@ -18,7 +18,7 @@ {% for t in p.Post.tags %} - + #{{t.tag}} {% endfor %}
@@ -33,25 +33,27 @@ {% endblock %} diff --git a/pyproger/templates/blog/tagget_posts.html b/pyproger/templates/blog/tagget_posts.html new file mode 100644 index 0000000..8191d09 --- /dev/null +++ b/pyproger/templates/blog/tagget_posts.html @@ -0,0 +1,23 @@ +{% extends 'blog/index.html' %} + +{% block nav_pages %} +{% if posts.has_prev %} +
  • <<
  • +{% else %} +
  • <<
  • +{% endif %} + +{% for i in list_pages %} +{% if i == page %} +
  • {{ i }}
  • +{% else %} +
  • {{ i }}
  • +{% endif %} +{% endfor %} + +{% if posts.has_next %} +
  • >>
  • +{% else %} +
  • >>
  • +{% endif %} +{% endblock nav_pages %} diff --git a/pyproger/templates/blog/tags.html b/pyproger/templates/blog/tags.html index 81379aa..dd5cb8c 100644 --- a/pyproger/templates/blog/tags.html +++ b/pyproger/templates/blog/tags.html @@ -15,7 +15,7 @@

    Тэги статей:

    {% for t in tags %}
  • - + #{{t.tag}}