diff options
author | maheshgudi | 2016-09-06 12:44:49 +0530 |
---|---|---|
committer | maheshgudi | 2016-09-06 12:47:26 +0530 |
commit | 848f7945811f1d16bdf8d5e2a99d157d9ed9a18c (patch) | |
tree | 5d106375e3f8613f1afc14caf0ebf51ddd4dab2b /yaksh | |
parent | 01e08dd15b59ce353043d541c9be81592cda3fe0 (diff) | |
download | online_test-848f7945811f1d16bdf8d5e2a99d157d9ed9a18c.tar.gz online_test-848f7945811f1d16bdf8d5e2a99d157d9ed9a18c.tar.bz2 online_test-848f7945811f1d16bdf8d5e2a99d157d9ed9a18c.zip |
added 'add new quiz' button to each course
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/forms.py | 8 | ||||
-rw-r--r-- | yaksh/templates/yaksh/courses.html | 17 | ||||
-rw-r--r-- | yaksh/urls.py | 4 | ||||
-rw-r--r-- | yaksh/views.py | 16 |
4 files changed, 28 insertions, 17 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py index 4a20102..62179d5 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -153,13 +153,15 @@ 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__creator=user, + 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)) + self.fields['course'].initial = Course.objects.get(id=course_id) class Meta: model = Quiz diff --git a/yaksh/templates/yaksh/courses.html b/yaksh/templates/yaksh/courses.html index 42f49d1..ba7d09f 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,21 @@ <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 <br><br></h4></center> {% 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/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..0fb2214 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -246,7 +246,7 @@ 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 @@ -256,23 +256,29 @@ def add_quiz(request, quiz_id=None): 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', |