testappproj/testapp/views.py
author amit@thunder
Fri, 25 Jun 2010 03:59:57 +0530
changeset 5 548c6261fa00
parent 4 4d5422e5a45d
child 6 d0f107095b1a
permissions -rwxr-xr-x
A pure python way to compare the solution images
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
     7
import StringIO
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
     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
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
    35
from django.contrib.auth.decorators import login_required 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
    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
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
    38
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
    39
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
    40
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
    41
  """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
    42
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
    43
  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
    44
    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
    45
    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
    46
      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
    47
    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
    48
    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
    49
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
    50
  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
    51
    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
    52
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
    53
  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
    54
    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
    55
  """
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
    56
  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
    57
     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
    58
  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
    59
    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
    60
    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
    61
  #   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
    62
  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
    63
    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
    64
  # 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
    65
  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
    66
  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
    67
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    68
def import_check(user_code):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    69
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    70
  no_imports=len(re.findall('import',user_code))
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    71
  
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    72
  if (no_imports >= 1):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    73
    return True
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    74
  return False
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    75
  
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    76
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    77
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    78
def plot_change_code(user_code):
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
    79
  user_code=re.sub("show\(\)",'',user_code)
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
    80
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    81
  return user_code
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    82
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    83
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    84
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    85
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    86
def check_examination_done(f):
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    87
        def wrap(request, *args, **kwargs):
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    88
                #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
    89
              
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    90
                if unicode(request.user)==unicode('amit'):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    91
                  print "hello what the hell"
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    92
                  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
    93
                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
    94
                if user.exam_done==True:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    95
                        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
    96
                return f(request, *args, **kwargs)
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    97
        return wrap
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    98
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    99
  
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   100
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   101
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   102
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   103
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   104
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   105
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   106
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   107
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   108
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
   109
   
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   110
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   111
  solved=False
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   112
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   113
  if import_check(user_code):
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   114
    print "entered"
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   115
    return solved,None,True
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   116
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   117
 
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   118
  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
   119
   
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   120
  
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   121
  user_code=plot_change_code(user_code)
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   122
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   123
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   124
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   125
  code="""from pylab import *
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   126
import pylab
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   127
%s
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   128
figure_conf=pylab.gcf()
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   129
figure_conf.set_size_inches(10,10)
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   130
figure_conf.set_dpi(80)
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   131
figure_conf.savefig('%s')"""%(user_code,user_image_name)
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   132
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   133
  
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   134
  print code
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   135
  # create file-like string to capture output
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   136
  codeOut = StringIO.StringIO()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   137
  codeErr = StringIO.StringIO()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   138
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   139
  print str(codeOut)
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   140
  
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   141
  # capture output and errors
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   142
  sys.stdout = codeOut
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   143
  sys.stderr = codeErr
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   144
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   145
 
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   146
  sandbox.execute(code)
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   147
5
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
 
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   150
# restore stdout and stderr
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   151
  sys.stdout = sys.__stdout__
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   152
  sys.stderr = sys.__stderr__
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   153
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   154
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   155
  new_solution_image='media-root/'+str((solution_image))
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   156
  solution_image_matrix=imread(new_solution_image)
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   157
  print str(solution_image_matrix)
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   158
  print user_image_name
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   159
  user_image_matrix=imread(user_image_name)
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   160
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   161
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   162
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   163
  if solution_image_matrix==user_image_matrix:
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   164
    solved=True
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   165
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   166
  errors=codeErr.getvalue()  
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   167
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   168
  codeOut.close()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   169
  codeErr.close()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   170
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   171
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   172
  print solved
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   173
  return solved,errors,False
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   174
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   175
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
   176
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   177
  solved=False
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   178
 
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   179
 
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   180
  if import_check(code):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   181
    print "entered"
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   182
    return solved,None,True
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   183
  # create file-like string to capture output
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   184
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   185
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   186
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   187
  codeOut = StringIO.StringIO()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   188
  codeErr = StringIO.StringIO()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   189
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   190
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   191
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   192
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   193
  # capture output and errors
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   194
  sys.stdout = codeOut
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   195
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   196
  sys.stderr = codeErr
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   197
 
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   198
  sandbox.execute(code)
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   199
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   200
# restore stdout and stderr
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   201
  sys.stdout = sys.__stdout__
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   202
  sys.stderr = sys.__stderr__
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   203
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   204
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   205
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   206
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   207
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   208
  s = codeOut.getvalue()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   209
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   210
  s=unicode(s)
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   211
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   212
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   213
  print s.strip()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   214
  print solution.strip()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   215
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   216
 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   217
     
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   218
  if solution.strip() == s.strip():
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   219
    solved =True
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   220
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   221
  errors=codeErr.getvalue()
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   222
  
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   223
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   224
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   225
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   226
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   227
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   228
  codeOut.close()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   229
  codeErr.close()
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   230
  
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   231
  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
   232
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
   233
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   234
def complete(request):
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   235
  print request.user
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   236
  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
   237
  user.exam_done=True
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   238
  user.save()
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   239
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   240
  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
   241
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   242
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   243
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   244
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
   245
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
   246
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
   247
  """ 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
   248
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
   249
  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
   250
  
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
   251
  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
   252
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   253
   
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
   254
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   255
@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
   256
@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
   257
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
   258
  user = request.user
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   259
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   260
  entries=[]
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   261
  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
   262
  
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
   263
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
   264
  
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   265
  
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
   266
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
   267
  
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
   268
  #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
   269
  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
   270
    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
   271
    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
   272
             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
   273
             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
   274
             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
   275
               )
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
   276
    entries.append(e)
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   277
    
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
   278
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
   279
  return respond(request, user, 'problems',{'entries' : entries }  )
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   280
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   281
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   282
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   283
@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
   284
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
   285
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   286
#  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
   287
  problem = Problem.objects.get(id=int(problem_id))
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   288
  
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
   289
  if problem is None:
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   290
  
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
   291
    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
   292
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   293
  print problem.id
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   294
  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
   295
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
def run(request):
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   297
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   298
   user = request.user 
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   299
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   300
   problem_id = request.POST.get('problem_id')
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   301
  
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   302
   if problem_id:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   303
     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
   304
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   305
     if problem is None:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   306
       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
   307
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   308
   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
   309
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   310
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   311
   if  user_code == '':
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   312
     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
   313
  
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   314
    
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   315
   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
   316
   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
   317
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   318
   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
   319
  
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   320
   print problem.problem_type
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   321
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
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   323
   if unicode(problem.problem_type)==unicode('S'):
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   324
     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
   325
   else :
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   326
     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
   327
   
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   328
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   329
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   330
   print solved
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   331
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   332
   if import_test==True:
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   333
     
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   334
     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
   335
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   336
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   337
   if solved==True:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   338
    
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   339
     #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
   340
     try:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   341
       print user.id
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   342
       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
   343
       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
   344
       score_for_user.save()
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   345
    
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   346
    # user has answered questions previously
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   347
     except Score.DoesNotExist:
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   348
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   349
       score_new_user=user.id
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   350
       score_total_credits=problem.credit
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   351
       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
   352
       score.save()
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   353
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   354
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   355
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   356
   else:
5
548c6261fa00 A pure python way to compare the solution images
amit@thunder
parents: 4
diff changeset
   357
     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
   358
     
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   359
 
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   360
   return http.HttpResponse("Right Answer")
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   361
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
   362
  
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
   363
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
   364
@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
   365
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
   366
  
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
   367
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
   368
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
   369
  # internal indicates that it is being called internally by uploader
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   370
  
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
   371
  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
   372
  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
   373
    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
   374
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
   375
  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
   376
    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
   377
  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
   378
    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
   379
    
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
   380
  if request.method == 'POST':
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   381
    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
   382
  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
   383
    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
   384
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
   385
  
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
   386
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
   387
  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
   388
    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
   389
  
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
   390
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
   391
  
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
   392
  
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
   393
  if form.is_valid():
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   394
    try:
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   395
      description = form.cleaned_data['Description']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   396
      problem_type=form.cleaned_data['Problem_type']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   397
      solution=form.cleaned_data['Solution']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   398
      session=form.cleaned_data['Session']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   399
      credit=form.cleaned_data['Credit']
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   400
   # solution_image=form.cleaned_data['Solution_Image']
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   401
      solution_image=request.FILES['Solution_Image']
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   402
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   403
      author = user.username
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   404
      created = date.today()
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   405
      modified=date.today()
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   406
    
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   407
    # print request.FILES 
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   408
    # print "this is solution"+solution
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   409
    # print "this is solution_image"+solution_image
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   410
  
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   411
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   412
      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
   413
    
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   414
    except MultiValueDictKeyError:
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   415
      description = form.cleaned_data['Description']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   416
      problem_type=form.cleaned_data['Problem_type']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   417
      solution=form.cleaned_data['Solution']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   418
      session=form.cleaned_data['Session']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   419
      credit=form.cleaned_data['Credit']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   420
   # solution_image=form.cleaned_data['Solution_Image']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   421
    
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   422
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   423
      author = user.username
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   424
      created = date.today()
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   425
      modified=date.today()
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   426
    
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   427
      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
   428
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   429
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
   430
    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
   431
    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
   432
  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
   433
    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
   434
    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
   435
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
   436
#  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
   437
  #  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
   438
  #    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
   439
      
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
   440
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   441
  if form.errors:
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   442
    print "new world"
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   443
    return respond(request, user, 'new_edit_problem', 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   444
                         {'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
   445
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
   446
  # 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
   447
  #   # 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
   448
  #   #   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
   449
  #   #     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
   450
  #   #     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
   451
  #   #   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
   452
  #   #     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
   453
  #   # 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
   454
    
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
   455
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
   456
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
   457
    
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
   458
  
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
   459
   
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
   460
#  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
   461
  # 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
   462
  #   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
   463
  # 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
   464
  # 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
   465
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
   466
  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
   467
    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
   468
  
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
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
  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
   471
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
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