summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCruiseDevice2020-04-13 17:27:49 +0530
committerCruiseDevice2020-04-13 17:27:49 +0530
commit2f9331717075b34534f2745706f57a98f7dce20d (patch)
treee942155f11e47299d7deb5447267c0055e49d4de
parent0e6c7d589114450d5cd1bc581ee1692c235f1a73 (diff)
downloadonline_test-2f9331717075b34534f2745706f57a98f7dce20d.tar.gz
online_test-2f9331717075b34534f2745706f57a98f7dce20d.tar.bz2
online_test-2f9331717075b34534f2745706f57a98f7dce20d.zip
Add feature to hide thread or comments
-rw-r--r--yaksh/models.py2
-rw-r--r--yaksh/templates/yaksh/course_forum.html4
-rw-r--r--yaksh/templates/yaksh/thread_comments.html12
-rw-r--r--yaksh/urls.py6
-rw-r--r--yaksh/views.py23
5 files changed, 37 insertions, 10 deletions
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 %}
<small> {% if thread.creator.profile.is_moderator %} INSTRUCTOR CREATED {% endif %} Last Post by: <strong>{{last_comment.creator}}</strong> . {{last_comment.modified_at|naturaltime}}</small>
{% endwith %}
- <small><a href="{% url "yaksh:delete_thread" course.id thread.uid %}" class="pull-right">Delete</i></a></small>
+ {% if user.profile.is_moderator %}
+ <small><a href="{% url "yaksh:hide_thread" course.id thread.uid %}" class="pull-right">Delete</i></a></small>
+ {% endif %}
</div>
</div>
<br>
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 @@
<div class="card-header">
{{thread.title}}
<br>
- <small><strong>{{thread.creator.username}}</strong> {{thread.created_at}}</small>
+ <small>
+ <strong>{{thread.creator.username}}</strong>
+ {{thread.created_at}}
+ {% if user.profile.is_moderator %}<a href="{% url "yaksh:hide_thread" thread.course.id thread.uid %}" class="pull-right">Delete</a>{% endif %}
+ </small>
+
</div>
<div class="card-body">
<p>{{thread.description}}</p>
@@ -29,7 +34,10 @@
</a>
{% endif %}
<p>{{comment.description}}</p>
- <small class="pull-right">by: <strong>{{comment.user.username}} </strong>. {{comment.created_at}}</small>
+ <small class="pull-right">
+ by: <strong>{{comment.creator.username}} </strong>. {{comment.created_at}}
+ {% if user.profile.is_moderator %}<a href="{% url "yaksh:hide_comment" thread.course.id comment.uid %}">Delete</a>{% endif %}
+ </small>
</div>
<hr>
{% 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<course_id>\d+)/$',
views.course_modules, name='course_modules'),
url(r'^forum/(?P<course_id>\d+)/$', views.course_forum, name='course_forum'),
- url(r'^forum/(?P<course_id>\d+)/thread/(?P<uuid>[0-9a-f-]+)/', views.thread_comments, name='thread_comments'),
- url(r'^forum/(?P<course_id>\d+)/thread/(?P<uuid>[0-9a-f-]+)/delete/', views.delete_thread, name='delete_thread'),
+ url(r'^forum/(?P<course_id>\d+)/thread/(?P<uuid>[0-9a-f-]+)/$', views.thread_comments, name='thread_comments'),
+ url(r'^forum/(?P<course_id>\d+)/thread/(?P<uuid>[0-9a-f-]+)/delete/', views.hide_thread, name='hide_thread'),
+ url(r'^forum/(?P<course_id>\d+)/comment/(?P<uuid>[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<question_id>\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)