testappproj/testapp/views.py
author amit@thunder
Mon, 14 Jun 2010 22:02:14 +0530
changeset 4 4d5422e5a45d
parent 3 34d0c21e3352
child 5 548c6261fa00
permissions -rwxr-xr-x
checking if somebody is importing a libarary in code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
     1
# Python imports
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
     2
import doctest
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
     3
import logging
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
     4
import os
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
     5
import traceback
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
     6
import random
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
     7
import StringIO
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
     8
import sys
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
     9
import json
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
    10
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
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
    19
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
    20
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
    21
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
    22
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
    23
# 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
    24
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
    25
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
    26
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
    27
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
    28
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
    29
from models import Problem
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
    30
from django.contrib.auth.decorators import login_required 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
    31
from models import Score 
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    32
import time
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    33
import sandbox
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    34
import re
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    35
from django.utils.datastructures import MultiValueDictKeyError
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
    36
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
    37
  """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
    38
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
    39
  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
    40
    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
    41
    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
    42
      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
    43
    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
    44
    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
    45
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
    46
  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
    47
    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
    48
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
    50
    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
    51
  """
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
    53
     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
    54
  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
    55
    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
    56
    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
    57
  #   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
    58
  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
    59
    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
    60
  # 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
    61
  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
    62
  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
    63
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    64
def import_check(user_code):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    65
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    66
  no_imports=len(re.findall('import',user_code))
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    67
  
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    68
  if (no_imports >= 1):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    69
    return True
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    70
  return False
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    71
  
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    72
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    73
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    74
def plot_change_code(user_code):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    75
  return user_code
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    76
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    77
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    78
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    79
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    80
def check_examination_done(f):
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    81
        def wrap(request, *args, **kwargs):
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    82
                #this check the session if userid key exist, if not it will redirect to login page
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    83
              
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    84
                if unicode(request.user)==unicode('amit'):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    85
                  print "hello what the hell"
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
    86
                  return f(request, *args, **kwargs)
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    87
                user= Test_User.objects.get(user=request.user)
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    88
                if user.exam_done==True:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    89
                        return HttpResponse("You have given the exam before")
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    90
                return f(request, *args, **kwargs)
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    91
        return wrap
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    92
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    93
  
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    94
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    95
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    96
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    97
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    98
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    99
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   100
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   101
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   102
def execute_plotting_test_cases(user_code , solution_image,problem_id , username):
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   103
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   104
  print  user_code 
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   105
  print "solution"+solution_image
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
  image_name = username+'_'+str(problem_id)+'_'+time.time()
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
  code="""from pylab import *
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   110
  %s
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   111
  show()"""%user_code
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   112
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   113
  solved=False
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   114
  # create file-like string to capture output
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   115
  codeOut = StringIO.StringIO()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   116
  codeErr = StringIO.StringIO()
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
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   119
  
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   120
  # capture output and errors
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   121
  sys.stdout = codeOut
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   122
  sys.stderr = codeErr
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   123
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   124
  sandbox.execute(code)
