diff options
author | manojvaghela | 2020-03-18 16:36:52 +0530 |
---|---|---|
committer | manojvaghela | 2020-03-18 16:45:42 +0530 |
commit | 8835afbc95c1a398cf62da7880596e7a302ae148 (patch) | |
tree | 6eb2193f420eb5da143d3569026fc9ff1387f219 | |
parent | 15ce39acb70056bdfb9820efa634d704a963cb84 (diff) | |
download | online_test-8835afbc95c1a398cf62da7880596e7a302ae148.tar.gz online_test-8835afbc95c1a398cf62da7880596e7a302ae148.tar.bz2 online_test-8835afbc95c1a398cf62da7880596e7a302ae148.zip |
Search bar added
-rw-r--r-- | yaksh/forms.py | 19 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 28 | ||||
-rw-r--r-- | yaksh/templates/yaksh/lessons.html | 30 | ||||
-rw-r--r-- | yaksh/templates/yaksh/modules.html | 30 | ||||
-rw-r--r-- | yaksh/templates/yaksh/quizzes.html | 30 | ||||
-rw-r--r-- | 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 @@ </div> {% else %} <hr> + <form name=frm action="" method="post"> + {% csrf_token %} + <div class="card"> + <div class="card-header"> + <h3>Search/Filter Courses</h3> + </div> + <div class="card-body"> + <div class="row"> + <div class="col-md-6"> + {{ form.search_tags }} + </div> + <div class="col-md-3"> + {{ form.search_status }} + </div> + </div> + <br> + <button class="btn btn-success" type="submit">Search</button> + <button class="btn btn-primary" href="{% url 'yaksh:courses' %}"> + Clear Search + </button> + </div> + </div> + </form> + <hr> + <center><h4 class="badge badge-success">{{ courses_found }} Course(s) Available</h4></center> + {% if messages %} {% for message in messages %} <div class="alert alert-dismissible alert-{{ message.tags }}"> @@ -198,7 +224,7 @@ <br> {% for course in courses %} <div class="card"> - <div class="card-header"> + <div class="card-header bg-secondary"> <div class="row"> <div class="col-md-5"> {{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 %} <br><br> <div class="alert alert-info"> - <center><h3> No new Lessons added</h3></center> + <center><h3> No lessons found</h3></center> </div> {% else %} - <center><h3> Lessons </h3></center> + <hr> + <form name=frm action="" method="post"> + {% csrf_token %} + <div class="card"> + <div class="card-header"> + <h3> Search/Filter Lessons </h3> + </div> + <div class="card-body"> + <div class="row"> + <div class="col-md-6"> + {{ form.search_tags }} + </div> + <div class="col-md-3"> + {{ form.search_status }} + </div> + </div> + <br> + <button class="btn btn-success" type="submit">Search</button> + <button class="btn btn-primary" href="{% url 'yaksh:show_all_lessons' %}"> + Clear Search + </button> + </div> + </div> + </form> + <hr> + <center><h4 class="badge badge-success">{{ lessons_found }} Lesson(s) Available</h4></center> + <table id="course-details" class="table table-bordered table-responsive-sm"> <tr> <th>Sr.No</th> 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 %} <br><br> <div class="alert alert-info"> - <center><h3> No new learning modules added</h3></center> + <center><h3> No learning modules found</h3></center> </div> {% else %} - <center><h3> Learning Modules </h3></center> + <hr> + <form name=frm action="" method="post"> + {% csrf_token %} + <div class="card"> + <div class="card-header"> + <h3> Search/Filter Learning Modules </h3> + </div> + <div class="card-body"> + <div class="row"> + <div class="col-md-6"> + {{ form.search_tags }} + </div> + <div class="col-md-3"> + {{ form.search_status }} + </div> + </div> + <br> + <button class="btn btn-success" type="submit">Search</button> + <button class="btn btn-primary" href="{% url 'yaksh:show_all_modules' %}"> + Clear Search + </button> + </div> + </div> + </form> + <hr> + <center><h4 class="badge badge-success">{{ modules_found }} Learning Module(s) Available</h4></center> + <table class="table table-bordered table-responsive-sm"> <tr> <th>Sr.No</th> 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 %} <br><br> <div class="alert alert-info"> - <center><h3> No new Quiz added</h3></center> + <center><h3> No quizzes found</h3></center> </div> {% else %} - <center><h3> Quizzes </h3></center> + <hr> + <form name=frm action="" method="post"> + {% csrf_token %} + <div class="card"> + <div class="card-header"> + <h3> Search/Filter Quizzes </h3> + </div> + <div class="card-body"> + <div class="row"> + <div class="col-md-6"> + {{ form.search_tags }} + </div> + <div class="col-md-3"> + {{ form.search_status }} + </div> + </div> + <br> + <button class="btn btn-success" type="submit">Search</button> + <button class="btn btn-primary" href="{% url 'yaksh:show_all_quizzes' %}"> + Clear Search + </button> + </div> + </div> + </form> + <hr> + <center><h4 class="badge badge-success">{{ quizzes_found }} Quiz(zes) Available</h4></center> + <table class="table table-bordered table-responsive-sm"> <tr> <th>Sr.No</th> 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 ) |