event/views.py
author nishanth
Wed, 30 Jun 2010 10:50:49 +0530
changeset 75 f7ee769f0d95
parent 74 46c5ae6594df
child 76 c84fc7ace0f5
permissions -rw-r--r--
all the admin key checking is now done via urls
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
     1
from django.db.models import Sum
6
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
     2
from django.http import Http404
9
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
     3
from django.shortcuts import render_to_response, redirect
6
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
     4
39
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 38
diff changeset
     5
from offline.settings import ADMIN_KEY
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 38
diff changeset
     6
6
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
     7
from offline.event.models import Event
63
21cdadb1b98e replaced the old form with new one in view and template for opening quiz
nishanth
parents: 48
diff changeset
     8
from offline.event.forms import EventCreateForm, OpenQuizForm
39
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 38
diff changeset
     9
44
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
    10
from offline.quiz.models import Quiz, QuestionBank
39
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 38
diff changeset
    11
from offline.quiz.utils import correct_quiz
7
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    12
34
8d0d82c981b3 added "return to admin page" link in open_quiz page
nishanth
parents: 26
diff changeset
    13
num2name = {"11" : "Day 1 Quiz 1",
8d0d82c981b3 added "return to admin page" link in open_quiz page
nishanth
parents: 26
diff changeset
    14
            "12" : "Day 1 Quiz 2",
8d0d82c981b3 added "return to admin page" link in open_quiz page
nishanth
parents: 26
diff changeset
    15
            "21" : "Day 2 Quiz 1",
8d0d82c981b3 added "return to admin page" link in open_quiz page
nishanth
parents: 26
diff changeset
    16
           }
8d0d82c981b3 added "return to admin page" link in open_quiz page
nishanth
parents: 26
diff changeset
    17
6
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    18
def event_home(request):
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    19
    """ The page for people to view.
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    20
    """
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    21
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    22
    try:
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    23
        event = Event.objects.all()[0]
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    24
    except IndexError:
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    25
        raise Http404
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    26
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    27
    ip = request.META['REMOTE_ADDR']
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    28
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    29
    can_submit_feedback = True if event.feedback_status != '0' and \
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    30
            not event.feedback.filter(day=event.feedback_status,user_ip=ip) else False
23
f57c30096b51 added the link on home to attempt quiz
nishanth
parents: 9
diff changeset
    31
    can_take_quiz = True if event.quiz_status != "00" else False
6
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    32
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    33
    return render_to_response('home.html', {'event':event, 'can_submit_feedback':can_submit_feedback, 'can_take_quiz':can_take_quiz})
8929b82c1dbb added home page with minimum functionality
nishanth
parents: 4
diff changeset
    34
72
665287ab8e3a now the checking for admin key is done via urls
nishanth
parents: 65
diff changeset
    35
def event_admin(request):
7
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    36
    """ see if the key is correct and then display options.
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    37
    """
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    38
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    39
    try:
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    40
        event = Event.objects.all()[0]
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    41
    except IndexError:
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    42
        return redirect('/event/create/%s'%ADMIN_KEY)
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    43
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    44
    return render_to_response('admin.html', {'event':event, 'admin_key':ADMIN_KEY})
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    45
    
73
5c2c74afb94e checking for admin key is done via urls in all the views related to feedback
nishanth
parents: 72
diff changeset
    46
def event_create(request):
9
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    47
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    48
    try:
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    49
        event = Event.objects.all()[0]
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    50
        return redirect("/event/admin/%s"%admin_key)
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    51
    except IndexError:
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    52
        new_event = Event()
7
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    53
9
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    54
    if request.method == "POST":
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    55
        form = EventCreateForm(request.POST)
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    56
        if form.is_valid():
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    57
            new_event.title = form.cleaned_data['title']
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    58
            new_event.start_date = form.cleaned_data['start_date']
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    59
            new_event.stop_date = form.cleaned_data['stop_date']
