From dd3fd7b8c58d836baba24441e7d55c6d51858eab Mon Sep 17 00:00:00 2001 From: hardythe1 Date: Thu, 23 Feb 2012 18:49:36 +0530 Subject: View for Editing Quiz --- testapp/exam/urls.py | 1 + testapp/exam/views.py | 49 ++++++++++++++++++++++++++++++++++- testapp/templates/exam/edit_quiz.html | 31 ++++++++++++++++++++++ testapp/templates/exam/show_quiz.html | 15 ++++++++++- testapp/templates/exam/user_data.html | 28 +++----------------- 5 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 testapp/templates/exam/edit_quiz.html 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\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\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 %} + + +
+{% csrf_token %} +{% for form in forms %} +
+ +{{ form.as_table }} +
+
+
+{% endfor %} +
+
+
+{% 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 {% endblock %} @@ -39,7 +50,9 @@ function my_confirm(frm)   {{ quiz.description }}
{% endfor %}

-   +   +   + {% 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 %} -
-
- -
-
-

Data for user {{ data.user.get_full_name.title }}


+{% block subtitle %}Data for user {{ data.user.get_full_name.title }}{% endblock %}
- -

Name: {{ data.user.get_full_name.title }}
Username: {{ data.user.username }}
@@ -87,16 +78,5 @@ User IP address: {{ paper.user_ip }} Monitor quiz {% endwith %} {% endif %} -
-Admin - -

-
-
-
-

© FOSSEE group, IIT Bombay

-
- -
-{% endblock content %} +{% endblock %} -- cgit