From 9acff5f2cf9f9ae3d2fc097e1fcd84712d3199d0 Mon Sep 17 00:00:00 2001 From: hardythe1 Date: Thu, 23 Feb 2012 16:30:36 +0530 Subject: more changes to edit multiple questions at a time --- testapp/exam/urls.py | 1 + testapp/exam/views.py | 59 +++++++++++++++++++++++++++++-- testapp/static/exam/css/base.css | 2 +- testapp/templates/exam/edit_question.html | 29 +++++++++++++++ testapp/templates/exam/showquestions.html | 18 ++++++++-- testapp/templates/manage.html | 6 +++- 6 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 testapp/templates/exam/edit_question.html diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py index d4ebe50..67debd2 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/editquestion/$', 'edit_question'), url(r'^manage/addquiz/(?P\d+)/$', 'add_quiz'), url(r'^manage/gradeuser/$', 'show_all_users'), url(r'^manage/gradeuser/(?P[a-zA-Z0-9_.]+)/$', 'grade_user'), diff --git a/testapp/exam/views.py b/testapp/exam/views.py index bc2290b..22151e7 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -92,6 +92,33 @@ def user_register(request): {'form':form}, context_instance=RequestContext(request)) +def edit_question(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!') + + summary = request.POST.getlist('summary') + description = request.POST.getlist('description') + points = request.POST.getlist('points') + test = request.POST.getlist('test') + options = request.POST.getlist('options') + type = request.POST.getlist('type') + active = request.POST.getlist('active') + j = 0 + for i in editquestionlist: + question = Question.objects.get(id=i) + question.summary = summary[j] + question.description = description[j] + question.points = points[j] + question.test = test[j] + question.options = options[j] + question.type = type[j] + question.active = active[j] + question.save() + j += 1 + return my_redirect("/exam/manage/questions") + + def add_question(request,question_id=None): """To add a new question in the database. Create a new question and store it.""" user = request.user @@ -478,7 +505,7 @@ def show_all_questions(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('question') if data == None: questions = Question.objects.all() @@ -495,7 +522,35 @@ def show_all_questions(request): 'questions':questions} return my_render_to_response('exam/showquestions.html', context, context_instance=RequestContext(request)) - + + elif request.method == 'POST' and request.POST.get('edit')=='edit': + data = request.POST.getlist('question') + global editquestionlist + editquestionlist = data + if data == None: + questions = Question.objects.all() + context = {'papers': [], + 'question': None, + 'questions':questions} + return my_render_to_response('exam/showquestions.html', context, + context_instance=RequestContext(request)) + + forms = [] + for j in data: + d = Question.objects.get(id=j) + form = QuestionForm() + form.initial['summary']= d.summary + form.initial['description'] = d.description + form.initial['points']= d.points + form.initial['test'] = d.test + form.initial['options'] = d.options + form.initial['type'] = d.type + form.initial['active'] = d.active + forms.append(form) + + return my_render_to_response('exam/edit_question.html', + {'forms':forms}, + context_instance=RequestContext(request)) else: questions = Question.objects.all() context = {'papers': [], diff --git a/testapp/static/exam/css/base.css b/testapp/static/exam/css/base.css index 6891402..9a37d2f 100644 --- a/testapp/static/exam/css/base.css +++ b/testapp/static/exam/css/base.css @@ -482,7 +482,7 @@ dl dd { hr { margin: 20px 0 19px; border: 0; - border-bottom: 1px solid #eee; + border-bottom: 10px solid; } strong { font-style: inherit; diff --git a/testapp/templates/exam/edit_question.html b/testapp/templates/exam/edit_question.html new file mode 100644 index 0000000..04217ab --- /dev/null +++ b/testapp/templates/exam/edit_question.html @@ -0,0 +1,29 @@ +{% extends "manage.html" %} + +{% block subtitle %} +Edit Question +{% endblock %} + + +{% block manage %} + + +
+{% csrf_token %} +{% for form in forms %} + +{{ form.as_table }} +
+
+{% endfor %} +
+
+
+{% endblock %} diff --git a/testapp/templates/exam/showquestions.html b/testapp/templates/exam/showquestions.html index 994ca26..edcba6f 100644 --- a/testapp/templates/exam/showquestions.html +++ b/testapp/templates/exam/showquestions.html @@ -7,7 +7,7 @@ List of Questions {% block script %} {% endblock %} @@ -30,6 +42,8 @@ function my_confirm(frm) {% endfor %}
   - +   + + {% endblock %} diff --git a/testapp/templates/manage.html b/testapp/templates/manage.html index c7c6fa1..10842c3 100644 --- a/testapp/templates/manage.html +++ b/testapp/templates/manage.html @@ -13,7 +13,7 @@
-
+

{% block subtitle %} {% endblock %}


{% block manage %} {% endblock %} @@ -22,6 +22,10 @@ .content .span4 { min-height: 500px; } + .textarea + { + width: 10px; + }
-- cgit