From e261686554ad339449ba9fec6c2391faaefc0eff Mon Sep 17 00:00:00 2001
From: CruiseDevice
Date: Sun, 26 Apr 2020 22:21:41 +0530
Subject: Add search bar in forum to search posts
---
yaksh/templates/yaksh/course_forum.html | 28 +++++++++++++++++++++-------
yaksh/views.py | 7 +++++--
2 files changed, 26 insertions(+), 9 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html
index bf098d3..dea4d8f 100644
--- a/yaksh/templates/yaksh/course_forum.html
+++ b/yaksh/templates/yaksh/course_forum.html
@@ -9,13 +9,27 @@
{{course.name}}
Discussion Forum
- {% if moderator %}
- Back to Course
- {% else %}
- Back to Course
- {% endif %}
-
-
+
diff --git a/yaksh/views.py b/yaksh/views.py
index cd53d55..be33a5e 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -3206,8 +3206,11 @@ def course_forum(request, course_id):
if (not course.is_creator(user) and not course.is_teacher(user)
and not course.is_student(user)):
raise Http404('You are not enrolled in {0} course'.format(course.name))
- sort = request.GET.get('desc')
- posts = course.post.filter(active=True).order_by('-modified_at')
+ if 'search' in request.GET:
+ search_term = request.GET['search']
+ posts = course.post.filter(active=True, title__icontains=search_term)
+ else:
+ posts = course.post.filter(active=True).order_by('-modified_at')
paginator = Paginator(posts, 10)
page = request.GET.get('page')
posts = paginator.get_page(page)
--
cgit