From 114460370c2613ea103b6eb709b3ea076d045bc9 Mon Sep 17 00:00:00 2001 From: Bobby Date: Sun, 11 Jun 2023 19:02:56 -0400 Subject: Admin area improvements and comments management --- blog/views.py | 7 ++- blog_admin/urls.py | 1 + blog_admin/views.py | 34 +++++++++---- static/css/styles.css | 9 ++-- templates/blog/partials/sidebar.html | 2 +- templates/blog_admin/comments.html | 63 +++++++++++++++++++++++++ templates/blog_admin/partials/posts_topbar.html | 2 +- templates/blog_admin/posts.html | 27 +++++------ 8 files changed, 112 insertions(+), 33 deletions(-) create mode 100644 templates/blog_admin/comments.html diff --git a/blog/views.py b/blog/views.py index e36fc9d7..d3539dda 100644 --- a/blog/views.py +++ b/blog/views.py @@ -457,12 +457,15 @@ def articles(request, date=None, cg=None): else: category = 'all' posts = Paginator(posts, 10) - posts = posts.page(page) + num_pages = posts.num_pages + try: + posts = posts.page(page) + except: + posts = posts.page(num_pages) for post in posts: post.excerpt = add_excerpt(post) post.num_comments = add_num_comments(post) - num_pages = posts.paginator.num_pages return render(request, 'blog/articles.html', {'title': 'Articles', 'posts': posts, 'num_pages': num_pages, 'page': page, 'order_by': order_by, 'direction': direction, 'categories': categories, 'category': category, 'category_name': category_name if category != 'all' else '', 'type': type, 'date': date if date else '', 'cg': cg if cg else ''}) def user_activity(request, username): diff --git a/blog_admin/urls.py b/blog_admin/urls.py index 9b02fa89..251ebc35 100644 --- a/blog_admin/urls.py +++ b/blog_admin/urls.py @@ -10,4 +10,5 @@ urlpatterns = [ path('/posts//edit', views.edit_post, name='edit-post'), path('/posts//publish', views.publish_post, name='publish-post'), path('/posts//unpublish', views.unpublish_post, name='unpublish-post'), + path('/comments', views.comments, name='comments'), ] \ No newline at end of file diff --git a/blog_admin/views.py b/blog_admin/views.py index bd4f9dc2..c552db05 100644 --- a/blog_admin/views.py +++ b/blog_admin/views.py @@ -4,23 +4,39 @@ from datetime import datetime from django.contrib import messages from django.http import HttpResponseRedirect from django.shortcuts import redirect, render, reverse - -from blog.models import Category, Post, Tag -from ignis.models import CoverImage +from django.core.paginator import Paginator +from blog.models import Category, Post, Tag, Comment # Create your views here. def posts(request): 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 + posts = Post.objects.all().order_by('-date') + posts = Paginator(posts, 50) + num_pages = posts.num_pages try: - page = int(page) + posts = posts.page(page) except: - page = 1 - posts = Post.objects.all().order_by('-date')[50 * (page - 1):50 * page] - num_pages = Post.objects.all().count() // 50 + 1 - url_to_render = 'blog_admin/posts.html?page={}'.format(page) if int(page) and int(page) > 1 else 'blog_admin/posts.html' - return render(request, url_to_render, { 'title': 'Manage Posts', 'posts': posts, 'num_pages': num_pages, 'page': page }) + posts = posts.page(num_pages) + + return render(request, 'blog_admin/posts.html', { 'title': 'Manage Posts', 'posts': posts, 'num_pages': num_pages, 'page': page }) + else: + return redirect('blog:home') + +def comments(request): + 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 + comments = Comment.objects.all().order_by('-created_at') + comments = Paginator(comments, 50) + num_pages = comments.num_pages + try: + comments = comments.page(page) + except: + comments = comments.page(num_pages) + + return render(request, 'blog_admin/comments.html', { 'title': 'Manage Comments', 'comments': comments, 'num_pages': num_pages, 'page': page }) + else: return redirect('blog:home') diff --git a/static/css/styles.css b/static/css/styles.css index bfa7719f..7f9fc550 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -150,21 +150,22 @@ blockquote { } /* Full width auto spacing table... ellipsis if text overflows */ -#posts { +#tabular { width: 100%; border-collapse: collapse; border-spacing: 0; - /* table-layout: fixed; */ + table-layout: fixed; + max-width: 710px; } -#posts td { +#tabular td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 5px 0px; } -#posts th { +#tabular th { text-align: left; padding: 10px 0px; border-bottom: dotted 1px #dddddd; diff --git a/templates/blog/partials/sidebar.html b/templates/blog/partials/sidebar.html index 9699436b..68018db5 100644 --- a/templates/blog/partials/sidebar.html +++ b/templates/blog/partials/sidebar.html @@ -244,7 +244,7 @@ Archive - + Manage Comments diff --git a/templates/blog_admin/comments.html b/templates/blog_admin/comments.html new file mode 100644 index 00000000..95ae1d96 --- /dev/null +++ b/templates/blog_admin/comments.html @@ -0,0 +1,63 @@ +{% extends 'blog/partials/base.html' %} {% block content %} +{% load static %} +
+

{{ title }}

+{% for message in messages %} +
+

{{ message }}

+
+{% endfor %} + + + + + + + + + + + + {% for comment in comments %} + + + + + + + + {% endfor %} + +
TextAuthorPostComment DateActions
{{ comment.body }}{% if comment.user %}{{ comment.user.username }}{% else %}{{ comment.anonymous_user.name }}{% endif %}{{ comment.post.title }}{{ comment.created_at | date:"d.m.Y" }} + Edit + Delete +
+{% if num_pages and page %} + +{% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/blog_admin/partials/posts_topbar.html b/templates/blog_admin/partials/posts_topbar.html index 1e486c31..b9bad541 100644 --- a/templates/blog_admin/partials/posts_topbar.html +++ b/templates/blog_admin/partials/posts_topbar.html @@ -1,4 +1,4 @@ -
+
diff --git a/templates/blog_admin/posts.html b/templates/blog_admin/posts.html index 30cfdb93..a8aac92c 100644 --- a/templates/blog_admin/posts.html +++ b/templates/blog_admin/posts.html @@ -9,11 +9,12 @@

{{ message }}

{% endfor %} - +
- - + + + @@ -23,29 +24,23 @@ {% for post in posts %} - - - +
ArticleCoverArticle Author Created Category
+ {% if post.is_public %} - {% comment %} Published {% endcomment %} - - Home - + Home {% else %} - {% comment %} Draft {% endif %} {% endcomment %} - - Home - + Home {% endif %} - Cover Image + Cover Image + -

{{ post.title }}

+ {{ post.title }}
{{ post.author }}{{ post.date }}{{ post.date | date:"d M Y" }} {{ post.category }}

Edit Post Metadata

-- cgit v1.2.3