testappproj/testapp/views.py
author amit@thunder
Mon, 31 May 2010 19:18:57 +0530
changeset 2 654c583fd78e
parent 1 0eda880b3d25
child 3 34d0c21e3352
permissions -rwxr-xr-x
Made some changes and templates
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
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
     9
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
    10
# # AppEngine 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
    11
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
    12
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
    13
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
    14
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
    15
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
    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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
# Django 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
    20
#from django.conf import settings
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
#settings._target = 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
    22
#os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
#import django
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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 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
    25
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
    26
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
    27
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
    28
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
# 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
    30
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
    31
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
    32
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
    33
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
    34
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
    35
from models import Problem
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
    36
from django.contrib.auth.decorators import login_required 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
    37
from models import Score 
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    38
import time
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    39
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    40
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    41
# def handle_uploaded_file(f):
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    42
#   print f  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    43
#   destination = open('some/file/name.txt', 'wb+')
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    44
#   for chunk in f.chunks():
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    45
#     destination.write(chunk)
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    46
#   destination.close()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    47
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    48
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
    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
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
    51
  """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
    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
  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
    54
    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
    55
    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
    56
      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
    57
    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
    58
    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
    59
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
    61
    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
    62
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
    64
    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
    65
  """
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
    67
     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
    68
  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
    69
    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
    70
    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
    71
  #   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
    72
  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
    73
    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
    74
  # 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
    75
  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
    76
  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
    77
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    78
def execute_plotting_test_cases(user_code , solution_image,problem_id , username):
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    79
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    80
  print  user_code 
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    81
  print "solution"+solution_image
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    82
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    83
  image_name = username+'_'+str(problem_id)+'_'+time.time()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    84
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    85
  code="""from pylab import *
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    86
  %s
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    87
  show()"""%user_code
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    88
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    89
  solved=False
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    90
  # create file-like string to capture output
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    91
  codeOut = StringIO.StringIO()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    92
  codeErr = StringIO.StringIO()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    93
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    94
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    95
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    96
  # capture output and errors
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    97
  sys.stdout = codeOut
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    98
  sys.stderr = codeErr
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    99
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   100
  exec code
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   101
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   102
# restore stdout and stderr
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   103
  sys.stdout = sys.__stdout__
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   104
  sys.stderr = sys.__stderr__
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   105
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   106
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   107
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   108
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   109
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   110
  s = codeOut.getvalue()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   111
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   112
  s=unicode(s)
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   113
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   114
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   115
  print s.strip()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   116
  print solution.strip()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   117
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   118
 
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   119
     
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   120
  if solution.strip() == s.strip():
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   121
    solved =True
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   122
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   123
  errors=codeErr.getvalue()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   124
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   125
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   126
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   127
  codeOut.close()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   128
  codeErr.close()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   129
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   130
  return solved,errors
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   131
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   132
def execute_test_cases(code , 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
   133
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   134
  print code 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   135
  print "solution"+solution
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   136
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   137
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   138
  solved=False
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   139
  # create file-like string to capture output
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   140
  codeOut = StringIO.StringIO()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   141
  codeErr = StringIO.StringIO()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   142
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   143
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   144
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   145
  # capture output and errors
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   146
  sys.stdout = codeOut
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   147
  sys.stderr = codeErr
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   148
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   149
  exec code
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   150
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   151
# restore stdout and stderr
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   152
  sys.stdout = sys.__stdout__
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   153
  sys.stderr = sys.__stderr__
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   154
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   155
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
   156
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   157
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   158
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   159
  s = codeOut.getvalue()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   160
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   161
  s=unicode(s)
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   162
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   163
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   164
  print s.strip()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   165
  print solution.strip()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   166
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   167
 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   168
     
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   169
  if solution.strip() == s.strip():
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   170
    solved =True
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   171
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   172
  errors=codeErr.getvalue()
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   173
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   174
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   175
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   176
  codeOut.close()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   177
  codeErr.close()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   178
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   179
  return solved,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
   180
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   181
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   182
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   183
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
   184
  """ 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
   185
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   186
  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
   187
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   188
  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
   189
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   190
# def contribution(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
   191
# #  user = users.get_current_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
   192
#   return respond(request, user, 'contribution')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   193
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   194
# def help(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
   195
# #  user = users.get_current_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
   196
#   return respond(request, user, 'help')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   197
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   198
# def about(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
   199
# #  user = users.get_current_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
   200
#   return respond(request, user, 'about')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   201
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   202
# def vision(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
   203
# #  user = users.get_current_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
   204
#   return respond(request, user, 'vision')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   205
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   206
# def statements(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
   207
# #  user = users.get_current_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
   208
#   return respond(request, user, 'statements')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   209
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   210
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   211
def get_pu(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
   212
  '''
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   213
  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
   214
   - "USER_NOT_SIGNED_IN": user not signed in. returning this to prevent saving anonymous user's potentially crappy solution and display it to every anonymous visitor
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   215
   - "PU_NOT_FOUND": for signed in users when no solution has been attempted.
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   216
   - ProblemUser: for signed in users when a solution has been attempted
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   217
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   218
  '''
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   219
#  user = users.get_current_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
   220
#  if not 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
   221
#    return "USER_NOT_SIGNED_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
   222
  pu_query = models.ProblemUser.all().filter('problem = ', problem).filter('user =', users.get_current_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
   223
  pu_results = pu_query.fetch(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
   224
  if pu_results: 
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   225
    return pu_results[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
   226
  return "PU_NOT_FOUND"
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   227
   
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   228
# def is_solved(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
   229
#   pu = get_pu(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
   230
#   if pu == "PU_NOT_FOUND" or pu == "USER_NOT_SIGNED_IN": return 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
   231
#   return pu.solved
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   232
@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
   233
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
   234
  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
   235
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   236
  # if category 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
   237
  #   problems = db.GqlQuery('SELECT * FROM Problem ORDER BY created DESC')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   238
  # 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
   239
  #   problems = db.GqlQuery('SELECT * FROM Problem WHERE categories = :1 ORDER BY created DESC', category)
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   240
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   241
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   242
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   243
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   244
  # entries = []
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  # for problem in 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
   246
  #   e = dict(problem=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
   247
  #            username=problem.author.nickname().partition('@')[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
   248
  #            solved=is_solved(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
   249
  #   entries.append(e)
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  # problems = entries
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  entries=[]
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  all_sessions=set([element.session  for element in Problem.objects.all()])
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   253
  print 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
   254
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   255
  # for problem in 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
   256
  #    e = dict(problem=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
   257
  #             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
   258
  #             problem_id=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
   259
             
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   260
  #             )
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   261
  #    entries.append(e)
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
#  print entries
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   265
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  #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
   267
  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
   268
    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
   269
    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
   270
             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
   271
             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
   272
             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
   273
               )
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    entries.append(e)
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   275
    
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
   276
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   277
  return respond(request, user, 'problems',{'entries' : entries }  )
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   278
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   279
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   280
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   281
@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
   282
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
   283
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   284
#  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
   285
  problem = Problem.objects.get(id=int(problem_id))
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   286
  
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
  if problem is None:
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
    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
   290
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
#  pu = get_pu(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
#  if pu == "PU_NOT_FOUND":  # user is attempting problem for the first time
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   293
#    pu = models.ProblemUser(problem=problem, user=users.get_current_user(), solution='', solved=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
   294
#    pu.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
   295
#    pu = None
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   296
  print problem.id
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   297
  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
   298
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   299
def run(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
   300
  user = request.user 
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   301
  print request.POST
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   302
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
   303
  problem_id = request.POST.get('problem_id')
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   304
  
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
   305
  if 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
   306
    problem = Problem.objects.get(id=int(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
   307
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    if problem 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
   309
      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
   310
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  user_code = request.POST.get('user_code')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  if not user_code:
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    return http.HttpResponse('bad 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
   315
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  # pu = get_pu(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
   317
  # # update ProblemUser object for this 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
   318
  # if (pu.__class__ == models.ProblemUser):
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  #   pu.solution = user_code
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   320
  #   pu.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
   321
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  user_code = user_code.replace('\r\n', '\n')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  user_code += '\n\n'
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   324
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   326
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   328
  # try:
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   329
  #   print user_code
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   330
  #   compiled = compile(user_code, 'error_file', 'exec')
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   331
  #   g = {}
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   332
  #   exec compiled in g
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
#    s = problem.tests.replace('\r\n', '\n')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   335
#    s += '\n\n'
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   336
    # test_cases = doctest.DocTestParser().get_examples(s) 
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   337
  solved,errors = execute_test_cases(user_code,problem.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
   338
    # if solved:
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   339
    #   pu = get_pu(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
   340
    #   if pu.__class__ == models.ProblemUser:
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   341
    #     pu.solved = 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
   342
    #     pu.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
   343
    # 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
   344
    #   pu = get_pu(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
   345
    #   if pu.__class__ == models.ProblemUser:
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   346
    #     pu.solved = 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
   347
    #     pu.put()
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   348
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   349
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   350
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   351
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   352
  if solved==True:
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
    #user is answering his first question
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   355
    try:
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   356
   # print user.id
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   357
      score_for_user= Score.objects.get(user=user)
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   358
      score_for_user.total_credits+=problem.credit
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   359
      score_for_user.save()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   360
    
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   361
   # user has answered questions previously
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   362
    except Score.DoesNotExist:
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   363
#      print user.id 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   364
      score_new_user=user.id
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   365
      score_total_credits=problem.credit
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   366
      score=Score(user_id=user.id,total_credits=score_total_credits)
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   367
      score.save()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   368
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   369
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   370
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   371
  else:
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   372
    print "oops"
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   373
  results=solved
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   374
      
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
   375
  return respond(request, request.user, 'run', {'results': results})
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
@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
   379
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
   380
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   381
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  # internal indicates that it is being called internally by uploader
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   384
  
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
   385
  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
   386
  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
   387
    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
   388
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   390
    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
   391
  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
   392
    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
   393
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   394
  if request.method == 'POST':
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   395
    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
   396
  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
   397
    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
   398
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   399
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   402
    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
   403
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  if 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
   408
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    description = form.cleaned_data['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
   410
    problem_type=form.cleaned_data['Problem_type']
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    solution=form.cleaned_data['Solution']
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    session=form.cleaned_data['Session']
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   413
    credit=form.cleaned_data['Credit']
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   414
   # solution_image=form.cleaned_data['Solution_Image']
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   415
    solution_image=request.FILES['Solution_Image']
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   416
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
   417
    author = 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
   418
    created = date.today()
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   419
    modified=date.today()
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   420
    
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   421
    # print request.FILES 
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   422
    # print "this is solution"+solution
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   423
    # print "this is solution_image"+solution_image
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   424
  
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   425
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   426
    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
   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
    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
   429
    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
   430
  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
   431
    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
   432
    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
   433
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  #  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
   436
  #    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
   437
      
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   439
  if form.errors:
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   440
    print "new world"
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   441
    return respond(request, user, 'new_edit_problem', 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   442
                         {'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
   443
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   444
  # 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
   445
  #   # 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
   446
  #   #   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
   447
  #   #     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
   448
  #   #     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
   449
  #   #   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
   450
  #   #     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
   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
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
#  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
   459
  # 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
   460
  #   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
   461
  # 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
   462
  # 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
   463
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   465
    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
   466
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   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
def upload(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
   471
  """ upload handler, validates the form and calls handle_uploaded_file
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      for processing further
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   475
  if user 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
   476
    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
   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
  if request.method == '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
   479
    form = UploadForm(request.POST, request.FILES)
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   480
    if 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
   481
      submission_report = handle_uploaded_file(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
   482
      print "testing"
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      print submission_report
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      return respond(request, user, 'upload', {'report':submission_report})
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    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
   487
      return http.HttpResponseForbidden('Oops something went wrong with the upload')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
def handle_uploaded_file(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
   490
  """ Handles uploaded data, pushes it to existing problem creating code
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      TODO: 1. make efficient by putting actual database code Here
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
            2. Add more security and validation
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  submission_data = request.FILES['file'].read()
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  if '#---' in submission_data:
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    all_submissions = submission_data.split('#---')[1:-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
   497
    # ^^ ignoring the first null and last __main__ code
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    all_submissions = [ pykataupload.Submission(x) for x in all_submissions ]
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    report = []
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    for key,each_submission in enumerate(all_submissions):
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      # TODO: handle these later by TaskQueues to avoid timeouts on big uploads
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      # a good way would be to have ajax based status coming back to this page
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      # about each problem in the uploaded file, their status, progress etc.
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      each_submission.parse()
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      request.POST.clear()
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      request.POST.update (each_submission.data_dict)
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
      upload_status, upload_response = new_edit(request, internal=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
   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
      report.append ({'status':upload_status, 'name':each_submission['name'], 
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
                          'upload_response':upload_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
   512
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   513
      # Yay this hack works :D
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   514
    return report
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   515
  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
   516
    return http.HttpResponseForbidden('The file you uploaded is not in appropriate format.')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   517
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   518
def shell(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
   519
  """ 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
   520
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   521
  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
   522
  statement=request.GET.get('statement','')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   523
  if  statement is not '':
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   524
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   525
    # the python compiler doesn't like network line endings
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   526
    statement = statement.replace('\r\n', '\n')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   527
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   528
    # add a couple newlines at the end of the statement. this makes
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   529
    # single-line expressions such as 'class Foo: pass' evaluate happily.
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   530
    statement += '\n\n'
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   531
    print "statement"+statement 
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   532
    # log and compile the statement up front
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   533
    try:
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   534
      logging.info('Compiling and evaluating:\n%s' % statement)
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   535
      compiled = compile(statement, '<string>', 'single')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   536
    except:
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   537
       return HttpResponse(traceback.format_exc(),mimetype="text/plain")  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   538
#      pass
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   539
    return HttpResponse("",mimetype="text/plain")
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   540
  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
   541
    return respond(request, user, 'shell')
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   542
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   543