From 8835afbc95c1a398cf62da7880596e7a302ae148 Mon Sep 17 00:00:00 2001 From: manojvaghela Date: Wed, 18 Mar 2020 16:36:52 +0530 Subject: Search bar added --- yaksh/forms.py | 19 +++++++++ yaksh/templates/yaksh/courses.html | 28 +++++++++++- yaksh/templates/yaksh/lessons.html | 30 ++++++++++++- yaksh/templates/yaksh/modules.html | 30 ++++++++++++- yaksh/templates/yaksh/quizzes.html | 30 ++++++++++++- yaksh/views.py | 87 +++++++++++++++++++++++++++++++++++--- 6 files changed, 212 insertions(+), 12 deletions(-) diff --git a/yaksh/forms.py b/yaksh/forms.py index 7d5362b..c0f40ea 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -49,6 +49,12 @@ test_case_types = ( ("floattestcase", "Float Testcase"), ) +status_types = ( + ('select','Select Status'), + ('active', 'Active'), + ('closed', 'Inactive'), + ) + UNAME_CHARS = letters + "._" + digits PWD_CHARS = letters + punctuation + digits @@ -377,6 +383,19 @@ class QuestionFilterForm(forms.Form): ) +class SearchFilterForm(forms.Form): + search_tags = forms.CharField( + label='Search Tags', + widget=forms.TextInput(attrs={'placeholder': 'Search', + 'class': form_input_class,}), + required=False + ) + search_status = forms.CharField(max_length=16, widget=forms.Select( + choices=status_types, + attrs={'class': 'custom-select'}), + ) + + class CourseForm(forms.ModelForm): """ course form for moderators """ class Meta: diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 0eb9a38..cc4c69f 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -61,6 +61,32 @@ {% else %}
+
+ {% csrf_token %} +
+
+

Search/Filter Courses

+
+
+
+
+ {{ form.search_tags }} +
+
+ {{ form.search_status }} +
+
+
+ + +
+
+
+
+

{{ courses_found }} Course(s) Available

+ {% if messages %} {% for message in messages %}
@@ -198,7 +224,7 @@
{% for course in courses %}
-
+
{{course.name}} diff --git a/yaksh/templates/yaksh/lessons.html b/yaksh/templates/yaksh/lessons.html index 0146a6b..c806d26 100644 --- a/yaksh/templates/yaksh/lessons.html +++ b/yaksh/templates/yaksh/lessons.html @@ -45,10 +45,36 @@ {% if not lessons %}

-

No new Lessons added

+

No lessons found

{% else %} -

Lessons

+
+
+ {% csrf_token %} +
+
+

Search/Filter Lessons

+
+
+
+
+ {{ form.search_tags }} +
+
+ {{ form.search_status }} +
+
+
+ + +
+
+
+
+

{{ lessons_found }} Lesson(s) Available

+ diff --git a/yaksh/templates/yaksh/modules.html b/yaksh/templates/yaksh/modules.html index 4fafbf1..610960c 100644 --- a/yaksh/templates/yaksh/modules.html +++ b/yaksh/templates/yaksh/modules.html @@ -46,10 +46,36 @@ {% if not modules %}

-

No new learning modules added

+

No learning modules found

{% else %} -

Learning Modules

+
+ + {% csrf_token %} +
+
+

Search/Filter Learning Modules

+
+
+
+
+ {{ form.search_tags }} +
+
+ {{ form.search_status }} +
+
+
+ + +
+
+ +
+

{{ modules_found }} Learning Module(s) Available

+
Sr.No
diff --git a/yaksh/templates/yaksh/quizzes.html b/yaksh/templates/yaksh/quizzes.html index 7e53d31..7532940 100644 --- a/yaksh/templates/yaksh/quizzes.html +++ b/yaksh/templates/yaksh/quizzes.html @@ -49,10 +49,36 @@ {% if not quizzes %}

-

No new Quiz added

+

No quizzes found

{% else %} -

Quizzes

+
+ + {% csrf_token %} +
+
+

Search/Filter Quizzes

+
+
+
+
+ {{ form.search_tags }} +
+
+ {{ form.search_status }} +
+
+
+ + +
+
+ +
+

{{ quizzes_found }} Quiz(zes) Available

