From bfd33c397d30c60cde16d5073382bdae94d475cd Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 27 Apr 2020 14:48:12 +0530 Subject: Fix pagination for forum post search --- yaksh/templates/yaksh/course_forum.html | 52 ++++++++++++++++++++++---------- yaksh/templates/yaksh/paginator.html | 6 ++-- yaksh/templates/yaksh/post_comments.html | 7 +++-- yaksh/views.py | 13 ++++---- 4 files changed, 51 insertions(+), 27 deletions(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html index e6b6a90..4724981 100644 --- a/yaksh/templates/yaksh/course_forum.html +++ b/yaksh/templates/yaksh/course_forum.html @@ -12,23 +12,19 @@
{% if moderator %} - Back to Course + +  Back + {% else %} - Back to Course + +  Back + {% endif %}
-
-
-
- - - - -
-
-
-
- +
+
@@ -58,12 +54,34 @@

+
+
+
+
+ + + + +
+
+
+
+ +  Clear Search + +
+

+ {% with objects as posts %} {% if posts %} + {% include "yaksh/paginator.html" %} +
- + @@ -98,10 +116,12 @@ {% endfor %}
QuestionsPosts Created by Replies Last reply
+
+ {% include "yaksh/paginator.html" %} {% else %} No discussion posts are there yet. Create one to start discussing. {% endif %} - {% include "yaksh/paginator.html" %} + {% endwith %} {% endblock content %} {% block script %} diff --git a/yaksh/templates/yaksh/paginator.html b/yaksh/templates/yaksh/paginator.html index e958519..e18cbce 100644 --- a/yaksh/templates/yaksh/paginator.html +++ b/yaksh/templates/yaksh/paginator.html @@ -2,7 +2,7 @@ {% if objects.has_previous %}
  • + {% if request.GET.search_tags %}&search_tags={{ request.GET.search_tags }}{% endif %}{% if request.GET.search_status %}&search_status={{ request.GET.search_status }}{% endif %}{% if request.GET.search_post %}&search_post={{ request.GET.search_post }}{% endif %}" aria-label="Previous"> @@ -17,13 +17,13 @@ {{ n }}(current)
  • {% elif n > objects.number|add:'-5' and n < objects.number|add:'5' %} -
  • {{ n }}
  • +
  • {{ n }}
  • {% endif %} {% endfor %} {% if objects.has_next %}
  • - + diff --git a/yaksh/templates/yaksh/post_comments.html b/yaksh/templates/yaksh/post_comments.html index 463103e..b16b80c 100644 --- a/yaksh/templates/yaksh/post_comments.html +++ b/yaksh/templates/yaksh/post_comments.html @@ -6,7 +6,9 @@ {% block content %}
    - Back to Posts + +  Back to Posts +

    @@ -56,12 +58,13 @@ {% endif %}
    + Add comment:
    {% csrf_token %} {{form}}
    - +
    diff --git a/yaksh/views.py b/yaksh/views.py index 397e7c8..36a2fd2 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3291,12 +3291,14 @@ 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)) - if 'search' in request.GET: - search_term = request.GET['search'] - posts = course.post.filter(active=True, title__icontains=search_term) + search_term = request.GET.get('search_post') + if search_term: + posts = course.post.get_queryset().filter( + active=True, title__icontains=search_term) else: - posts = course.post.filter(active=True).order_by('-modified_at') - paginator = Paginator(posts, 10) + posts = course.post.get_queryset().filter( + active=True).order_by('-modified_at') + paginator = Paginator(posts, 1) page = request.GET.get('page') posts = paginator.get_page(page) if request.method == "POST": @@ -3314,7 +3316,6 @@ def course_forum(request, course_id): 'user': user, 'course': course, 'base_template': base_template, - 'posts': posts, 'moderator': moderator, 'objects': posts, 'form': form, -- cgit