aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-09-20 00:32:16 -0400
committerBobby <[email protected]>2022-09-20 00:32:16 -0400
commit84c80328c1ff76416ee2a8bd7f098710ae93c01c (patch)
tree98662659720025a8db4e5a4dc604b1b376dcd6a9
parent71362e284887e628f411eef3a39387699060a08f (diff)
downloadthatcomputerscientist-84c80328c1ff76416ee2a8bd7f098710ae93c01c.tar.xz
thatcomputerscientist-84c80328c1ff76416ee2a8bd7f098710ae93c01c.zip
Tags page
-rw-r--r--blog_admin/views.py18
-rw-r--r--templates/blog_admin/partials/tags_topbar.html13
-rw-r--r--templates/blog_admin/posts.html22
-rw-r--r--templates/blog_admin/tags.html49
4 files changed, 101 insertions, 1 deletions
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 @@
+<h1 style="font-size: 2em;">{{ title }}</h1>
+<div class="float-right">
+ <a href="{% url 'blog-admin:new-post' %}" >Create New Tag</a>
+ {% comment %} Search Users Box {% endcomment %}
+ <form style="display: inline-block; margin-left: 10px;" action="{% url 'blog-admin:posts-search' %}" method="get">
+ <input style="display: inline-block" type="text" name="q" placeholder="Search Tags" autocomplete="off"/>
+ <input style="display: inline-block" type="submit" value="Search" />
+ </form>
+</div>
+<hr>
+{% for message in messages %}
+ <p class="{{message.tags}}" style="text-align:center;">{{ message }}</p>
+{% 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 @@
</tr>
{% endfor %}
</tbody>
+ </table>
+ {% if num_pages and page %}
+ <div class="pagination">
+ {% if page == 1 %}
+ <a href="#" class="disabled">&laquo;</a>
+ <a href="#" class="disabled">&lsaquo;</a>
+ {% else %}
+ <a href="{% url 'blog-admin:posts'%}?page=1">&laquo;</a>
+ <a href="{% url 'blog-admin:posts'%}?page={{ page|add:-1 }}">&lsaquo;</a>
+ {% endif %}
+ {% for i in num_pages|make_list %}
+ <a href="{% url 'blog-admin:posts'%}?page={{ i }}">{{ i }}</a>
+ {% endfor %}
+ {% if page == num_pages %}
+ <a href="#" class="disabled">&rsaquo;</a>
+ <a href="#" class="disabled">&raquo;</a>
+ {% else %}
+ <a href="{% url 'blog-admin:posts'%}?page={{ page|add:1 }}">&rsaquo;</a>
+ <a href="{% url 'blog-admin:posts'%}?page={{ num_pages }}">&raquo;</a>
+ {% endif %}
+ </div>
+ {% endif %}
</section>
</div>
{% 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 %}
+<div class="main">
+ <section>
+ {% include 'blog_admin/partials/tags_topbar.html' %}
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Slug</th>
+ <th>tags</th>
+ <th>Actions</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for tag in tags %}
+ <tr>
+ <td>{{ tag.slug }}</td>
+ <td>{{ tag.post_count }}</td>
+ <td>
+ <a href="#" class="btn btn-default btn-xs">Edit</a>
+ <a href="#" class="btn btn-danger btn-xs">Delete</a>
+ </td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ </table>
+ {% if num_pages and page %}
+ <div class="pagination">
+ {% if page == 1 %}
+ <a href="#" class="disabled">&laquo;</a>
+ <a href="#" class="disabled">&lsaquo;</a>
+ {% else %}
+ <a href="{% url 'blog-admin:tags'%}?page=1">&laquo;</a>
+ <a href="{% url 'blog-admin:tags'%}?page={{ page|add:-1 }}">&lsaquo;</a>
+ {% endif %}
+ {% for i in num_pages|make_list %}
+ <a href="{% url 'blog-admin:tags'%}?page={{ i }}">{{ i }}</a>
+ {% endfor %}
+ {% if page == num_pages %}
+ <a href="#" class="disabled">&rsaquo;</a>
+ <a href="#" class="disabled">&raquo;</a>
+ {% else %}
+ <a href="{% url 'blog-admin:tags'%}?page={{ page|add:1 }}">&rsaquo;</a>
+ <a href="{% url 'blog-admin:tags'%}?page={{ num_pages }}">&raquo;</a>
+ {% endif %}
+ </div>
+ {% endif %}
+ </section>
+</div>
+{% endblock %}