From 2f9331717075b34534f2745706f57a98f7dce20d Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Mon, 13 Apr 2020 17:27:49 +0530 Subject: Add feature to hide thread or comments --- yaksh/models.py | 2 +- yaksh/templates/yaksh/course_forum.html | 4 +++- yaksh/templates/yaksh/thread_comments.html | 12 ++++++++++-- yaksh/urls.py | 6 ++++-- yaksh/views.py | 23 +++++++++++++++++++---- 5 files changed, 37 insertions(+), 10 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index f9878e4..d76d6aa 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -2670,7 +2670,7 @@ class Thread(ForumBase): return self.comment.last() def get_comments_count(self): - return self.comment.count() + return self.comment.filter(active=True).count() class Comment(ForumBase): diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html index 4741ae0..41dbd7b 100644 --- a/yaksh/templates/yaksh/course_forum.html +++ b/yaksh/templates/yaksh/course_forum.html @@ -57,7 +57,9 @@ {% with thread.get_last_comment as last_comment %} {% if thread.creator.profile.is_moderator %} INSTRUCTOR CREATED {% endif %} Last Post by: {{last_comment.creator}} . {{last_comment.modified_at|naturaltime}} {% endwith %} - Delete + {% if user.profile.is_moderator %} + Delete + {% endif %}
diff --git a/yaksh/templates/yaksh/thread_comments.html b/yaksh/templates/yaksh/thread_comments.html index ab0ade9..f614b7a 100644 --- a/yaksh/templates/yaksh/thread_comments.html +++ b/yaksh/templates/yaksh/thread_comments.html @@ -11,7 +11,12 @@
{{thread.title}}
- {{thread.creator.username}} {{thread.created_at}} + + {{thread.creator.username}} + {{thread.created_at}} + {% if user.profile.is_moderator %}Delete{% endif %} + +

{{thread.description}}

@@ -29,7 +34,10 @@ {% endif %}

{{comment.description}}

- by: {{comment.user.username}} . {{comment.created_at}} + + by: {{comment.creator.username}} . {{comment.created_at}} + {% if user.profile.is_moderator %}Delete{% endif %} +

{% endfor %} diff --git a/yaksh/urls.py b/yaksh/urls.py index a8aa224..1b86ae8 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -60,8 +60,10 @@ urlpatterns = [ url(r'^course_modules/(?P\d+)/$', views.course_modules, name='course_modules'), url(r'^forum/(?P\d+)/$', views.course_forum, name='course_forum'), - url(r'^forum/(?P\d+)/thread/(?P[0-9a-f-]+)/', views.thread_comments, name='thread_comments'), - url(r'^forum/(?P\d+)/thread/(?P[0-9a-f-]+)/delete/', views.delete_thread, name='delete_thread'), + url(r'^forum/(?P\d+)/thread/(?P[0-9a-f-]+)/$', views.thread_comments, name='thread_comments'), + url(r'^forum/(?P\d+)/thread/(?P[0-9a-f-]+)/delete/', views.hide_thread, name='hide_thread'), + url(r'^forum/(?P\d+)/comment/(?P[0-9a-f-]+)/delete/', views.hide_comment, name='hide_comment'), + url(r'^manage/$', views.prof_manage, name='manage'), url(r'^manage/addquestion/$', views.add_question, name="add_question"), url(r'^manage/addquestion/(?P\d+)/$', views.add_question, diff --git a/yaksh/views.py b/yaksh/views.py index afa21df..0567f3d 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3198,7 +3198,7 @@ def download_course_progress(request, course_id): def course_forum(request, course_id): user = request.user course = get_object_or_404(Course, id=course_id) - threads = course.thread.all().order_by('-modified_at') + threads = course.thread.filter(active=True).order_by('-modified_at') if request.method == "POST": form = ThreadForm(request.POST, request.FILES) if form.is_valid(): @@ -3214,13 +3214,15 @@ def course_forum(request, course_id): 'user': user, 'course': course, 'threads': threads, - 'form': form + 'form': form, + 'user': user }) @login_required @email_verified def thread_comments(request, course_id, uuid): + user = request.user thread = get_object_or_404(Thread, uid=uuid) comments = thread.comment.filter(active=True) form = CommentForm() @@ -3235,11 +3237,24 @@ def thread_comments(request, course_id, uuid): return render(request, 'yaksh/thread_comments.html', { 'thread': thread, 'comments': comments, - 'form': form + 'form': form, + 'user': user }) @login_required @email_verified -def delete_thread(request, course_id, uuid): +def hide_thread(request, course_id, uuid): thread = get_object_or_404(Thread, uid=uuid) + thread.comment.active = False + thread.active = False + thread.save() + return redirect('yaksh:course_forum', course_id) + + +def hide_comment(request, course_id, uuid): + comment = get_object_or_404(Comment, uid=uuid) + thread_uid = comment.thread_field.uid + comment.active = False + comment.save() + return redirect('yaksh:thread_comments', course_id, thread_uid) -- cgit