8000 Issue #13 done. · moktadirul-raju/DjangoBlog@195a3d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 195a3d9

Browse files
committed
Issue #13 done.
1 parent 5181adf commit 195a3d9

12 files changed

+73
-20
lines changed
58 Bytes
Binary file not shown.
352 Bytes
Binary file not shown.

backend/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
path('delete_post/<int:pk>/', views.delete_post, name='delete_post'),
1313
path('users/', views.users, name='users'),
1414
path('comments/', views.comments, name='comments'),
15+
path('moderate_comment/', views.moderate_comment, name='moderate_comment'),
1516
path('tags/', views.tags, name='tags'),
1617
path('categories/', views.categories, name='categories'),
1718
path('settings/', views.settings, name='settings'),

backend/views.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def create_post(request):
6161

6262
if status == "Save as Draft":
6363
post.status = "drafted"
64-
post.published_date = datetime.now() # Have to remove this line later
64+
post.published_date = datetime.now() # Have to remove this line later
6565
else:
6666
post.status = "published"
6767

@@ -128,6 +128,20 @@ def comments(request):
128128

129129
return render(request, 'backend/comments.html', context=my_dict)
130130

131+
def moderate_comment(request):
132+
if request.method == 'POST':
133+
comment_id = request.POST.get('comment_id')
134+
comment = Comment.objects.get(id=comment_id)
135+
action = request.POST.get('action')
136+
137+
if action == "approve":
138+
comment.approve()
139+
140+
elif action == "trash":
141+
comment.move_to_trash()
142+
143+
return HttpResponseRedirect(reverse('backend:comments'))
144+
131145
def users(request):
132146
users = UserProfileInfo.objects.all()
133147
my_dict = {'users':users}
132 Bytes
Binary file not shown.

blog/__pycache__/views.cpython-37.pyc

15 Bytes
Binary file not shown.
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 2.1.4 on 2019-02-07 02:55
2+
3+
import datetime
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('blog', '0015_auto_20190204_0148'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='comment',
16+
name='created_date',
17+
field=models.DateTimeField(default=datetime.datetime(2019, 2, 7, 2, 55, 13, 967155)),
18+
),
19+
migrations.AlterField(
20+
model_name='post',
21+
name='created_date',
22+
field=models.DateTimeField(default=datetime.datetime(2019, 2, 7, 2, 55, 13, 966589)),
23+
),
24+
migrations.AlterField(
25+
model_name='reply',
26+
name='published_date',
27+
field=models.DateTimeField(blank=True, default=datetime.datetime(2019, 2, 7, 2, 55, 13, 967556)),
28+
),
29+
]
Binary file not shown.

blog/models.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ class Comment(models.Model):
5252
published_date = models.DateTimeField(null=True, blank=True)
5353
is_approved = models.BooleanField(default=False)
5454

55+
5556
def approve(self):
56-
self.is_approved = true
57+
self.is_approved = True
5758
self.save()
5859

60+
def move_to_trash(self):
61+
self.delete()
62+
5963
def get_absolute_url(self):
6064
return reverse('blog:post_details', args=(post_id, ))
6165

blog/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def post_details(request, pk):
4242
previous_post = None
4343

4444
post_id = post.id
45-
comments = post.comments.all()
45+
comments = post.comments.filter(is_approved=True)
4646

4747

4848

db.sqlite3

0 Bytes
Binary file not shown.

templates/backend/comments.html

+22-17
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,45 @@
2020
{% if comments %}
2121
{% for comment in comments %}
2222
<tr>
23-
<th scope="row">1</th>
23+
<th scope="row">{{forloop.counter }}</th>
2424

2525
<td style="width:400px;">
2626
<p>{{ comment.content }}</p>
27-
<a href="#" class="btn btn-success">View in the Post</a>
27+
<a href="/blog/posts/{{comment.post.id}}" class="btn btn-success">View in the Post</a>
2828

2929
</td>
3030
<td>{{ comment.author }}</td>
3131
{% if comment.is_approved %}
3232
<td>Approved</td>
3333
<td>
34-
<select class="custom-select" style="width:200px">
35-
<option>
34+
<form action="{% url 'backend:moderate_comment'%}" method="POST" >
35+
{% csrf_token %}
36+
<input type="hidden" name="comment_id" value="{{comment.id}}">
37+
<select name="action" class="custom-select" style="width:200px">
38+
<option value="trash">
3639
Move to Trash
3740
</option>
3841
</select>
39-
<button class="btn btn-dark">Apply</button>
42+
<button type="submit" class="btn btn-dark">Apply</button>
43+
</form>
4044
</td>
4145
{% else %}
4246
<td>Awaiting for Moderation </td>
4347
<td>
44-
<select class="custom-select" style="width:200px">
45-
<option>
46-
Approve
48+
<form action="{% url 'backend:moderate_comment'%}" method="POST" >
49+
{% csrf_token %}
50+
<input type="hidden" name="comment_id" value="{{comment.id}}">
51+
<select name="action" class="custom-select" style="width:200px">
52+
<option value="approve">
53+
Approve
54+
</option>
55+
56+
<option value="trash">
57+
Move to Trash
4758
</option>
48-
49-
<option>
50-
Mark As Spam
51-
</option>
52-
<option>
53-
Move to Trash
54-
</option>
55-
</select>
56-
<button class="btn btn-dark">Apply</button>
59+
</select>
60+
<button type="submit" class="btn btn-dark">Apply</button>
61+
</form>
5762
</td>
5863
{% endif %}
5964

0 commit comments

Comments
 (0)
0