event/views.py
author nishanth
Thu, 01 Jul 2010 16:04:09 +0530
changeset 77 7315ee25bf83
parent 76 c84fc7ace0f5
child 78 2264a51fc9cf
permissions -rw-r--r--
created another url for listing all the questions
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):
76
c84fc7ace0f5 included help text for the method
nishanth
parents: 75
diff changeset
    47
    """ Create an event for which the quiz and feedback should be conducted.
c84fc7ace0f5 included help text for the method
nishanth
parents: 75
diff changeset
    48
    """
9
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    49
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    50
    try:
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    51
        event = Event.objects.all()[0]
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    52
        return redirect("/event/admin/%s"%admin_key)
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    53
    except IndexError:
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    54
        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
    55
9
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    56
    if request.method == "POST":
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    57
        form = EventCreateForm(request.POST)
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    58
        if form.is_valid():
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    59
            new_event.title = form.cleaned_data['title']
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    60
            new_event.start_date = form.cleaned_data['start_date']
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    61
            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
    62
9
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    63
            new_event.save()
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    64
            return redirect('/event/admin/%s'%ADMIN_KEY)
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    65
        else:
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    66
            return render_to_response('create_event.html',{'form':form})
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    67
    else:
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    68
        form = EventCreateForm()
601057af86c2 implemented event create
nishanth
parents: 7
diff changeset
    69
        return render_to_response('create_event.html',{'form':form})
23
f57c30096b51 added the link on home to attempt quiz
nishanth
parents: 9
diff changeset
    70
74
46c5ae6594df cheching for admin key in opening and closing of quiz is now done via urls
nishanth
parents: 73
diff changeset
    71
def open_quiz(request):
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    72
    """ check for admin and then for quiz status.
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    73
    """
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    74
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    75
    try:
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    76
        event = Event.objects.all()[0]
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    77
    except IndexError:
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    78
        return redirect('/event/create/%s'%ADMIN_KEY)
23
f57c30096b51 added the link on home to attempt quiz
nishanth
parents: 9
diff changeset
    79
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    80
    if event.quiz_status != "00":
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    81
        return redirect('/event/create/%s'%ADMIN_KEY)
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    82
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    83
    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
    84
        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
    85
        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
    86
            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
    87
            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
    88
            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
    89
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    90
            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
    91
                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
    92
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    93
            event.quiz_status = quiz_num
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    94
            event.save()
34
8d0d82c981b3 added "return to admin page" link in open_quiz page
nishanth
parents: 26
diff changeset
    95
            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
    96
        else:
88a36f434284 added the required changes in open_quiz view. the design is now final and ready for use
nishanth
parents: 63
diff changeset
    97
            return render_to_response("open_quiz.html", {"form":form})
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
    98
    else:
63
21cdadb1b98e replaced the old form with new one in view and template for opening quiz
nishanth
parents: 48
diff changeset
    99
        form = OpenQuizForm()
21cdadb1b98e replaced the old form with new one in view and template for opening quiz
nishanth
parents: 48
diff changeset
   100
        return render_to_response("open_quiz.html", {"form":form})
25
4143a8f90b00 added open quiz functionality
nishanth
parents: 23
diff changeset
   101
   
74
46c5ae6594df cheching for admin key in opening and closing of quiz is now done via urls
nishanth
parents: 73
diff changeset
   102
def close_quiz(request):
26
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   103
    """ check for admin and then for quiz status.
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   104
    """
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   105
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   106
    try:
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   107
        event = Event.objects.all()[0]
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   108
    except IndexError:
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   109
        return redirect('/event/create/%s'%ADMIN_KEY)
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   110
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   111
    if event.quiz_status == "00":
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   112
        return redirect('/event/create/%s'%ADMIN_KEY)
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   113
    
38
307c6887cc67 added quiz name in close quiz page.
nishanth
parents: 35
diff changeset
   114
    quiz_num = event.quiz_status
307c6887cc67 added quiz name in close quiz page.
nishanth
parents: 35
diff changeset
   115
26
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   116
    event.quiz_status = "00"
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   117
    event.save()
10760aa2cf52 added close quiz functionality
nishanth
parents: 25
diff changeset
   118
39
0fa055b8ea98 implemented correct_quiz function and added it at the time of closing quiz and modified question bank
nishanth
parents: 38
diff changeset
   119
    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
   120
    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
   121
        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
   122
38
307c6887cc67 added quiz name in close quiz page.
nishanth
parents: 35
diff changeset
   123
    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
   124
75
f7ee769f0d95 all the admin key checking is now done via urls
nishanth
parents: 74
diff changeset
   125
def list_toppers(request, quiz_num):
41
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   126
    """ check for admin key
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   127
    Then check for quiz_num in ['11', ..]
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   128
    then give appropriate response.
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   129
    """
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   130
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   131
    try:
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   132
        event = Event.objects.all()[0]
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   133
    except IndexError:
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   134
        return redirect('/event/create/%s'%ADMIN_KEY)
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   135
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   136
    if quiz_num not in ["11", "12", "21"]:
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   137
        raise Http404
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   138
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   139
    quizzes = Quiz.objects.filter(event=event,quiz_num=quiz_num)
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   140
    quizzes_with_scores = quizzes.annotate(score=Sum('que_answered__is_correct'))
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   141
    sorted_quizzes = quizzes_with_scores.order_by("score").reverse()
d424b9668a74 implemented list toppers function
nishanth
parents: 39
diff changeset
   142
42
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   143
    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
   144
75
f7ee769f0d95 all the admin key checking is now done via urls
nishanth
parents: 74
diff changeset
   145
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
   146
    """ 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
   147
    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
   148
    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
   149
    """
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   150
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   151
    try:
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   152
        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
   153
    except IndexError:
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   154
        return redirect('/event/create/%s'%ADMIN_KEY)
44
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   155
42
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   156
    try:
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   157
        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
   158
    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
   159
        raise Http404
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   160
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   161
    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
   162
        raise Http404
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   163
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   164
    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
   165
    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
   166
        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
   167
            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
   168
            ans.save()
007d87112911 created a user_dump page that shows all the answers entered by user at one place
nishanth
parents: 41
diff changeset
   169
        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
   170
    else:
44
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   171
        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
   172
75
f7ee769f0d95 all the admin key checking is now done via urls
nishanth
parents: 74
diff changeset
   173
def que_dump(request, que_id):
44
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   174
    """ check for admin key
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   175
    then simply render all answers corresponding to the question.
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   176
    """
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   177
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   178
    try:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   179
        event = Event.objects.all()[0]
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   180
    except IndexError:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   181
        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
   182
44
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   183
    try:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   184
        question = QuestionBank.objects.get(id=que_id)
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   185
    except QuestionBank.DoesNotExist:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   186
        raise Http404
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   187
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   188
    quiz_num = question.quiz_num
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   189
    quiz_name = num2name[quiz_num]
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   190
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   191
    answers = question.answer.all()
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   192
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   193
    if request.method == "POST":
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   194
        for ans in answers:
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   195
            ans.is_correct = True if str(ans.id) in request.POST else False
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   196
            ans.save()
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   197
        return redirect("/quiz/toppers/%s/%s"%(ADMIN_KEY, quiz_num))
ffc035725a4e created que_dump page
nishanth
parents: 42
diff changeset
   198
    else:
48
aae2f69ba89c updated the que_dump template to show the question properly.
nishanth
parents: 44
diff changeset
   199
        return render_to_response("que_dump.html", {"quiz_name":quiz_name, "question":question, "answers":answers})