diff options
author | Prabhu Ramachandran | 2016-09-08 08:37:07 +0530 |
---|---|---|
committer | GitHub | 2016-09-08 08:37:07 +0530 |
commit | 68db5b034de8e3fe021a84ed4f64b60679fa3255 (patch) | |
tree | 770b9067974b572e3378c40a613567c1c49f4029 /yaksh | |
parent | 01e08dd15b59ce353043d541c9be81592cda3fe0 (diff) | |
parent | 6e2a0db4d67902cca52277d22dd7a67ebd059268 (diff) | |
download | online_test-68db5b034de8e3fe021a84ed4f64b60679fa3255.tar.gz online_test-68db5b034de8e3fe021a84ed4f64b60679fa3255.tar.bz2 online_test-68db5b034de8e3fe021a84ed4f64b60679fa3255.zip |
Merge pull request #132 from maheshgudi/course_changes
added add quiz button to each course
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 7 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 18 | ||||
-rw-r--r-- | yaksh/test_views.py | 22 | ||||
-rw-r--r-- | yaksh/urls.py | 4 | ||||
-rw-r--r-- | yaksh/views.py | 19 |
5 files changed, 45 insertions, 25 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index 4a20102..23131b7 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -153,13 +153,14 @@ class QuizForm(forms.ModelForm): def __init__(self, *args, **kwargs): user = kwargs.pop('user') + course_id = kwargs.pop('course') super(QuizForm, self).__init__(*args, **kwargs) self.fields['prerequisite'] = forms.ModelChoiceField( - queryset=Quiz.objects.filter(course__creator=user)) + queryset=Quiz.objects.filter(course__id=course_id, + is_trial=False)) self.fields['prerequisite'].required = False self.fields['course'] = forms.ModelChoiceField( - queryset=Course.objects.filter(Q(creator=user)| - Q(teachers=user)).distinct()) + queryset=Course.objects.filter(id=course_id), empty_label=None) class Meta: model = Quiz diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 42f49d1..109b996 100644 --- a/yaksh/templates/yaksh/courses.html +++ b/yaksh/templates/yaksh/courses.html @@ -65,13 +65,17 @@ <p><b><u>Quiz(zes)</u></b></p> {% if course.get_quizzes %} {% for quiz in course.get_quizzes %} - <a href="{{URL_ROOT}}/exam/manage/addquiz/{{quiz.id}}/">{{ quiz.description }}</a><br> + <a href="{{URL_ROOT}}/exam/manage/addquiz/{{course.id}}/{{quiz.id}}/">{{ quiz.description }}</a><br> + {% endfor %} {% else %} <p><b>No quiz </b></p> {% endif %} </div> </div> + <br/> + <button class="btn primary"type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/addquiz/{{course.id}}/");'>Add New Quiz</button> + </div> </div> <br><br> @@ -130,22 +134,22 @@ <p><b><u>Quiz(zes)</u></b></p> {% if course.get_quizzes %} {% for quiz in course.get_quizzes %} - <a href="{{URL_ROOT}}/exam/manage/addquiz/{{quiz.id}}/">{{ quiz.description }}</a><br> + <a href="{{URL_ROOT}}/exam/manage/addquiz/{{course.id}}/{{quiz.id}}/">{{ quiz.description }}</a><br> {% endfor %} {% else %} <p><b>No quiz </b></p> {% endif %} </div> </div> + <button class="btn primary"type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/addquiz/{{course.id}}/");'>Add New Quiz</button> </div> </div> <br><br> {% endfor %} {% else %} - <center><h4> No new Courses allotted </h4></center> + <center><h4> No new Courses allotted</h4></center> + <br><br> {% endif %} -<button class="btn primary" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/add_course");'>Add New Course</button> - {% if courses or allotted_courses %} - <button class="btn primary" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/addquiz");'>Add New Quiz</button> -{% endif %} +<center><button class="btn primary" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/add_course");'>Add New Course</button></center> + {% endblock %} diff --git a/yaksh/test_views.py b/yaksh/test_views.py index e232bc0..7d23ce9 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -213,8 +213,11 @@ class TestAddQuiz(TestCase): """ If not logged in redirect to login page """ - response = self.client.get(reverse('yaksh:add_quiz'), follow=True) - redirect_destination = '/exam/login/?next=/exam/manage/addquiz/' + response = self.client.get(reverse('yaksh:add_quiz', + kwargs={'course_id': self.course.id}), + follow=True + ) + redirect_destination = '/exam/login/?next=/exam/manage/addquiz/{0}/'.format(self.course.id) self.assertRedirects(response, redirect_destination) def test_view_profile_denies_non_moderator(self): @@ -225,8 +228,11 @@ class TestAddQuiz(TestCase): username=self.student.username, password=self.student_plaintext_pass ) - - response = self.client.get(reverse('yaksh:add_quiz'), follow=True) + course_id = self.course.id + response = self.client.get(reverse('yaksh:add_quiz', + kwargs={'course_id': self.course.id}), + follow=True + ) self.assertEqual(response.status_code, 404) def test_add_quiz_get(self): @@ -237,7 +243,9 @@ class TestAddQuiz(TestCase): username=self.user.username, password=self.user_plaintext_pass ) - response = self.client.get(reverse('yaksh:add_quiz')) + response = self.client.get(reverse('yaksh:add_quiz', + kwargs={'course_id': self.course.id}) + ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'yaksh/add_quiz.html') self.assertIsNotNone(response.context['form']) @@ -252,7 +260,7 @@ class TestAddQuiz(TestCase): ) tzone = pytz.timezone('UTC') response = self.client.post(reverse('yaksh:edit_quiz', - kwargs={'quiz_id': self.quiz.id}), + kwargs={'course_id':self.course.id, 'quiz_id': self.quiz.id}), data={ 'start_date_time': '2016-01-10 09:00:15', 'end_date_time': '2016-01-15 09:00:15', @@ -298,7 +306,7 @@ class TestAddQuiz(TestCase): ) tzone = pytz.timezone('UTC') - response = self.client.post(reverse('yaksh:add_quiz'), + response = self.client.post(reverse('yaksh:add_quiz', kwargs={"course_id": self.course.id}), data={ 'start_date_time': '2016-01-10 09:00:15', 'end_date_time': '2016-01-15 09:00:15', diff --git a/yaksh/urls.py b/yaksh/urls.py index 69d7f87..daa6008 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -53,8 +53,8 @@ urlpatterns += [ url(r'^manage/$', views.prof_manage, name='manage'), url(r'^manage/addquestion/$', views.add_question), url(r'^manage/addquestion/(?P<question_id>\d+)/$', views.edit_question), - url(r'^manage/addquiz/$', views.add_quiz, name='add_quiz'), - url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', views.add_quiz, name='edit_quiz'), + url(r'^manage/addquiz/(?P<course_id>\d+)/$', views.add_quiz, name='add_quiz'), + url(r'^manage/addquiz/(?P<course_id>\d+)/(?P<quiz_id>\d+)/$', views.add_quiz, name='edit_quiz'), url(r'^manage/gradeuser/$', views.grade_user), url(r'^manage/gradeuser/(?P<quiz_id>\d+)/$',views.grade_user), url(r'^manage/gradeuser/(?P<quiz_id>\d+)/(?P<user_id>\d+)/$',views.grade_user), diff --git a/yaksh/views.py b/yaksh/views.py index 1abf248..fa4dac6 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -246,33 +246,40 @@ def edit_question(request, question_id=None): context_instance=ci) @login_required -def add_quiz(request, quiz_id=None): +def add_quiz(request, course_id, quiz_id=None): """To add a new quiz in the database. Create a new quiz and store it.""" user = request.user + course = get_object_or_404(Course, pk=course_id) ci = RequestContext(request) - if not is_moderator(user): + if not is_moderator(user) or (user != course.creator and user not in course.teachers.all()): raise Http404('You are not allowed to view this page!') context = {} if request.method == "POST": if quiz_id is None: - form = QuizForm(request.POST, user=user) + form = QuizForm(request.POST, user=user, course=course_id) if form.is_valid(): form.save() return my_redirect(reverse('yaksh:design_questionpaper')) + else: + context["form"] = form + return my_render_to_response('yaksh/add_quiz.html', + context, + context_instance=ci) else: quiz = Quiz.objects.get(id=quiz_id) - form = QuizForm(request.POST, user=user, instance=quiz) + form = QuizForm(request.POST, user=user, course=course_id, + instance=quiz) if form.is_valid(): form.save() context["quiz_id"] = quiz_id return my_redirect("/exam/manage/") else: if quiz_id is None: - form = QuizForm(user=user) + form = QuizForm(course=course_id, user=user) else: quiz = Quiz.objects.get(id=quiz_id) - form = QuizForm(user=user, instance=quiz) + form = QuizForm(user=user,course=course_id, instance=quiz) context["quiz_id"] = quiz_id context["form"] = form return my_render_to_response('yaksh/add_quiz.html', |