diff options
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/live_server_tests/load_test.py | 41 | ||||
-rw-r--r-- | yaksh/live_server_tests/selenium_test.py | 50 | ||||
-rw-r--r-- | yaksh/static/yaksh/js/add_lesson.js | 11 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_module.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/course_modules.html | 112 | ||||
-rw-r--r-- | yaksh/templates/yaksh/intro.html | 14 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/quizzes_user.html | 77 | ||||
-rw-r--r-- | yaksh/templates/yaksh/show_video.html | 8 | ||||
-rw-r--r-- | yaksh/test_views.py | 83 | ||||
-rw-r--r-- | yaksh/urls.py | 2 | ||||
-rw-r--r-- | yaksh/views.py | 38 |
12 files changed, 303 insertions, 137 deletions
diff --git a/yaksh/live_server_tests/load_test.py b/yaksh/live_server_tests/load_test.py index c3eb6e6..520bebe 100644 --- a/yaksh/live_server_tests/load_test.py +++ b/yaksh/live_server_tests/load_test.py @@ -1,17 +1,10 @@ -import os -import signal -import subprocess -from datetime import datetime -import pytz from threading import Thread -from selenium.webdriver.firefox.webdriver import WebDriver - from django.contrib.staticfiles.testing import StaticLiveServerTestCase -from yaksh.models import User, Profile, Question, Quiz, Course, QuestionPaper, TestCase +# Local imports +from yaksh.models import User, Profile, Course from yaksh.code_server import ServerPool from yaksh import settings - from .selenium_test import SeleniumTest @@ -33,20 +26,24 @@ class YakshSeleniumTests(StaticLiveServerTestCase): cls.code_server_thread = t = Thread(target=code_server_pool.run) t.start() - cls.demo_student = User.objects.create_user(username='demo_student', - password='demo_student', - email='demo_student@test.com' + cls.demo_student = User.objects.create_user( + username='demo_student', + password='demo_student', + email='demo_student@test.com' ) - cls.demo_student_profile = Profile.objects.create(user=cls.demo_student, + cls.demo_student_profile = Profile.objects.create( + user=cls.demo_student, roll_number=3, institute='IIT', department='Chemical', position='Student' ) - cls.demo_mod = User.objects.create_user(username='demo_mod', - password='demo_mod', - email='demo_mod@test.com' + cls.demo_mod = User.objects.create_user( + username='demo_mod', + password='demo_mod', + email='demo_mod@test.com' ) - cls.demo_mod_profile = Profile.objects.create(user=cls.demo_mod, + cls.demo_mod_profile = Profile.objects.create( + user=cls.demo_mod, roll_number=0, institute='IIT', department='Chemical', position='Moderator' ) @@ -73,7 +70,11 @@ class YakshSeleniumTests(StaticLiveServerTestCase): def test_load(self): url = '%s%s' % (self.live_server_url, '/exam/login/') quiz_name = "Yaksh Demo quiz" - module_name = "demo module" + module_name = "Demo Module" + course_name = "Yaksh Demo course" selenium_test = SeleniumTest(url=url, quiz_name=quiz_name, - module_name=module_name) - selenium_test.run_load_test(url=url, username='demo_student', password='demo_student') + module_name=module_name, + course_name=course_name) + selenium_test.run_load_test( + url=url, username='demo_student', password='demo_student' + ) diff --git a/yaksh/live_server_tests/selenium_test.py b/yaksh/live_server_tests/selenium_test.py index 160ad02..0d9e8b8 100644 --- a/yaksh/live_server_tests/selenium_test.py +++ b/yaksh/live_server_tests/selenium_test.py @@ -1,9 +1,7 @@ from selenium import webdriver -from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC -from selenium.common.exceptions import WebDriverException import multiprocessing import argparse @@ -18,18 +16,20 @@ class ElementDisplay(object): try: element = EC._find_element(driver, self.locator) return element.value_of_css_property("display") == "none" - except Exception as e: + except Exception: return False class SeleniumTestError(Exception): pass + class SeleniumTest(): - def __init__(self, url, quiz_name, module_name): + def __init__(self, url, quiz_name, module_name, course_name): self.driver = webdriver.Firefox() self.quiz_name = quiz_name self.module_name = module_name + self.course_name = course_name self.url = url def run_load_test(self, url, username, password): @@ -43,10 +43,10 @@ class SeleniumTest(): self.logout() self.driver.close() except Exception as e: - self.driver.close() + # self.driver.close() msg = ("An Error occurred while running the Selenium load" - " test on Yaksh!\n" - "Error:\n{0}".format(e)) + " test on Yaksh!\n" + "Error:\n{0}".format(e)) raise SeleniumTestError(msg) @@ -54,7 +54,8 @@ class SeleniumTest(): # get the username, password and submit form elements username_elem = self.driver.find_element_by_id("id_username") password_elem = self.driver.find_element_by_id("id_password") - submit_login_elem = self.driver.find_element_by_css_selector('button.btn') + submit_login_elem = self.driver.find_element_by_css_selector( + 'button.btn') # Type in the username, password and submit form username_elem.send_keys(username) @@ -66,7 +67,8 @@ class SeleniumTest(): for count in range(loop_count): self.driver.find_element_by_link_text(question_label).click() submit_answer_elem = self.driver.find_element_by_id("check") - self.driver.execute_script('global_editor.editor.setValue({});'.format(answer)) + self.driver.execute_script( + 'global_editor.editor.setValue({});'.format(answer)) submit_answer_elem.click() WebDriverWait(self.driver, 90).until(ElementDisplay( (By.XPATH, "//*[@id='ontop']"))) @@ -121,10 +123,12 @@ class SeleniumTest(): def open_quiz(self): # open module link + self.driver.find_elements_by_partial_link_text( + self.course_name)[0].click() self.driver.find_element_by_link_text(self.module_name).click() # open quiz link - quiz_link_elem = self.driver.find_element_by_link_text(self.quiz_name).click() - + self.driver.find_element_by_link_text(self.quiz_name).click() + # Get page elements start_exam_elem = WebDriverWait(self.driver, 5).until( EC.presence_of_element_located((By.NAME, "start")) @@ -158,8 +162,10 @@ class SeleniumTest(): ) logout_link_elem.click() + def user_gen(url, ids): - return [(url, 'User%d'%x, 'User%d'%x) for x in ids] + return [(url, 'User%d' % x, 'User%d' % x) for x in ids] + def wrap_run_load_test(args): url = "http://yaksh.fossee.aero.iitb.ac.in/exam/" @@ -168,17 +174,25 @@ def wrap_run_load_test(args): if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('url', type=str, help="url of the website being tested") + parser.add_argument( + 'url', type=str, help="url of the website being tested" + ) parser.add_argument('start', type=int, help="Starting user id") - parser.add_argument("-n", "--number", type=int, default=10, help="number of users") + parser.add_argument( + "-n", "--number", type=int, default=10, help="number of users" + ) opts = parser.parse_args() quiz_name = "Demo quiz" - module_name = "demo module" + module_name = "Demo Module" + course_name = "Yaksh Demo course" selenium_test = SeleniumTest(url=opts.url, quiz_name=quiz_name, - module_name=module_name) + module_name=module_name, + course_name=course_name) pool = multiprocessing.Pool(opts.number) - pool.map(wrap_run_load_test, user_gen(opts.url, range(opts.start, opts.start + opts.number))) + pool.map( + wrap_run_load_test, + user_gen(opts.url, range(opts.start, opts.start + opts.number)) + ) pool.close() pool.join() - diff --git a/yaksh/static/yaksh/js/add_lesson.js b/yaksh/static/yaksh/js/add_lesson.js deleted file mode 100644 index 4ad6e4d..0000000 --- a/yaksh/static/yaksh/js/add_lesson.js +++ /dev/null @@ -1,11 +0,0 @@ -$(document).ready(function(){ - $("#submit").click(function(){ - var selected_quiz = $("#id_quiz :selected").text(); - var video_session = $("#id_video_session").val(); - if(selected_quiz == "---------" && video_session.length == 0) { - $("#alert").toggle(); - return false; - } - return true; - }); -});
\ No newline at end of file diff --git a/yaksh/templates/yaksh/add_module.html b/yaksh/templates/yaksh/add_module.html index 499646b..07fcb5f 100644 --- a/yaksh/templates/yaksh/add_module.html +++ b/yaksh/templates/yaksh/add_module.html @@ -36,7 +36,7 @@ <button class="btn" type="submit" id="submit" name="Save"> Save </button> <button class="btn" type="button" name="button" id="preview"> - Preview Lesson Description + Preview Module Description </button> </center> </form> diff --git a/yaksh/templates/yaksh/course_modules.html b/yaksh/templates/yaksh/course_modules.html new file mode 100644 index 0000000..4933113 --- /dev/null +++ b/yaksh/templates/yaksh/course_modules.html @@ -0,0 +1,112 @@ +{% extends "user.html" %} +{% load custom_filters %} +{% block title %} Course Modules {% endblock %} +{% block pagetitle %} Curriculum for {{course}} {% endblock %} +{% block script %} +<script> + function view_unit(unit){ + $("#"+unit+"_down").toggle(); + $("#"+unit+"_up").toggle(); + } + +</script> +{% endblock %} +{% block main %} +{% if msg %} + <div class="alert alert-warning" role="alert"> + <center>{{ msg }}</center> + </div> +{% endif %} +{% if learning_modules %} + {% for module in learning_modules %} + <div class="row well"> + <table class="table"> + <tr> + <td> + <a href="{{URL_ROOT}}/exam/quizzes/view_module/{{module.id}}/{{course.id}}"> + {{module.name|title}}</a> + </td> + <td> + <span class="glyphicon glyphicon-chevron-down" id="learning_units{{module.id}}{{course.id}}_down"> + </span> + <span class="glyphicon glyphicon-chevron-up" id="learning_units{{module.id}}{{course.id}}_up" style="display: none;"></span> + <a data-toggle="collapse" data-target="#learning_units{{module.id}}{{course.id}}" onclick="view_unit('learning_units{{module.id}}{{course.id}}');"> + View Lessons/Quizzes</a> + </td> + <td> + {% get_module_status user module course as module_status %} + Status: + {% if module_status == "completed" %} + <span class="label label-success"> + {{module_status|title}} + </span> + {% elif module_status == "inprogress" %} + <span class="label label-info"> + {{module_status|title}} + </span> + {% else %} + <span class="label label-warning"> + {{module_status|title}} + </span> + {% endif %} + </td> + </tr> + </table> + </div> + <div id="learning_units{{module.id}}{{course.id}}" class="collapse"> + <table class="table"> + <tr> + <th>Lesson/Quiz</th> + <th>Status</th> + <th>Type</th> + <th>View AnswerPaper</th> + </tr> + {% for unit in module.get_learning_units %} + <tr> + <ul class="inputs-list"> + <td> + {% if unit.learning_type == "quiz" %} + {{unit.quiz.description}} + {% else %} + {{unit.lesson.name}} + {% endif %} + </td> + <td> + {% get_unit_status course module unit user as status %} + {% if status == "completed" %} + <span class="label label-success">{{status|title}} + </span> + {% elif status == "inprogress" %} + <span class="label label-info">{{status|title}} + </span> + {% else %} + <span class="label label-warning">{{status|title}} + </span> + {% endif %} + </td> + <td> + {{unit.learning_type|title}} + </td> + <td> + {% if unit.learning_type == "quiz" %} + {% if unit.quiz.view_answerpaper %} + <a href="{{ URL_ROOT }}/exam/view_answerpaper/{{ unit.quiz.questionpaper_set.get.id }}/{{course.id}}"><i class="fa fa-eye" aria-hidden="true"></i> Can View </a> + {% else %} + <a> + <i class="fa fa-eye-slash" aria-hidden="true"> + </i> Cannot view now </a> + {% endif %} + {% else %} + ------ + {% endif %} + </td> + </ul> + </tr> + {% endfor %} + </table> + </div> + {% endfor %} +{% else %} + <h3> No lectures found </h3> +{% endif %} +{% endblock %}
\ No newline at end of file diff --git a/yaksh/templates/yaksh/intro.html b/yaksh/templates/yaksh/intro.html index 2d213b9..ca49d64 100644 --- a/yaksh/templates/yaksh/intro.html +++ b/yaksh/templates/yaksh/intro.html @@ -20,12 +20,22 @@ <br/> </div> {% endif %} - <p> Welcome <strong>{{user.first_name.title}} {{user.last_name.title}}</strong>, to the programming quiz! </p> + <p> Welcome <strong>{{user.get_full_name|title}}</strong>, to the programming quiz! </p> {{ questionpaper.quiz.instructions|safe }} <div class="row"> <div class="col-md-6"> <center> - <a href="{{URL_ROOT}}/exam" class="btn btn-primary" name="home">Home</a> + {% if status == "moderator" %} + <a href="{{URL_ROOT}}/exam/quizzes/view_module/{{module.id}}/{{course.id}}" class="btn btn-primary" name="home"> + <span class=" glyphicon glyphicon-arrow-left"> + </span> + Go Back</a> + {% else %} + <a href="{{URL_ROOT}}/exam" class="btn btn-primary" name="home"> + <span class=" glyphicon glyphicon-arrow-left"> + </span> + Go Back</a> + {% endif %} </center> </div> <div class="col-md-6"> diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 674fafc..6adda5b 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -106,7 +106,7 @@ module_id = "{{module.id}}" {% get_unit_status course module unit user as status %} {% if unit.quiz.id == paper.question_paper.quiz.id %} - <span class="glyphicon glyphicon-pencil" data-toggle="tooltip" title="Currently on"></span> + <span class=" glyphicon glyphicon-edit" data-toggle="tooltip" title="Currently on"></span> {% endif %} {% if unit.learning_type == "quiz" %} diff --git a/yaksh/templates/yaksh/quizzes_user.html b/yaksh/templates/yaksh/quizzes_user.html index 26e550d..cf08752 100644 --- a/yaksh/templates/yaksh/quizzes_user.html +++ b/yaksh/templates/yaksh/quizzes_user.html @@ -1,5 +1,4 @@ {% extends "user.html" %} -{% load custom_filters %} {% block title %} Student Dashboard {% endblock %} {% block pagetitle %} {{ title }} {% endblock %} {% block main %} @@ -33,7 +32,11 @@ No Courses to display <div class="col-md-12"> <div class="row"> <div class="col-md-4"> - <h4><b><u> {{ course.name }} by {{ course.creator.get_full_name }}</u></b></h4> + <h4><b> + <a href="{{URL_ROOT}}/exam/course_modules/{{course.id}}"> + {{ course.name }} by {{ course.creator.get_full_name }} + </a> + </b></h4> </div> <div class="col-md-4"> {% if not course.active %} @@ -56,76 +59,6 @@ No Courses to display </div> </div> - <div class="row"> - {% if user in course.students.all and course.get_learning_modules %} - <table class="table table-bordered"> - <th>Learning Modules</th> - <th>Learning Units</th> - <th>Status</th> - {% for module in course.get_learning_modules %} - <tr> - <td> - <a href="{{URL_ROOT}}/exam/quizzes/view_module/{{module.id}}/{{course.id}}"> - {{module.name}}</a> - </td> - <td> - <a data-toggle="collapse" data-target="#learning_units{{module.id}}{{course.id}}"> - <span class="glyphicon glyphicon-chevron-down"> - View Learning Units</span></a> - <div id="learning_units{{module.id}}{{course.id}}" class="collapse"> - <table class="table table-bordered"> - <th>Lesson/quiz</th> - <th>status</th> - <th>View Answerpaper</th> - {% for unit in module.get_learning_units %} - <tr> - <ul class="inputs-list"> - <td> - {% if unit.learning_type == "quiz" %} - {{unit.quiz.description}} - {% else %} - {{unit.lesson.name}} - {% endif %} - </td> - <td> - {% get_unit_status course module unit user as status %} - {% if status == "completed" %} - <span class="label label-info">{{status|title}}</span> - {% else %} - <span class="label label-warning">{{status|title}}</span> - {% endif %} - </td> - <td> - {% if unit.learning_type == "quiz" %} - {% if unit.quiz.view_answerpaper %} - <a href="{{ URL_ROOT }}/exam/view_answerpaper/{{ unit.quiz.questionpaper_set.get.id }}/{{course.id}}"><i class="fa fa-eye" aria-hidden="true"></i> Can View </a> - {% else %} - <a><i class="fa fa-eye-slash" aria-hidden="true"></i> Cannot view now </a> - {% endif %} - {% else %} - ------ - {% endif %} - </td> - </ul> - </tr> - {% endfor %} - </table> - </div> - </td> - <td> - {% get_module_status user module course as module_status %} - {% if module_status == "completed" %} - <span class="label label-info">{{module_status|title}}</span> - {% else %} - <span class="label label-warning">{{module_status|title}}</span> - {% endif %} - </td> - </tr> - {% endfor %} - </table> - {% endif %} - </div> - {% if course.instructions %} <div class="row"> <div class="panel-group"> diff --git a/yaksh/templates/yaksh/show_video.html b/yaksh/templates/yaksh/show_video.html index ff79808..1f80e71 100644 --- a/yaksh/templates/yaksh/show_video.html +++ b/yaksh/templates/yaksh/show_video.html @@ -1,9 +1,9 @@ {% extends "user.html" %} {% load custom_filters %} -{% block title %} {{ learning_module.name }} {% endblock %} +{% block title %} {{ learning_module.name|title }} {% endblock %} -{% block pagetitle %} {{ learning_module.name }} {% endblock %} +{% block pagetitle %} {{ learning_module.name|title }} {% endblock %} {% block usersidebar %} <br><br><br> @@ -15,7 +15,7 @@ {% get_unit_status course learning_module unit user as status %} {% if unit.id == current_unit.id %} - <span class="glyphicon glyphicon-pencil" data-toggle="tooltip" title="Currently on"> + <span class="glyphicon glyphicon-edit" data-toggle="tooltip" title="Currently on"> </span> {% endif %} {% if unit.learning_type == "quiz" %} @@ -54,7 +54,7 @@ </div> </div> <div style="text-align: center;"> - <a href="{{ URL_ROOT }}/exam/next_unit/{{course.id}}/{{learning_module.id}}/{{first_unit.id}}/1" class="btn btn-info">Next Unit + <a href="{{ URL_ROOT }}/exam/next_unit/{{course.id}}/{{learning_module.id}}/{{first_unit.id}}/1" class="btn btn-info">First Unit <span class="glyphicon glyphicon-chevron-right"> </span> </a> diff --git a/yaksh/test_views.py b/yaksh/test_views.py index a5bd25e..45d3314 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -1171,6 +1171,20 @@ class TestAddQuiz(TestCase): self.assertEqual(response.status_code, 302) self.assertRedirects(response, '/exam/manage/courses/all_quizzes/') + def test_show_all_quizzes(self): + self.client.login( + username=self.user.username, + password=self.user_plaintext_pass + ) + response = self.client.get( + reverse('yaksh:show_all_quizzes'), + follow=True + ) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['type'], "quiz") + self.assertEqual(response.context['quizzes'][0], self.quiz) + self.assertTemplateUsed(response, "yaksh/courses.html") + class TestAddTeacher(TestCase): def setUp(self): @@ -1524,6 +1538,14 @@ class TestCourses(TestCase): last_name='student_last_name', email='demo_student@test.com' ) + Profile.objects.create( + user=self.student, + roll_number=10, + institute='IIT', + department='Aeronautical', + position='Moderator', + timezone='UTC' + ) self.teacher_plaintext_pass = 'teacher' self.teacher = User.objects.create_user( @@ -1663,6 +1685,54 @@ class TestCourses(TestCase): self.assertTemplateUsed(response, 'yaksh/design_course_session.html') self.assertFalse(self.user1_course.learning_module.all().exists()) + def test_get_course_modules(self): + """ Test to check if student gets course modules """ + self.client.login( + username=self.student.username, + password=self.student_plaintext_pass + ) + response = self.client.get( + reverse('yaksh:course_modules', + kwargs={"course_id": self.user1_course.id}), + follow=True + ) + # Student is not allowed if not enrolled in the course + err_msg = "You are not enrolled for this course!" + self.assertEqual(response.context['msg'], err_msg) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "yaksh/quizzes_user.html") + + # enroll student in the course + self.user1_course.students.add(self.student) + # deactivate the course and check if student is able to view course + self.user1_course.active = False + self.user1_course.save() + response = self.client.get( + reverse('yaksh:course_modules', + kwargs={"course_id": self.user1_course.id}), + follow=True + ) + err_msg = "{0} is either expired or not active".format( + self.user1_course.name) + self.assertEqual(response.context['msg'], err_msg) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "yaksh/quizzes_user.html") + + # activate the course and check if students gets course modules + self.user1_course.active = True + self.user1_course.save() + self.user1_course.learning_module.add(self.learning_module) + response = self.client.get( + reverse('yaksh:course_modules', + kwargs={"course_id": self.user1_course.id}), + follow=True + ) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "yaksh/course_modules.html") + self.assertEqual(response.context['course'], self.user1_course) + self.assertEqual(response.context['learning_modules'][0], + self.learning_module) + class TestAddCourse(TestCase): def setUp(self): @@ -4624,3 +4694,16 @@ class TestLessons(TestCase): self.assertEqual(response.context["type"], "lesson") self.assertEqual(response.context["lessons"][0], self.lesson) + def test_preview_lesson_description(self): + """ Test preview lesson description converted from md to html""" + self.client.login( + username=self.teacher.username, + password=self.teacher_plaintext_pass + ) + lesson = json.dumps({'description': self.lesson.description}) + response = self.client.post( + reverse('yaksh:preview_html_text'), + data=lesson, content_type="application/json" + ) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()['data'], '<p>test description</p>') diff --git a/yaksh/urls.py b/yaksh/urls.py index dada74f..716a7d0 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -42,6 +42,8 @@ urlpatterns = [ views.get_next_unit, name='next_unit'), url(r'^next_unit/(?P<course_id>\d+)/(?P<module_id>\d+)/(?P<current_unit_id>\d+)/(?P<first_unit>\d+)/$', views.get_next_unit, name='next_unit'), + url(r'^course_modules/(?P<course_id>\d+)/$', + views.course_modules, name='course_modules'), 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 e0688f0..cfeb666 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -292,9 +292,9 @@ def add_quiz(request, quiz_id=None, course_id=None): ci = RequestContext(request) if not is_moderator(user): raise Http404('You are not allowed to view this course !') - if quiz_id and not course_id: + if quiz_id: quiz = get_object_or_404(Quiz, pk=quiz_id) - if quiz.creator != user: + if quiz.creator != user and not course_id: raise Http404('This quiz does not belong to you') else: quiz = None @@ -464,9 +464,12 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, ) # allowed to start if not quest_paper.can_attempt_now(user, course_id): + msg = "You cannot attempt {0} quiz more than {1} times".format( + quest_paper.quiz.description, quest_paper.quiz.attempts_allowed) if is_moderator(user): - return redirect("/exam/manage") - return redirect("/exam/quizzes") + return prof_manage(request, msg=msg) + return view_module(request, module_id=module_id, course_id=course_id, + msg=msg) if not last_attempt: attempt_number = 1 else: @@ -480,7 +483,7 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, 'module': learning_module, } if is_moderator(user): - context["user"] = "moderator" + context["status"] = "moderator" return my_render_to_response('yaksh/intro.html', context, context_instance=ci) else: @@ -2234,7 +2237,7 @@ def show_lesson(request, lesson_id, module_id, course_id): learning_units = learn_module.get_learning_units() if learn_unit.has_prerequisite(): if not learn_unit.is_prerequisite_passed(user, learn_module, course): - msg = "You have not passed the prerequisite" + msg = "You have not completed the prerequisite" return view_module(request, learn_module.id, course_id, msg=msg) context = {'lesson': learn_unit.lesson, 'user': user, 'course': course, 'state': "lesson", @@ -2399,6 +2402,7 @@ def preview_html_text(request): if not is_moderator(user): raise Http404('You are not allowed to view this page!') response_kwargs = {} + response_kwargs['content_type'] = 'application/json' request_data = json.loads(request.body.decode("utf-8")) html_text = get_html_text(request_data['description']) return HttpResponse(json.dumps({"data": html_text}), **response_kwargs) @@ -2519,12 +2523,12 @@ def view_module(request, module_id, course_id, msg=None): context = {} if not course.active or not course.is_active_enrollment(): msg = "{0} is either expired or not active".format(course.name) - return quizlist_user(request, msg=msg) + return course_modules(request, course_id, msg) learning_module = course.learning_module.get(id=module_id) if learning_module.has_prerequisite(): if not learning_module.is_prerequisite_passed(user, course): msg = "You have not completed the previous learning module" - return quizlist_user(request, msg=msg) + return course_modules(request, course_id, msg) learning_units = learning_module.get_learning_units() context['learning_units'] = learning_units context['learning_module'] = learning_module @@ -2534,3 +2538,21 @@ def view_module(request, module_id, course_id, msg=None): context['state'] = "module" context['msg'] = msg return my_render_to_response('yaksh/show_video.html', context) + + +@login_required +@email_verified +def course_modules(request, course_id, msg=None): + user = request.user + course = Course.objects.get(id=course_id) + if user not in course.students.all(): + msg = 'You are not enrolled for this course!' + return quizlist_user(request, msg=msg) + + if not course.active or not course.is_active_enrollment(): + msg = "{0} is either expired or not active".format(course.name) + return quizlist_user(request, msg=msg) + learning_modules = course.get_learning_modules() + context = {"course": course, "learning_modules": learning_modules, + "user": user, "msg": msg} + return my_render_to_response('yaksh/course_modules.html', context) |