2
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
# restore stdout and stderr
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   127
  sys.stdout = sys.__stdout__
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   128
  sys.stderr = sys.__stderr__
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
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   131
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   132
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   133
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   134
  s = codeOut.getvalue()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   135
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   136
  s=unicode(s)
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   137
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   138
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   139
  print s.strip()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   140
  print solution.strip()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   141
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   142
 
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   143
     
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   144
  if solution.strip() == s.strip():
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   145
    solved =True
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   146
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   147
  errors=codeErr.getvalue()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   148
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   149
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   150
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   151
  codeOut.close()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   152
  codeErr.close()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   153
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   154
  return solved,errors
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   155
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   156
def execute_test_cases(code , solution):
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   157
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   158
  solved=False
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   159
 
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   160
 
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   161
  if import_check(code):
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   162
    print "entered"
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   163
    return solved,None,True
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   164
  # create file-like string to capture output
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   165
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   166
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   167
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   168
  codeOut = StringIO.StringIO()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   169
  codeErr = StringIO.StringIO()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   170
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   171
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   172
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   173
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   174
  # capture output and errors
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   175
  sys.stdout = codeOut
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   176
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   177
  sys.stderr = codeErr
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   178
 
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   179
  sandbox.execute(code)
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   180
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   181
# restore stdout and stderr
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   182
  sys.stdout = sys.__stdout__
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   183
  sys.stderr = sys.__stderr__
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   184
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   185
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   186
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   187
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   188
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   189
  s = codeOut.getvalue()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   190
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   191
  s=unicode(s)
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   192
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   193
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   194
  print s.strip()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   195
  print solution.strip()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   196
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   197
 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   198
     
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   199
  if solution.strip() == s.strip():
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   200
    solved =True
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   201
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   202
  errors=codeErr.getvalue()
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   203
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   204
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   205
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   206
  codeOut.close()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   207
  codeErr.close()
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   208
  
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   209
  return solved,errors,False
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   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
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   212
def complete(request):
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   213
  print request.user
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   214
  user= Test_User.objects.get(user=request.user)
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   215
  user.exam_done=True
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   216
  user.save()
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   217
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   218
  return respond(request, request.user ,'submit')
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   219
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   220
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   221
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   222
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
   223
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
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
   225
  """ 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
   226
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   228
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   230
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   231
   
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   232
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   233
@login_required(function=None, redirect_field_name='next')
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   234
@check_examination_done
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   235
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
   236
  user = request.user
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   237
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   238
  entries=[]
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   239
  all_sessions=set([element.session  for element in Problem.objects.all()])
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   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
  
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   243
  
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
   244
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   245
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   246
  #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
   247
  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
   248
    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
   249
    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
   250
             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
   251
             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
   252
             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
   253
               )
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    entries.append(e)
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   255
    
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
   256
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  return respond(request, user, 'problems',{'entries' : entries }  )
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   258
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   259
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   260
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   261
@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
   262
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
   263
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   264
#  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
   265
  problem = Problem.objects.get(id=int(problem_id))
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   266
  
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
   267
  if problem is None:
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   268
  
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
   269
    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
   270
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   271
  print problem.id
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   272
  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
   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
def run(request):
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   275
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   276
   user = request.user 
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   277
   print user
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   278
   problem_id = request.POST.get('problem_id')
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   279
  
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   280
   if problem_id:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   281
     problem = Problem.objects.get(id=int(problem_id))
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   282
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   283
     if problem is None:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   284
       return http.HttpResponse('There is no problem like this are you sure you solved it')
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   285
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   286
   user_code = request.POST.get('user_code')
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   287
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   288
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   289
   if  user_code == '':
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   290
     return http.HttpResponse('No solution')
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   291
  
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   292
    
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   293
   user_code = user_code.replace('\r\n', '\n')
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   294
   user_code += '\n\n'
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   295
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   296
   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
   297
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   299
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   300
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   301
   solved,errors,import_test= execute_test_cases(user_code,problem.solution)
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   302
   
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   303
   if import_test==True:
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   304
     
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   305
     return http.HttpResponse("DO NOT try to import or your exam and account will invalidated")
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   306
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   307
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   308
   if solved==True:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   309
    
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   310
     #user is answering his first question
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   311
     try:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   312
       print user.id
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   313
       score_for_user= Score.objects.get(user=user)
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   314
       score_for_user.total_credits+=problem.credit
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   315
       score_for_user.save()
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   316
    
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   317
    # user has answered questions previously
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   318
     except Score.DoesNotExist:
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   319
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   320
       score_new_user=user.id
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   321
       score_total_credits=problem.credit
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   322
       score=Score(user_id=user.id,total_credits=score_total_credits)
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   323
       score.save()
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   324
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   325
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   326
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   327
   else:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   328
     http.HttpResponse('Wrong Answer')
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   329
     
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   330
 
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   331
   return http.HttpResponse("Right Answer")
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   332
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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
@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
   336
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
   337
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  # internal indicates that it is being called internally by uploader
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   341
  
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   342
  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
   343
  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
   344
    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
   345
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   347
    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
   348
  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
   349
    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
   350
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   351
  if request.method == 'POST':
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   352
    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
   353
  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
   354
    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
   355
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   356
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   357
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   358
  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
   359
    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
   360
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   361
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   362
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   363
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   364
  if form.is_valid():
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   365
    try:
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   366
      description = form.cleaned_data['Description']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   367
      problem_type=form.cleaned_data['Problem_type']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   368
      solution=form.cleaned_data['Solution']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   369
      session=form.cleaned_data['Session']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   370
      credit=form.cleaned_data['Credit']
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   371
   # solution_image=form.cleaned_data['Solution_Image']
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   372
      solution_image=request.FILES['Solution_Image']
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   373
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   374
      author = user.username
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   375
      created = date.today()
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   376
      modified=date.today()
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   377
    
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   378
    # print request.FILES 
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   379
    # print "this is solution"+solution
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   380
    # print "this is solution_image"+solution_image
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   381
  
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   382
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   383
      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
   384
    
4
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   385
    except MultiValueDictKeyError:
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   386
      description = form.cleaned_data['Description']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   387
      problem_type=form.cleaned_data['Problem_type']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   388
      solution=form.cleaned_data['Solution']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   389
      session=form.cleaned_data['Session']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   390
      credit=form.cleaned_data['Credit']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   391
   # solution_image=form.cleaned_data['Solution_Image']
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   392
    
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   393
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   394
      author = user.username
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   395
      created = date.today()
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   396
      modified=date.today()
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   397
    
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   398
      problem=Problem(description=description,problem_type=problem_type,solution=solution,session=session,author=author,created=created,modified=modified,credit=credit)  
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   399
4d5422e5a45d checking if somebody is importing a libarary in code
amit@thunder
parents: 3
diff changeset
   400
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
   401
    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
   402
    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
   403
  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
   404
    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
   405
    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
   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
#  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
   408
  #  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
   409
  #    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
   410
      
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   412
  if form.errors:
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   413
    print "new world"
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   414
    return respond(request, user, 'new_edit_problem', 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   415
                         {'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
   416
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  # 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
   418
  #   # 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
   419
  #   #   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
   420
  #   #     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
   421
  #   #     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
   422
  #   #   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
   423
  #   #     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
   424
  #   # 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
   425
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   426
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   427
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   428
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   429
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   430
   
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   431
#  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
   432
  # 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
   433
  #   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
   434
  # 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
   435
  # 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
   436
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   438
    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
   439
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   440
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   441
  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
   442
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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