7
dfedb369f32e first fixed on the urls and then gave the admin_key in settings and then created main admin page.
nishanth
parents: 6
diff changeset
    60
9
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    61
            new_event.save()
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    62
            return redirect('/event/admin/%s'%ADMIN_KEY)
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    63
        else:
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    64
            return render_to_response('create_event.html',{'form':form})
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    65
    else:
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    66
        form = EventCreateForm()
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    67
        return render_to_response('create_event.html',{'form':form})
23
f57c30096b51 added the link on home to attempt quiz
nishanth
parents: 9
diff changeset
    68
74
46c5ae6594df cheching for admin key in opening and closing of quiz is now done via urls
nishanth
parents: 73
diff changeset
    69
def open_quiz(request):
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    70
    """ check for admin and then for quiz status.
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    71
    """
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    72
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    73
    try:
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    74
        event = Event.objects.all()[0]
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    75
    except IndexError:
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    76
        return redirect('/event/create/%s'%ADMIN_KEY)
23
f57c30096b51 added the link on home to attempt quiz
nishanth
parents: 9
diff changeset
    77
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    78
    if event.quiz_status != "00":
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    79
        return redirect('/event/create/%s'%ADMIN_KEY)
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    80
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    81
    if request.method=="POST":
65
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    82
        form = OpenQuizForm(request.POST)
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    83
        if form.is_valid():
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    84
            data = form.cleaned_data
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    85
            quiz_num = data['quiz_num']
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    86
            topics = data['topics']
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    87
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    88
            for topic in topics:
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    89
                QuestionBank.objects.filter(topic=topic).update(quiz_num=quiz_num)
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    90
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    91
            event.quiz_status = quiz_num
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    92
            event.save()
34
8d0d82c981b3 added "return to admin page" link in open_quiz page
nishanth
parents: 26
diff changeset
    93
            return render_to_response("open_quiz.html",{"admin_key":ADMIN_KEY, "quiz_name":num2name[quiz_num], 'success':True})
65
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    94
        else:
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    95
            return render_to_response("open_quiz.html", {"form":form})
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    96
    else:
63
21cdadb1b98e replaced the old form with new one in view and template for opening quiz
nishanth
parents: 48
diff changeset
    97
        form = OpenQuizForm()
21cdadb1b98e replaced the old form with new one in view and template for opening quiz
nishanth
parents: 48
diff changeset
    98
        return render_to_response("open_quiz.html", {"form":form})
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    99
   
74
46c5ae6594df cheching for admin key in opening and closing of quiz is now done via urls
nishanth
parents: 73
diff changeset
   100
def close_quiz(request):
26
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   101
    """ check for admin and then for quiz status.
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   102
    """
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   103
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   104
    try:
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   105
        event = Event.objects.all()[0]
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   106
    except IndexError:
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   107
        return redirect('/event/create/%s'%ADMIN_KEY)
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   108
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   109
    if event.quiz_status == "00":
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   110
        return redirect('/event/create/%s'%ADMIN_KEY)
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   111
    
38
307c6887cc67 added quiz name in close quiz page.
nishanth
parents: 35
diff changeset
   112
    quiz_num = event.quiz_status
307c6887cc67 added quiz name in close quiz page.
nishanth
parents: 35
diff changeset
   113
26
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   114
    event.quiz_status = "00"
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   115
    event.save()
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   116
39
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 38
diff changeset
   117
    event_quizzes = event.quiz.filter(quiz_num=quiz_num)
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 38
diff changeset
   118
    for quiz in event_quizzes:
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 38
diff changeset
   119
        correct_quiz(quiz)
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 38
diff changeset
   120
38
307c6887cc67 added quiz name in close quiz page.
nishanth
parents: 35
diff changeset
   121
    return render_to_response("close_quiz.html", {"admin_key":ADMIN_KEY, "quiz_name":num2name[quiz_num]})