+
Sr.No
diff --git a/yaksh/views.py b/yaksh/views.py index 58fe6e2..cf7f3b4 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -44,7 +44,8 @@ from yaksh.forms import ( UserRegisterForm, UserLoginForm, QuizForm, QuestionForm, QuestionFilterForm, CourseForm, ProfileForm, UploadFileForm, FileForm, QuestionPaperForm, LessonForm, - LessonFileForm, LearningModuleForm, ExerciseForm, TestcaseForm + LessonFileForm, LearningModuleForm, ExerciseForm, TestcaseForm, + SearchFilterForm ) from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from .settings import URL_ROOT @@ -1046,6 +1047,23 @@ def courses(request): courses = Course.objects.filter( Q(creator=user) | Q(teachers=user), is_trial=False).order_by('-active').distinct() + + form = SearchFilterForm() + + if request.method == 'POST': + course_tags = request.POST.get('search_tags') + course_status = request.POST.get('search_status') + + if course_status == 'select' : + courses = courses.filter( + name__contains=course_tags) + elif course_status == 'active' : + courses = courses.filter( + name__contains=course_tags, active=True) + elif course_status == 'closed': + courses = courses.filter( + name__contains=course_tags, active=False) + paginator = Paginator(courses, 30) page = request.GET.get('page') try: @@ -1056,7 +1074,9 @@ def courses(request): except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. courses = paginator.page(paginator.num_pages) - context = {'objects': courses, 'created': True} + courses_found = courses.object_list.count() + context = {'objects': courses, 'created': True, + 'form': form, 'courses_found': courses_found} return my_render_to_response(request, 'yaksh/courses.html', context) @@ -2729,7 +2749,26 @@ def show_all_quizzes(request): if not is_moderator(user): raise Http404('You are not allowed to view this page!') quizzes = Quiz.objects.filter(creator=user, is_trial=False) - context = {"quizzes": quizzes} + + form = SearchFilterForm() + + if request.method == 'POST': + quiz_tags = request.POST.get('search_tags') + quiz_status = request.POST.get('search_status') + + if quiz_status == 'select' : + quizzes = quizzes.filter( + description__contains=quiz_tags) + elif quiz_status == 'active' : + quizzes = quizzes.filter( + description__contains=quiz_tags, active=True) + elif quiz_status == 'closed': + quizzes = quizzes.filter( + description__contains=quiz_tags, active=False) + quizzes_found = quizzes.count() + + context = {"quizzes": quizzes, "form": form, + "quizzes_found": quizzes_found} return my_render_to_response(request, 'yaksh/quizzes.html', context) @@ -2740,7 +2779,26 @@ def show_all_lessons(request): if not is_moderator(user): raise Http404('You are not allowed to view this page!') lessons = Lesson.objects.filter(creator=user) - context = {"lessons": lessons} + + form = SearchFilterForm() + + if request.method == 'POST': + lesson_tags = request.POST.get('search_tags') + lesson_status = request.POST.get('search_status') + + if lesson_status == 'select' : + lessons = lessons.filter( + description__contains=lesson_tags) + elif lesson_status == 'active' : + lessons = lessons.filter( + description__contains=lesson_tags, active=True) + elif lesson_status == 'closed': + lessons = lessons.filter( + description__contains=lesson_tags, active=False) + lessons_found = lessons.count() + + context = {"lessons": lessons, "form": form, + "lessons_found": lessons_found} return my_render_to_response(request, 'yaksh/lessons.html', context) @@ -2752,7 +2810,26 @@ def show_all_modules(request): raise Http404('You are not allowed to view this page!') learning_modules = LearningModule.objects.filter( creator=user, is_trial=False) - context = {"modules": learning_modules} + + form = SearchFilterForm() + + if request.method == 'POST': + module_tags = request.POST.get('search_tags') + module_status = request.POST.get('search_status') + + if module_status == 'select' : + learning_modules = learning_modules.filter( + name__contains=module_tags) + elif module_status == 'active' : + learning_modules = learning_modules.filter( + name__contains=module_tags, active=True) + elif module_status == 'closed': + learning_modules = learning_modules.filter( + name__contains=module_tags, active=False) + learning_modules_found = learning_modules.count() + + context = {"modules": learning_modules, "form": form, + "modules_found": learning_modules_found} return my_render_to_response( request, 'yaksh/modules.html', context ) -- cgit
Sr.No