diff options
author | hardythe1 | 2012-02-23 18:49:36 +0530 |
---|---|---|
committer | hardythe1 | 2012-02-23 18:49:36 +0530 |
commit | dd3fd7b8c58d836baba24441e7d55c6d51858eab (patch) | |
tree | 7500dd2e40934f311a5f2cf505ad442946afee71 /testapp | |
parent | 9acff5f2cf9f9ae3d2fc097e1fcd84712d3199d0 (diff) | |
download | online_test-dd3fd7b8c58d836baba24441e7d55c6d51858eab.tar.gz online_test-dd3fd7b8c58d836baba24441e7d55c6d51858eab.tar.bz2 online_test-dd3fd7b8c58d836baba24441e7d55c6d51858eab.zip |
View for Editing Quiz
Diffstat (limited to 'testapp')
-rw-r--r-- | testapp/exam/urls.py | 1 | ||||
-rw-r--r-- | testapp/exam/views.py | 49 | ||||
-rw-r--r-- | testapp/templates/exam/edit_quiz.html | 31 | ||||
-rw-r--r-- | testapp/templates/exam/show_quiz.html | 15 | ||||
-rw-r--r-- | testapp/templates/exam/user_data.html | 28 |
5 files changed, 98 insertions, 26 deletions
diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py index 67debd2..a8b81f7 100644 --- a/testapp/exam/urls.py +++ b/testapp/exam/urls.py @@ -14,6 +14,7 @@ urlpatterns = patterns('exam.views', url(r'^manage/addquestion/$', 'add_question'), url(r'^manage/addquestion/(?P<question_id>\d+)/$', 'add_question'), url(r'^manage/addquiz/$', 'add_quiz'), + url(r'^manage/editquiz/$', 'edit_quiz'), url(r'^manage/editquestion/$', 'edit_question'), url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', 'add_quiz'), url(r'^manage/gradeuser/$', 'show_all_users'), diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 22151e7..6eea338 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -92,6 +92,27 @@ def user_register(request): {'form':form}, context_instance=RequestContext(request)) +def edit_quiz(request): + user = request.user + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : + raise Http404('You are not allowed to view this page!') + + start_date = request.POST.getlist('start_date') + duration = request.POST.getlist('duration') + active = request.POST.getlist('active') + description = request.POST.getlist('description') + + j = 0 + for i in quizlist: + quiz = Quiz.objects.get(id=i) + quiz.start_date = start_date[j] + quiz.duration = duration[j] + quiz.active = active[j] + quiz.description = description[j] + quiz.save() + j += 1 + return my_redirect("/exam/manage/showquiz/") + def edit_question(request): user = request.user if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : @@ -472,7 +493,7 @@ def show_all_quiz(request): if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0: raise Http404('You are not allowed to view this page !') - if request.method == 'POST': + if request.method == 'POST' and request.POST.get('delete')=='delete': data = request.POST.getlist('quiz') if data == None: quizzes = Quiz.objects.all() @@ -489,6 +510,32 @@ def show_all_quiz(request): 'quizzes':quizzes} return my_render_to_response('exam/show_quiz.html', context, context_instance=RequestContext(request)) + + elif request.method == 'POST' and request.POST.get('edit')=='edit': + data = request.POST.getlist('quiz') + global quizlist + quizlist = data + if data == None: + quiz = Quiz.objects.all() + context = {'papers': [], + 'quiz': None, + 'quizzes':quiz} + return my_render_to_response('exam/showquiz.html', context, + context_instance=RequestContext(request)) + + forms = [] + for j in data: + d = Quiz.objects.get(id=j) + form = QuizForm() + form.initial['start_date']= d.start_date + form.initial['duration'] = d.duration + form.initial['active']= d.active + form.initial['description'] = d.description + forms.append(form) + + return my_render_to_response('exam/edit_quiz.html', + {'forms':forms}, + context_instance=RequestContext(request)) else: quizzes = Quiz.objects.all() diff --git a/testapp/templates/exam/edit_quiz.html b/testapp/templates/exam/edit_quiz.html new file mode 100644 index 0000000..7744623 --- /dev/null +++ b/testapp/templates/exam/edit_quiz.html @@ -0,0 +1,31 @@ +{% extends "manage.html" %} + + +{% block subtitle %} +Edit Quiz(zes) +{% endblock %} + +{% block manage %} + +<style type='text/css'> + +table th, table td { + padding: 10px 10px 9px; + line-height: 18px; + text-align: left; +} +</style> +<form name=frm action="{{URL_ROOT}}/exam/manage/editquiz/" method="post"> +{% csrf_token %} +{% for form in forms %} +<center> +<table class=span1> +{{ form.as_table }} +</table> +</center> +<hr> +{% endfor %} +<center><button class="btn" type="submit" name="save">Save</button> +<button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/showquiz/");'>Cancel</button> </center> +</form> +{% endblock %} diff --git a/testapp/templates/exam/show_quiz.html b/testapp/templates/exam/show_quiz.html index 001b2fe..d546b06 100644 --- a/testapp/templates/exam/show_quiz.html +++ b/testapp/templates/exam/show_quiz.html @@ -17,6 +17,17 @@ function my_confirm(frm) } } +function confirm_edit(frm) +{ + var n = 0; + for (var i =0;i<frm.quiz.length;i++) + { + if (frm.quiz[i].checked == false) + n = n + 1 ; + } + if(n == frm.quiz.length) + location.replace("{{URL_ROOT}}/exam/manage/showquiz"); +} </script> {% endblock %} @@ -39,7 +50,9 @@ function my_confirm(frm) <input type=checkbox name='quiz' value={{quiz.id}} /> <a href="{{URL_ROOT}}/exam/manage/addquiz/{{quiz.id}}/">{{ quiz.description }}</a><br> {% endfor %} <br><br> -<button class="btn" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/addquiz");'>Add New Quiz</button> <button class="btn" type="submit" name="delete" onClick="my_confirm(frm);">Delete</button> +<button class="btn" type="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/addquiz");'>Add New Quiz</button> +<button class="btn" type="submit" name='edit' value='edit' onClick="confirm_edit(frm);" >Edit Selected</button> +<button class="btn" type="submit" name="delete" value='delete' onClick="my_confirm(frm);">Delete Selected</button> </form> {% endif %} {% endblock %} diff --git a/testapp/templates/exam/user_data.html b/testapp/templates/exam/user_data.html index c835f61..943dfe8 100644 --- a/testapp/templates/exam/user_data.html +++ b/testapp/templates/exam/user_data.html @@ -1,20 +1,11 @@ -{% extends "base.html" %} +{% extends "manage.html" %} {% block title %} Data for user {{ data.user.get_full_name.title }} {% endblock title %} -{% block content %} +{% block manage %} - <div class="container"> - <div class="content"> -<div class="page-header"> -<h1><Strong><center>Online Test</center></strong></h1> -</div> - <div class=row> - <div class=span14> -<h3><center>Data for user {{ data.user.get_full_name.title }}</center></h3><br> +{% block subtitle %}Data for user {{ data.user.get_full_name.title }}{% endblock %} <form action="" method="post"> - - <p> Name: {{ data.user.get_full_name.title }} <br/> Username: {{ data.user.username }} <br/> @@ -87,16 +78,5 @@ User IP address: {{ paper.user_ip }} Monitor quiz</a> {% endwith %} {% endif %} -<br /> -<a href="{{URL_ROOT}}/admin/">Admin</a> - -</div> - </div> - </div> -<footer> - <p>© FOSSEE group, IIT Bombay</p> - </footer> - - </div> <!-- /container --> -{% endblock content %} +{% endblock %} |