307c6887cc67 added quiz name in close quiz page.
nishanth
parents: 35
diff changeset
   122
75
f7ee769f0d95 all the admin key checking is now done via urls
nishanth
parents: 74
diff changeset
   123
def list_toppers(request, quiz_num):
41
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   124
    """ check for admin key
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   125
    Then check for quiz_num in ['11', ..]
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   126
    then give appropriate response.
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   127
    """
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   128
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   129
    try:
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   130
        event = Event.objects.all()[0]
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   131
    except IndexError:
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   132
        return redirect('/event/create/%s'%ADMIN_KEY)
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   133
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   134
    if quiz_num not in ["11", "12", "21"]:
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   135
        raise Http404
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   136
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   137
    quizzes = Quiz.objects.filter(event=event,quiz_num=quiz_num)
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   138
    quizzes_with_scores = quizzes.annotate(score=Sum('que_answered__is_correct'))
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   139
    sorted_quizzes = quizzes_with_scores.order_by("score").reverse()
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   140
42
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   141
    return render_to_response("list_toppers.html", {"sorted_quizzes":sorted_quizzes,"admin_key":ADMIN_KEY, "event":event, "quiz_name":num2name[quiz_num]})
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   142
75
f7ee769f0d95 all the admin key checking is now done via urls
nishanth
parents: 74
diff changeset
   143
def user_dump(request, quiz_key, user_name):
42
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   144
    """ check for admin_key
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   145
    then get quiz by quiz_key and user_name.
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   146
    then display the dump
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   147
    """
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   148
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   149
    try:
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   150
        event = Event.objects.all()[0]
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   151
    except IndexError:
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   152
        return redirect('/event/create/%s'%ADMIN_KEY)
44
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   153
42
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   154
    try:
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   155
        quiz = Quiz.objects.get(event=event, key=quiz_key)
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   156
    except Quiz.DoesNotExist:
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   157
        raise Http404
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   158
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   159
    if not quiz.user.username == user_name:
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   160
        raise Http404
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   161
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   162
    quiz_name = num2name[quiz.quiz_num]
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   163
    if request.method == "POST":
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   164
        for ans in quiz.que_answered.all():
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   165
            ans.is_correct = True if str(ans.question.id) in request.POST else False
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   166
            ans.save()
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   167
        return redirect("/quiz/toppers/%s/%s"%(ADMIN_KEY, quiz.quiz_num))
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   168
    else:
44
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   169
        return render_to_response("user_dump.html", {"quiz":quiz, "quiz_name":quiz_name, "admin_key":ADMIN_KEY}) 
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   170
75
f7ee769f0d95 all the admin key checking is now done via urls
nishanth
parents: 74
diff changeset
   171
def que_dump(request, que_id):
44
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   172
    """ check for admin key
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   173
    then simply render all answers corresponding to the question.
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   174
    """
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   175
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   176
    try:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   177
        event = Event.objects.all()[0]
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   178
    except IndexError:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   179
        return redirect('/event/create/%s'%ADMIN_KEY)
42
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   180
44
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   181
    try:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   182
        question = QuestionBank.objects.get(id=que_id)
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   183
    except QuestionBank.DoesNotExist:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   184
        raise Http404
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   185
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   186
    quiz_num = question.quiz_num
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   187
    quiz_name = num2name[quiz_num]
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   188
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   189
    answers = question.answer.all()
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   190
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   191
    if request.method == "POST":
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   192
        for ans in answers:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   193
            ans.is_correct = True if str(ans.id) in request.POST else False
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   194
            ans.save()
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   195
        return redirect("/quiz/toppers/%s/%s"%(ADMIN_KEY, quiz_num))
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   196
    else:
48
aae2f69ba89c updated the que_dump template to show the question properly.
nishanth
parents: 44
diff changeset
   197
        return render_to_response("que_dump.html", {"quiz_name":quiz_name, "question":question, "answers":answers})