From 84c80328c1ff76416ee2a8bd7f098710ae93c01c Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 20 Sep 2022 00:32:16 -0400 Subject: Tags page --- blog_admin/views.py | 18 +++++++++- templates/blog_admin/partials/tags_topbar.html | 13 +++++++ templates/blog_admin/posts.html | 22 ++++++++++++ templates/blog_admin/tags.html | 49 ++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 templates/blog_admin/partials/tags_topbar.html create mode 100644 templates/blog_admin/tags.html diff --git a/blog_admin/views.py b/blog_admin/views.py index ff11ba26..7732866a 100644 --- a/blog_admin/views.py +++ b/blog_admin/views.py @@ -115,7 +115,23 @@ def delete_category(request, slug): pass def tags(request): - pass + if request.user.is_authenticated and (request.user.is_superuser or request.user.is_staff): + page = request.GET.get('page') if request.GET.get('page') else 1 + try: + page = int(page) + except: + page = 1 + tags = Tag.objects.all()[(page-1)*50:page*50] + num_pages = Tag.objects.all().count() // 50 + 1 + # add post count to each tag + for tag in tags: + # post_count which contain this tag slug + post_count = Post.objects.filter(tags__slug = tag.slug).count() + tag.post_count = post_count + url_to_render = 'blog_admin/tags.html?page={}'.format(page) if int(page) and int(page) > 1 else 'blog_admin/tags.html' + return render(request, url_to_render, { 'title': 'Manage Tags', 'tags': tags, 'num_pages': num_pages, 'page': page }) + else: + return redirect('blog:home') def new(request): pass diff --git a/templates/blog_admin/partials/tags_topbar.html b/templates/blog_admin/partials/tags_topbar.html new file mode 100644 index 00000000..1e7090f9 --- /dev/null +++ b/templates/blog_admin/partials/tags_topbar.html @@ -0,0 +1,13 @@ +

{{ title }}

+
+ Create New Tag + {% comment %} Search Users Box {% endcomment %} +
+ + +
+
+
+{% for message in messages %} +

{{ message }}

+{% endfor %} \ No newline at end of file diff --git a/templates/blog_admin/posts.html b/templates/blog_admin/posts.html index 807f403a..ec1f462e 100644 --- a/templates/blog_admin/posts.html +++ b/templates/blog_admin/posts.html @@ -36,6 +36,28 @@ {% endfor %} + + {% if num_pages and page %} + + {% endif %} {% endblock %} diff --git a/templates/blog_admin/tags.html b/templates/blog_admin/tags.html new file mode 100644 index 00000000..3d3d10d2 --- /dev/null +++ b/templates/blog_admin/tags.html @@ -0,0 +1,49 @@ +{% extends 'blog/partials/base.html' %} {% block content %} +
+
+ {% include 'blog_admin/partials/tags_topbar.html' %} + + + + + + + + + + {% for tag in tags %} + + + + + + {% endfor %} + +
SlugtagsActions
{{ tag.slug }}{{ tag.post_count }} + Edit + Delete +
+ {% if num_pages and page %} + + {% endif %} +
+
+{% endblock %} -- cgit v1.2.3