diff options
| -rw-r--r-- | blog/views.py | 7 | ||||
| -rw-r--r-- | blog_admin/urls.py | 1 | ||||
| -rw-r--r-- | blog_admin/views.py | 34 | ||||
| -rw-r--r-- | static/css/styles.css | 9 | ||||
| -rw-r--r-- | templates/blog/partials/sidebar.html | 2 | ||||
| -rw-r--r-- | templates/blog_admin/comments.html | 63 | ||||
| -rw-r--r-- | templates/blog_admin/partials/posts_topbar.html | 2 | ||||
| -rw-r--r-- | templates/blog_admin/posts.html | 27 |
8 files changed, 112 insertions, 33 deletions
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/<str:slug>/edit', views.edit_post, name='edit-post'), path('/posts/<str:slug>/publish', views.publish_post, name='publish-post'), path('/posts/<str:slug>/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 @@ <img src="{% static 'images/site/icons/right_hand.gif' %}" alt="Archive" border="0"> </span> <span> - <a href="#"> + <a href="{% url 'blog-admin:comments' %}"> Manage Comments </a> </span> 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 %} +<div class="main"> + <h2 class="mtctitem" {% if not messages %}style="border: none; margin-bottom: 0;"{% endif %}>{{ title }}</h2> +{% for message in messages %} +<div style="text-align:center;padding:0;"> + <p class="{{message.tags}}" style="text-align:center; margin-bottom: 15px;">{{ message }}</p> +</div> +{% endfor %} +<table id="tabular"> + <thead> + <tr> + <th colspan="3">Text</th> + <th>Author</th> + <th colspan="2">Post</th> + <th>Comment Date</th> + <th>Actions</th> + </tr> + </thead> + <tbody> + {% for comment in comments %} + <tr> + <td colspan="3">{{ comment.body }}</td> + <td>{% if comment.user %}{{ comment.user.username }}{% else %}{{ comment.anonymous_user.name }}{% endif %}</td> + <td colspan="2">{{ comment.post.title }}</td> + <td>{{ comment.created_at | date:"d.m.Y" }}</td> + <td> + <a href="{% url 'admin:blog_comment_change' comment.id %}">Edit</a> + <a href="{% url 'admin:blog_comment_delete' comment.id %}">Delete</a> + </td> + </tr> + {% endfor %} + </tbody> +</table> +{% if num_pages and page %} + <div class="pagination"> + <center> + <table id="pagination"> + <tr> + {% if page == 1 %} + <td><a class="disabled">«</a></td> + <td style="margin-right: 15px;"><a class="disabled">‹</a></td> + {% else %} + <td><a href="{% url 'blog-admin:comments' %}?page=1">«</a></td> + <td style="margin-right: 15px;"><a href="{% url 'blog-admin:comments' %}?page={{ page|add:'-1' }}">‹</a></td> + {% endif %} + {% load times %} + {% for i in num_pages|times %} + <td><a {% if i == page %}class="active"{% endif %} href="{% url 'blog-admin:comments' %}?page={{ i }}">{{ i }}</a></td> + {% endfor %} + {% if page == num_pages %} + <td style="margin-left: 15px;" class="disabled"><a class="disabled">›</a></td> + <td><a class="disabled">»</a></td> + {% else %} + <td style="margin-left: 15px;"><a href="{% url 'blog-admin:comments' %}?page={{ page|add:'1' }}">›</a></td> + <td><a href="{% url 'blog-admin:comments' %}?page={{ num_pages }}">»</a></td> + {% endif %} + </tr> + </table> + </center> + </div> +{% 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 @@ -<div style="float: right; position: relative; top: -10px;"> +<div style="position: relative; top: -30px;"> <form style="display: inline-block;" action="{% url 'blog-admin:posts-search' %}" method="get"> <input style="display: inline;" type="text" name="q" placeholder="Search Posts" autocomplete="off"/> <input style="display: inline;" type="submit" value="Search" class="button" /> 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 @@ <p class="{{message.tags}}" style="text-align:center; margin-bottom: 15px;">{{ message }}</p> </div> {% endfor %} - <table id="posts"> + <table id="tabular"> <thead> <tr> - - <th colspan="3">Article</th> + <th style="width: 28px; text-align: center;"></th> + <th style="width: 90px; text-align: center;">Cover</th> + <th colspan='1'>Article</th> <th>Author</th> <th>Created</th> <th>Category</th> @@ -23,29 +24,23 @@ <tbody> {% for post in posts %} <tr> - <td style="position: relative;"> + <td> {% if post.is_public %} - {% comment %} <span class="label label-success">Published</span> {% endcomment %} - <span> - <img src="{% static 'images/site/icons/eye_open.png' %}" alt="Home" border="0" width="24" height="24"> - </span> + <img src="{% static 'images/site/icons/eye_open.png' %}" alt="Home" border="0" width="24" height="24" style="margin-left: 2px;"> {% else %} - {% comment %} <span class="label label-warning">Draft</span> {% endif %} {% endcomment %} - <span> - <img src="{% static 'images/site/icons/eye_closed.png' %}" alt="Home" border="0" width="24" height="24"> - </span> + <img src="{% static 'images/site/icons/eye_closed.png' %}" alt="Home" border="0" width="24" height="24" style="margin-left: 2px;"> {% endif %} </td> <td> - <img src="{% url 'ignis:post_image' '80' post.id %}.gif" alt="Cover Image" style="width: 80px; display: block;"> + <img src="{% url 'ignis:post_image' '80' post.id %}.gif" alt="Cover Image" style="width: 80px; display: block; margin: 0 auto;"> </td> - <td> + <td colspan='1'> <a href="{% url 'blog:post' post.slug %}"> - <p>{{ post.title }}</p> + {{ post.title }} </a> </td> <td><a href="{% url 'blog:user_activity' post.author %}">{{ post.author }}</a></td> - <td>{{ post.date }}</td> + <td>{{ post.date | date:"d M Y" }}</td> <td><a href="{% url 'blog:categories' %}/{{ post.category.slug }}">{{ post.category }}</a></td> <td> <p><a href="{% url 'blog-admin:new-post'%}?mode=edit&post_id={{post.id}}">Edit Post Metadata</a></p> |
