Skip to content

Commit 78e8667

Browse files
committed
add manage comments feature
1 parent 9ae864b commit 78e8667

File tree

6 files changed

+122
-6
lines changed

6 files changed

+122
-6
lines changed

app/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
path("documentation", DocumentationView.as_view(), name = "documentaion-page"),
99
path("", DocumentationView.as_view()),
1010
path("dashboard/api", login_required(ApiPageView.as_view())),
11-
path("aboutme", AboutDevPage.as_view(), name="about-me")
11+
path("aboutme", AboutDevPage.as_view(), name="about-me"),
12+
path("dashboard/comments/<str:post_id>", login_required(CommentView.as_view()), name = "comments-page")
1213
]

app/views.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from userprofile.models import Token
88
from app.models import UserSites
99
import uuid
10+
from comments.models import Comment
1011

1112
# Create your views here.
1213

@@ -189,4 +190,34 @@ class AboutDevPage(View):
189190

190191
def get(self, request, *args, **kwargs):
191192

192-
return render(request, self.template_name)
193+
return render(request, self.template_name)
194+
195+
196+
class CommentView(View):
197+
template_name = "comments.html"
198+
199+
def get(self, request, post_id, *args, **kwargs):
200+
post = get_object_or_404(Post, custom_id = post_id, creator = request.user)
201+
202+
comments = Comment.objects.filter(post = post)
203+
204+
context = {
205+
"comments": comments,
206+
}
207+
208+
return render(request, self.template_name, context = context)
209+
210+
def post(self, request, post_id, *args, **kwargs):
211+
if "deletePost" in request.POST:
212+
comment_id = request.POST["delete_id"]
213+
214+
comment = Comment.objects.get(id = comment_id)
215+
comment.delete()
216+
217+
messages.info(request, "You've successfully deleted a comment!")
218+
219+
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
220+
221+
else:
222+
messages.info(request, "Sorry, an error occured!")
223+
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

db.sqlite3

0 Bytes
Binary file not shown.

static/CSS/admin.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ body {
88

99

1010
.container {
11-
max-width: 800px;
1211
margin: 0 auto;
1312
padding: 20px;
1413
}
@@ -100,6 +99,16 @@ td a:hover{
10099
text-decoration: none;
101100
color: #fff;
102101
}
102+
103+
td.comment-s i, td.comment-s a{
104+
color: #128c7e !important;
105+
font-weight: bold;
106+
}
107+
108+
td.comment-s a:hover{
109+
color: #075e54;
110+
}
111+
103112
@media(max-width: 400px){
104113
#btns{
105114
display: flex !important;

templates/admin.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
1313
<link rel="stylesheet" href="{% static 'CSS/admin.css' %}">
1414
<link rel="shortcut icon" href="{% static 'images/logo.png' %}" type="image/x-icon">
15-
15+
<script src="https://kit.fontawesome.com/68ab06de90.js" crossorigin="anonymous"></script>
1616
</head>
1717
<body>
1818
{% include 'extensions/nav.html' %}
@@ -74,8 +74,10 @@ <h2>Manage Posts</h2>
7474
<th>Title</th>
7575
<th>Date</th>
7676
<th>Edit</th>
77+
<th>Comments</th>
7778
<th>Delete</th>
7879
<th>Publish</th>
80+
<th>Category</th>
7981
</tr>
8082
</thead>
8183
<tbody>
@@ -84,8 +86,8 @@ <h2>Manage Posts</h2>
8486
<td class="numbering"></td>
8587
<td style="white-space: nowrap;">{{ post.title|truncatewords:5 }}</td>
8688
<td style="white-space: nowrap;" class="time-of-post">{{ post.time }}</td>
87-
88-
<td><a href="edit/{{ post.custom_id }}" class="set-btn" id="dp{{ post.custom_id }}">Edit</a></td>
89+
<td><a href="edit/{{ post.custom_id }}" class="set-btn" id="dp{{ post.custom_id }}">Edit</a></td>
90+
<td class="comment-s"><a href="/dashboard/comments/{{ post.custom_id }}">{{ post.post.count }} <i class="fa-solid fa-comment green"></i></a></td>
8991
<form action="" method="post">
9092
{% csrf_token %}
9193

@@ -94,6 +96,7 @@ <h2>Manage Posts</h2>
9496

9597
</form>
9698
<td><input type="checkbox" {% if post.publish == True %} checked {% endif %} disabled></td>
99+
<td style="white-space: nowrap;">{{ post.categories|truncatewords:4 }}</td>
97100
</tr>
98101
{% endfor %}
99102
</tbody>

templates/comments.html

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{% load static %}
2+
3+
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
<head>
7+
<meta charset="UTF-8">
8+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
9+
<title>Admin Page</title>
10+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
11+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
12+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
13+
<link rel="stylesheet" href="{% static 'CSS/admin.css' %}">
14+
<link rel="shortcut icon" href="{% static 'images/logo.png' %}" type="image/x-icon">
15+
<script src="https://kit.fontawesome.com/68ab06de90.js" crossorigin="anonymous"></script>
16+
</head>
17+
<body>
18+
{% include 'extensions/nav.html' %}
19+
<section class="container">
20+
<div class="alert alert-success status_post" style="display: none;" role="alert" id="editor-empty-alert"></div>
21+
{% for message in messages %}
22+
<div class="alert alert-success" role="alert" id="editor-empty-alert">
23+
{{ message }}
24+
</div>
25+
{% endfor %}
26+
{% if comments %}
27+
<!-- Manage Post Section -->
28+
<section id="manage-post" class="form-section" style="display: block;">
29+
<h1>Manage Comments</h1>
30+
31+
<table class="table table-responsive">
32+
<thead>
33+
<tr>
34+
<th>S/N</th>
35+
<th>Name</th>
36+
<th>Date</th>
37+
<th>Email</th>
38+
<th>Comment</th>
39+
<th>Delete</th>
40+
</tr>
41+
</thead>
42+
<tbody>
43+
{% for comment in comments %}
44+
<tr>
45+
<td class="numbering"></td>
46+
<td style="white-space: nowrap;">{{ comment.name }}</td>
47+
<td style="white-space: nowrap;" class="time-of-post">{{ comment.time }}</td>
48+
<td>{{ comment.email }}</td>
49+
<td>{{ comment.comment|truncatewords:7 }}</td>
50+
<form action="" method="post">
51+
{% csrf_token %}
52+
<input type="hidden" name="delete_id" value="{{ comment.id }}">
53+
<td id="dp{{ comment.id }}"><button class="set-btn delpostnow" id = "{{ comment.id }}" name="deletePost">Delete</button></td>
54+
</form>
55+
</tr>
56+
{% endfor %}
57+
</tbody>
58+
</table>
59+
{% else %}
60+
<h1>No comments yet</h1>
61+
{% endif %}
62+
</section>
63+
<script>
64+
65+
</script>
66+
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
67+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote-lite.min.css" rel="stylesheet">
68+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote-lite.min.js"></script>
69+
<script src="{% static 'Javascript/summernote.js' %}"></script>
70+
<script src="{% static 'Javascript/admin.js' %}"></script>
71+
</body>
72+
</html>

0 commit comments

Comments
 (0)