author | amit@thunder |
Mon, 12 Jul 2010 15:16:52 +0530 | |
changeset 6 | d0f107095b1a |
parent 5 | 548c6261fa00 |
permissions | -rwxr-xr-x |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
1 |
# Python imports |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
2 |
import doctest |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
3 |
import logging |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
4 |
import os |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
5 |
import traceback |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
6 |
import random |
1 | 7 |
import StringIO |
8 |
import sys |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
9 |
import json |
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
10 |
import time |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
11 |
import sandbox |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
12 |
import re |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
13 |
from matplotlib.pyplot import imread |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
14 |
from numpy import alltrue |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
15 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
16 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
17 |
from django.contrib.auth.models import User |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
18 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
19 |
from testappproj.testapp.models import * |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
20 |
from django.http import HttpResponse |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
21 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
22 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
23 |
from django import http |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
24 |
from django import shortcuts |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
25 |
from django.template import Context ,RequestContext |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
26 |
from django.template.loader import get_template |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
27 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
28 |
# Local imports |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
29 |
from forms import * |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
30 |
import models |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
31 |
from helpers import bulkuploader as pykataupload |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
32 |
from datetime import date |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
33 |
from django.contrib.auth.decorators import permission_required |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
34 |
from models import Problem |
1 | 35 |
from django.contrib.auth.decorators import login_required |
36 |
from models import Score |
|
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
37 |
from django.utils.datastructures import MultiValueDictKeyError |
6 | 38 |
from subprocess import PIPE,Popen,STDOUT |
39 |
||
40 |
||
41 |
class RGBvalues(object): |
|
42 |
def __init__(self): |
|
43 |
self.red=None |
|
44 |
self.green=None |
|
45 |
self.blue=None |
|
46 |
self.alpha=None |
|
47 |
self.all=None |
|
48 |
self.rgb_dict=None |
|
49 |
def get_values(self,output): |
|
50 |
print output |
|
51 |
k=re.search(r"red:.*",output,re.DOTALL) |
|
52 |
all_values_string=output[k.start():k.end()] |
|
53 |
self.rgb_list=re.findall('(?<=: )\d+',all_values_string) |
|
54 |
self.red=self.rgb_list[0] |
|
55 |
self.green=self.rgb_list[1] |
|
56 |
self.blue=self.rgb_list[2] |
|
57 |
self.alpha=self.rgb_list[3] |
|
58 |
self.all=self.rgb_list[4] |
|
59 |
return self.rgb_list |
|
60 |
||
61 |
||
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
62 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
63 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
64 |
def respond(request, user,template, params=None): |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
65 |
"""Helper to render a response, passing standard stuff to the response. |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
66 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
67 |
Args: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
68 |
request: The request object. |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
69 |
user: The User object representing the current user; or None if nobody |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
70 |
is logged in. |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
71 |
template: The template name; '.html' is appended automatically. |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
72 |
params: A dict giving the template parameters; modified in-place. |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
73 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
74 |
Returns: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
75 |
Whatever render_to_response(template, params) returns. |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
76 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
77 |
Raises: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
78 |
Whatever render_to_response(template, params) raises. |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
79 |
""" |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
80 |
if params is None: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
81 |
params = {} |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
82 |
if user: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
83 |
params['user'] = user |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
84 |
params['sign_out'] = 1 |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
85 |
# params['is_admin'] = (users.is_current_user_admin()) |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
86 |
else: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
87 |
params['sign_in'] = 1 |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
88 |
# if not template.endswith('.html'): |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
89 |
template += '.html' |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
90 |
return shortcuts.render_to_response(template, params) |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
91 |
|
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
92 |
def import_check(user_code): |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
93 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
94 |
no_imports=len(re.findall('import',user_code)) |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
95 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
96 |
if (no_imports >= 1): |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
97 |
return True |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
98 |
return False |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
99 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
100 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
101 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
102 |
def plot_change_code(user_code): |
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
103 |
user_code=re.sub("show\(\)",'',user_code) |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
104 |
|
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
105 |
return user_code |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
106 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
107 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
108 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
109 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
110 |
def check_examination_done(f): |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
111 |
def wrap(request, *args, **kwargs): |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
112 |
#this check the session if userid key exist, if not it will redirect to login page |
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
113 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
114 |
if unicode(request.user)==unicode('amit'): |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
115 |
print "hello what the hell" |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
116 |
return f(request, *args, **kwargs) |
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
117 |
user= Test_User.objects.get(user=request.user) |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
118 |
if user.exam_done==True: |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
119 |
return HttpResponse("You have given the exam before") |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
120 |
return f(request, *args, **kwargs) |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
121 |
return wrap |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
122 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
123 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
124 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
125 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
126 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
127 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
128 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
129 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
130 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
131 |
|
2 | 132 |
def execute_plotting_test_cases(user_code , solution_image,problem_id , username): |
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
133 |
|
2 | 134 |
|
135 |
solved=False |
|
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
136 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
137 |
if import_check(user_code): |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
138 |
print "entered" |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
139 |
return solved,None,True |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
140 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
141 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
142 |
user_image_name = str(username)+'_'+str(problem_id)+'_'+str(int(time.time()))+'.png' |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
143 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
144 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
145 |
user_code=plot_change_code(user_code) |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
146 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
147 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
148 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
149 |
code="""from pylab import * |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
150 |
import pylab |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
151 |
%s |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
152 |
figure_conf=pylab.gcf() |
6 | 153 |
figure_conf.set_size_inches(10,7.5) |
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
154 |
figure_conf.set_dpi(80) |
6 | 155 |
figure_conf.savefig('%s',dpi=80)"""%(user_code,user_image_name) |
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
156 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
157 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
158 |
print code |
2 | 159 |
# create file-like string to capture output |
160 |
codeOut = StringIO.StringIO() |
|
161 |
codeErr = StringIO.StringIO() |
|
162 |
||
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
163 |
print str(codeOut) |
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
164 |
|
2 | 165 |
# capture output and errors |
166 |
sys.stdout = codeOut |
|
167 |
sys.stderr = codeErr |
|
168 |
||
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
169 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
170 |
sandbox.execute(code) |
2 | 171 |
|
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
172 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
173 |
|
2 | 174 |
# restore stdout and stderr |
175 |
sys.stdout = sys.__stdout__ |
|
176 |
sys.stderr = sys.__stderr__ |
|
177 |
||
178 |
||
6 | 179 |
solution_image_name='media-root/'+str((solution_image)) |
180 |
# solution_image_matrix=imread(new_solution_image) |
|
181 |
# # print str(solution_image_matrix) |
|
182 |
# # print user_image_name |
|
183 |
# user_image_matrix=imread(user_image_name) |
|
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
184 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
185 |
errors=codeErr.getvalue() |
2 | 186 |
|
187 |
codeOut.close() |
|
188 |
codeErr.close() |
|
6 | 189 |
|
190 |
cmd = 'compare -verbose -metric MAE %s %s null: 2>&1'%(solution_image_name,user_image_name) |
|
191 |
print cmd |
|
192 |
p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT) |
|
193 |
||
194 |
output = p.stdout.read() |
|
195 |
print output |
|
196 |
k=RGBvalues() |
|
197 |
print k.get_values(output) |
|
198 |
print k.all |
|
199 |
||
200 |
if k.all<=250: |
|
201 |
solved=True |
|
202 |
# if solution_image_matrix==user_image_matrix: |
|
203 |
# solved=True |
|
204 |
||
205 |
||
2 | 206 |
|
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
207 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
208 |
print solved |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
209 |
return solved,errors,False |
2 | 210 |
|
1 | 211 |
def execute_test_cases(code , solution): |
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
212 |
|
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
213 |
solved=False |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
214 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
215 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
216 |
if import_check(code): |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
217 |
print "entered" |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
218 |
return solved,None,True |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
219 |
# create file-like string to capture output |
1 | 220 |
|
221 |
||
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
222 |
|
1 | 223 |
codeOut = StringIO.StringIO() |
224 |
codeErr = StringIO.StringIO() |
|
225 |
||
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
226 |
|
1 | 227 |
|
228 |
||
229 |
# capture output and errors |
|
230 |
sys.stdout = codeOut |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
231 |
|
1 | 232 |
sys.stderr = codeErr |
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
233 |
|
6 | 234 |
try: |
235 |
sandbox.execute(code) |
|
236 |
except : |
|
237 |
print "ok now we are at something" |
|
1 | 238 |
# restore stdout and stderr |
239 |
sys.stdout = sys.__stdout__ |
|
240 |
sys.stderr = sys.__stderr__ |
|
241 |
||
242 |
||
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
243 |
|
1 | 244 |
|
245 |
||
246 |
s = codeOut.getvalue() |
|
247 |
||
248 |
s=unicode(s) |
|
249 |
||
250 |
||
251 |
print s.strip() |
|
252 |
print solution.strip() |
|
253 |
||
254 |
||
255 |
||
256 |
if solution.strip() == s.strip(): |
|
257 |
solved =True |
|
258 |
||
259 |
errors=codeErr.getvalue() |
|
2 | 260 |
|
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
261 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
262 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
263 |
|
1 | 264 |
|
265 |
||
266 |
codeOut.close() |
|
267 |
codeErr.close() |
|
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
268 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
269 |
return solved,errors,False |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
270 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
271 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
272 |
def complete(request): |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
273 |
print request.user |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
274 |
user= Test_User.objects.get(user=request.user) |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
275 |
user.exam_done=True |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
276 |
user.save() |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
277 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
278 |
return respond(request, request.user ,'submit') |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
279 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
280 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
281 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
282 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
283 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
284 |
def index(request): |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
285 |
""" need to change user in the django.contrib way""" |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
286 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
287 |
user = request.user |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
288 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
289 |
return respond(request , user, 'index') |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
290 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
291 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
292 |
|
1 | 293 |
@login_required(function=None, redirect_field_name='next') |
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
294 |
@check_examination_done |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
295 |
def problems(request, category=None): |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
296 |
user = request.user |
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
297 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
298 |
entries=[] |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
299 |
all_sessions=set([element.session for element in Problem.objects.all()]) |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
300 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
301 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
302 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
303 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
304 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
305 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
306 |
#get problems to solve from each session. |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
307 |
for session in all_sessions: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
308 |
get_problem=random.Random().choice(Problem.objects.filter(session=session)) |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
309 |
e = dict(problem=get_problem.description, |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
310 |
username=user.username, |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
311 |
problem_id=get_problem.id, |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
312 |
session =get_problem.session |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
313 |
) |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
314 |
entries.append(e) |
1 | 315 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
316 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
317 |
return respond(request, user, 'problems',{'entries' : entries } ) |
2 | 318 |
|
319 |
||
320 |
||
1 | 321 |
@login_required(function=None, redirect_field_name='next') |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
322 |
def code(request, problem_id): |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
323 |
|
1 | 324 |
# print problem_id |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
325 |
problem = Problem.objects.get(id=int(problem_id)) |
1 | 326 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
327 |
if problem is None: |
1 | 328 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
329 |
return http.HttpResponseNotFound('No such problem.') |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
330 |
|
1 | 331 |
print problem.id |
332 |
return respond(request, request.user ,'code' ,{'problem' : problem } ) |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
333 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
334 |
def run(request): |
1 | 335 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
336 |
user = request.user |
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
337 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
338 |
problem_id = request.POST.get('problem_id') |
1 | 339 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
340 |
if problem_id: |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
341 |
problem = Problem.objects.get(id=int(problem_id)) |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
342 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
343 |
if problem is None: |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
344 |
return http.HttpResponse('There is no problem like this are you sure you solved it') |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
345 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
346 |
user_code = request.POST.get('user_code') |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
347 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
348 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
349 |
if user_code == '': |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
350 |
return http.HttpResponse('No solution') |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
351 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
352 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
353 |
user_code = user_code.replace('\r\n', '\n') |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
354 |
user_code += '\n\n' |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
355 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
356 |
errors = '' |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
357 |
|
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
358 |
print problem.problem_type |
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
359 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
360 |
|
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
361 |
if unicode(problem.problem_type)==unicode('S'): |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
362 |
solved,errors,import_test= execute_test_cases(user_code,problem.solution) |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
363 |
else : |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
364 |
solved,errors,import_test= execute_plotting_test_cases(user_code,problem.solution_image,problem_id,user) |
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
365 |
|
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
366 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
367 |
|
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
368 |
print solved |
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
369 |
|
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
370 |
if import_test==True: |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
371 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
372 |
return http.HttpResponse("DO NOT try to import or your exam and account will invalidated") |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
373 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
374 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
375 |
if solved==True: |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
376 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
377 |
#user is answering his first question |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
378 |
try: |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
379 |
print user.id |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
380 |
score_for_user= Score.objects.get(user=user) |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
381 |
score_for_user.total_credits+=problem.credit |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
382 |
score_for_user.save() |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
383 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
384 |
# user has answered questions previously |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
385 |
except Score.DoesNotExist: |
1 | 386 |
|
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
387 |
score_new_user=user.id |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
388 |
score_total_credits=problem.credit |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
389 |
score=Score(user_id=user.id,total_credits=score_total_credits) |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
390 |
score.save() |
1 | 391 |
|
392 |
||
393 |
||
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
394 |
else: |
5
548c6261fa00
A pure python way to compare the solution images
amit@thunder
parents:
4
diff
changeset
|
395 |
return http.HttpResponse('Wrong Answer') |
3
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
396 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
397 |
|
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
398 |
return http.HttpResponse("Right Answer") |
34d0c21e3352
Checking if exam has been previously done by the user or not
amit@thunder
parents:
2
diff
changeset
|
399 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
400 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
401 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
402 |
@permission_required('testapp.add_problem' , login_url="/code/1234") |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
403 |
def new_edit(request, problem_id=None, internal=False): |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
404 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
405 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
406 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
407 |
# internal indicates that it is being called internally by uploader |
2 | 408 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
409 |
user = request.user |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
410 |
if user.is_anonymous() : |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
411 |
return http.HttpResponseForbidden('You must be an signed in to create edit a problem.') |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
412 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
413 |
if problem_id is None: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
414 |
creating_new = True |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
415 |
else: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
416 |
creating_new = False |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
417 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
418 |
if request.method == 'POST': |
2 | 419 |
form = ProblemForm(request.POST, request.FILES) |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
420 |
else: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
421 |
form = ProblemForm() |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
422 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
423 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
424 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
425 |
if not request.POST: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
426 |
return respond(request, user, 'new_edit_problem', {'form':form, 'problem':None, 'creating':creating_new }) |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
427 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
428 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
429 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
430 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
431 |
if form.is_valid(): |
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
432 |
try: |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
433 |
description = form.cleaned_data['Description'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
434 |
problem_type=form.cleaned_data['Problem_type'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
435 |
solution=form.cleaned_data['Solution'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
436 |
session=form.cleaned_data['Session'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
437 |
credit=form.cleaned_data['Credit'] |
2 | 438 |
# solution_image=form.cleaned_data['Solution_Image'] |
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
439 |
solution_image=request.FILES['Solution_Image'] |
1 | 440 |
|
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
441 |
author = user.username |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
442 |
created = date.today() |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
443 |
modified=date.today() |
2 | 444 |
|
445 |
# print request.FILES |
|
446 |
# print "this is solution"+solution |
|
447 |
# print "this is solution_image"+solution_image |
|
1 | 448 |
|
2 | 449 |
|
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
450 |
problem=Problem(description=description,problem_type=problem_type,solution_image=solution_image,session=session,author=author,created=created,modified=modified,credit=credit) |
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
451 |
|
4
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
452 |
except MultiValueDictKeyError: |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
453 |
description = form.cleaned_data['Description'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
454 |
problem_type=form.cleaned_data['Problem_type'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
455 |
solution=form.cleaned_data['Solution'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
456 |
session=form.cleaned_data['Session'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
457 |
credit=form.cleaned_data['Credit'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
458 |
# solution_image=form.cleaned_data['Solution_Image'] |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
459 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
460 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
461 |
author = user.username |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
462 |
created = date.today() |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
463 |
modified=date.today() |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
464 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
465 |
problem=Problem(description=description,problem_type=problem_type,solution=solution,session=session,author=author,created=created,modified=modified,credit=credit) |
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
466 |
|
4d5422e5a45d
checking if somebody is importing a libarary in code
amit@thunder
parents:
3
diff
changeset
|
467 |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
468 |
problem.save() |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
469 |
print "saved" |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
470 |
else: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
471 |
print "form is valid" |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
472 |
print form.errors |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
473 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
474 |
# print form.errors |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
475 |
# except ValueError, err: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
476 |
# errors['__all__'] = unicode(err) |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
477 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
478 |
|
1 | 479 |
if form.errors: |
480 |
print "new world" |
|
481 |
return respond(request, user, 'new_edit_problem', |
|
482 |
{'form': form, 'problem':problem, 'creating':creating_new,'error':errors}) |
|
0
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
483 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
484 |
# if creating_new: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
485 |
# # if internal: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
486 |
# # if len(request.POST['user_id'])>0: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
487 |
# # logging.info(request.POST) |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
488 |
# # problem.author = users.User(request.POST['user_id']) |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
489 |
# # else: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
490 |
# # problem.author = user |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
491 |
# # else: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
492 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
493 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
494 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
495 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
496 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
497 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
498 |
# l = [] |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
499 |
# for x in problem.categories: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
500 |
# l.extend(x.split()) |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
501 |
# problem.categories = l |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
502 |
# problem.put() |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
503 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
504 |
if internal: |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
505 |
return ('success','success') |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
506 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
507 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
508 |
return http.HttpResponseRedirect('/problems') |
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
509 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
510 |
|
0b061d58aea3
First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff
changeset
|
511 |