diff options
-rw-r--r-- | testapp/exam/urls.py | 1 | ||||
-rw-r--r-- | testapp/exam/views.py | 59 | ||||
-rw-r--r-- | testapp/static/exam/css/base.css | 2 | ||||
-rw-r--r-- | testapp/templates/exam/edit_question.html | 29 | ||||
-rw-r--r-- | testapp/templates/exam/showquestions.html | 18 | ||||
-rw-r--r-- | testapp/templates/manage.html | 6 |
6 files changed, 109 insertions, 6 deletions
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<question_id>\d+)/$', 'add_question'), url(r'^manage/addquiz/$', 'add_quiz'), + url(r'^manage/editquestion/$', 'edit_question'), url(r'^manage/addquiz/(?P<quiz_id>\d+)/$', 'add_quiz'), url(r'^manage/gradeuser/$', 'show_all_users'), url(r'^manage/gradeuser/(?P<username>[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 %} +<style type="text/css"> + +table th, table td { + padding: 10px 10px 9px; + line-height: 18px solid; + text-align: left; +} +</style> + +<form action="{{URL_ROOT}}/exam/manage/editquestion/" method="post"> +{% csrf_token %} +{% for form in forms %} +<table> +{{ form.as_table }} +</table> +<hr> +{% endfor %} +<center><button class="btn" type="submit" name="savequestion">Save</button> +<button class="btn" type="button" name="button" onClick='location.replace("{{URL_ROOT}}/exam/manage/questions/");'>Cancel</button> </center> +</form> +{% 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 %} <script type='text/javascript'> -function my_confirm(frm) +function confirm_delete(frm) { var r = confirm("Are you Sure ?"); if(r==false) @@ -19,6 +19,18 @@ function my_confirm(frm) location.replace("{{URL_ROOT}}/exam/manage/showquestion"); } } +function confirm_edit(frm) +{ + var n = 0; + for(i=0;i<frm.question.length;i++) + { + if(frm.question[i].checked==true) + n = n+1; + } + if(n==0) + location.replace("{{URL_ROOT}}/exam/manage/showquestion"); + +} </script> {% endblock %} @@ -30,6 +42,8 @@ function my_confirm(frm) {% endfor %} <br> <button class="btn" type="button" onclick='location.replace("{{URL_ROOT}}/exam/manage/addquestion/");'>Add Question</button> -<button class="btn" type="submit" onClick="my_confirm(frm);">Delete</button> +<button class="btn" type="submit" name='edit' value='edit' onClick="confirm_edit(frm);">Edit Selected</button> +<button class="btn" type="submit" onClick="confirm_delete(frm);" name='delete' value='delete'>Delete Selected</button> + </form> {% 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 @@ </div> <div class=row> - <div class=span10> + <div class=span10 style="overflow:auto"> <h3><center>{% block subtitle %} {% endblock %}</center></h3><br> {% block manage %} {% endblock %} @@ -22,6 +22,10 @@ .content .span4 { min-height: 500px; } + .textarea + { + width: 10px; + } </style> <div class="span4"> |