--- a/testappproj/testapp/views.py Mon Jun 14 01:00:59 2010 +0530
+++ b/testappproj/testapp/views.py Mon Jun 14 22:02:14 2010 +0530
@@ -31,8 +31,8 @@
from models import Score
import time
import sandbox
-
-
+import re
+from django.utils.datastructures import MultiValueDictKeyError
def respond(request, user,template, params=None):
"""Helper to render a response, passing standard stuff to the response.
@@ -61,13 +61,30 @@
template += '.html'
return shortcuts.render_to_response(template, params)
+def import_check(user_code):
+
+ no_imports=len(re.findall('import',user_code))
+
+ if (no_imports >= 1):
+ return True
+ return False
+
+
+
+def plot_change_code(user_code):
+ return user_code
+
+
def check_examination_done(f):
def wrap(request, *args, **kwargs):
#this check the session if userid key exist, if not it will redirect to login page
+
+ if unicode(request.user)==unicode('amit'):
+ print "hello what the hell"
+ return f(request, *args, **kwargs)
user= Test_User.objects.get(user=request.user)
-
if user.exam_done==True:
return HttpResponse("You have given the exam before")
return f(request, *args, **kwargs)
@@ -138,12 +155,16 @@
def execute_test_cases(code , solution):
-
-
+ solved=False
+
+
+ if import_check(code):
+ print "entered"
+ return solved,None,True
+ # create file-like string to capture output
- solved=False
- # create file-like string to capture output
+
codeOut = StringIO.StringIO()
codeErr = StringIO.StringIO()
@@ -154,7 +175,7 @@
sys.stdout = codeOut
sys.stderr = codeErr
- print "aaaklamnsldnlndskn"
+
sandbox.execute(code)
# restore stdout and stderr
@@ -162,7 +183,7 @@
sys.stderr = sys.__stderr__
- print "xs zc sdc"
+
s = codeOut.getvalue()
@@ -184,8 +205,8 @@
codeOut.close()
codeErr.close()
-
- return solved,errors
+
+ return solved,errors,False
def complete(request):
@@ -275,11 +296,15 @@
errors = ''
- print "ksmdlnjdns"
+
- solved,errors = execute_test_cases(user_code,problem.solution)
+ solved,errors,import_test= execute_test_cases(user_code,problem.solution)
-
+ if import_test==True:
+
+ return http.HttpResponse("DO NOT try to import or your exam and account will invalidated")
+
+
if solved==True:
#user is answering his first question
@@ -337,26 +362,42 @@
if form.is_valid():
-
- description = form.cleaned_data['Description']
- problem_type=form.cleaned_data['Problem_type']
- solution=form.cleaned_data['Solution']
- session=form.cleaned_data['Session']
- credit=form.cleaned_data['Credit']
+ try:
+ description = form.cleaned_data['Description']
+ problem_type=form.cleaned_data['Problem_type']
+ solution=form.cleaned_data['Solution']
+ session=form.cleaned_data['Session']
+ credit=form.cleaned_data['Credit']
# solution_image=form.cleaned_data['Solution_Image']
- solution_image=request.FILES['Solution_Image']
+ solution_image=request.FILES['Solution_Image']
- author = user.username
- created = date.today()
- modified=date.today()
+ author = user.username
+ created = date.today()
+ modified=date.today()
# print request.FILES
# print "this is solution"+solution
# print "this is solution_image"+solution_image
- problem=Problem(description=description,problem_type=problem_type,solution_image=solution_image,session=session,author=author,created=created,modified=modified,credit=credit)
+ problem=Problem(description=description,problem_type=problem_type,solution_image=solution_image,session=session,author=author,created=created,modified=modified,credit=credit)
+ except MultiValueDictKeyError:
+ description = form.cleaned_data['Description']
+ problem_type=form.cleaned_data['Problem_type']
+ solution=form.cleaned_data['Solution']
+ session=form.cleaned_data['Session']
+ credit=form.cleaned_data['Credit']
+ # solution_image=form.cleaned_data['Solution_Image']
+
+
+ author = user.username
+ created = date.today()
+ modified=date.today()
+
+ problem=Problem(description=description,problem_type=problem_type,solution=solution,session=session,author=author,created=created,modified=modified,credit=credit)
+
+
problem.save()
print "saved"
else: