testappproj/testapp/views.py
author amit@thunder
Mon, 14 Jun 2010 01:00:59 +0530
changeset 3 34d0c21e3352
parent 2 654c583fd78e
child 4 4d5422e5a45d
permissions -rwxr-xr-x
Checking if exam has been previously done by the user or not
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
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    34
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
    35
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    64
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    65
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    66
def check_examination_done(f):
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    67
        def wrap(request, *args, **kwargs):
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    68
                #this check the session if userid key exist, if not it will redirect to login page
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    69
                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
    70
                
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    71
                if user.exam_done==True:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    72
                        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
    73
                return f(request, *args, **kwargs)
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    74
        return wrap
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    75
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    76
  
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    77
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
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    81
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    82
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    83
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
    84
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    85
def execute_plotting_test_cases(user_code , solution_image,problem_id , username):
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    86
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    87
  print  user_code 
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    88
  print "solution"+solution_image
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    89
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    90
  image_name = username+'_'+str(problem_id)+'_'+time.time()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    91
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    92
  code="""from pylab import *
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    93
  %s
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    94
  show()"""%user_code
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
  solved=False
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    97
  # create file-like string to capture output
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    98
  codeOut = StringIO.StringIO()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
    99
  codeErr = StringIO.StringIO()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   100
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   101
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   102
  
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   103
  # capture output and errors
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   104
  sys.stdout = codeOut
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   105
  sys.stderr = codeErr
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   106
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   107
  sandbox.execute(code)
2
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
# restore stdout and stderr
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   110
  sys.stdout = sys.__stdout__
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   111
  sys.stderr = sys.__stderr__
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
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
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   116
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   117
  s = codeOut.getvalue()
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
  s=unicode(s)
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   120
  
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   121
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   122
  print s.strip()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   123
  print solution.strip()
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
  if solution.strip() == s.strip():
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   128
    solved =True
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
  errors=codeErr.getvalue()
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
  codeOut.close()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   135
  codeErr.close()
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   136
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   137
  return solved,errors
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   138
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   139
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
   140
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   141
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
   142
  
1
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
  solved=False
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   146
  # create file-like string to capture output
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   147
  codeOut = StringIO.StringIO()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   148
  codeErr = StringIO.StringIO()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   149
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   150
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   151
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   152
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   153
  # capture output and errors
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   154
  sys.stdout = codeOut
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   155
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   156
  sys.stderr = codeErr
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   157
  print "aaaklamnsldnlndskn"
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   158
  sandbox.execute(code)
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   159
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   160
# restore stdout and stderr
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   161
  sys.stdout = sys.__stdout__
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   162
  sys.stderr = sys.__stderr__
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
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   165
  print "xs zc sdc"
1
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
  s = codeOut.getvalue()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   169
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   170
  s=unicode(s)
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
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   173
  print s.strip()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   174
  print solution.strip()
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
 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   177
     
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   178
  if solution.strip() == s.strip():
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   179
    solved =True
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
  errors=codeErr.getvalue()
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   182
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   183
  
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
  codeOut.close()
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   186
  codeErr.close()
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
  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
   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
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   191
def complete(request):
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   192
  print request.user
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   193
  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
   194
  user.exam_done=True
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   195
  user.save()
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   196
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   197
  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
   198
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   199
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   200
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   201
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
   202
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
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
   204
  """ 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
   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
  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
   207
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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, '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
   209
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   210
   
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
   211
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   212
@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
   213
@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
   214
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
   215
  user = request.user
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   216
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   217
  entries=[]
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   218
  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
   219
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  
3
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
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  #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
   226
  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
   227
    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
   228
    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
   229
             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
   230
             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
   231
             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
   232
               )
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   233
    entries.append(e)
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   234
    
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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  return respond(request, user, 'problems',{'entries' : entries }  )
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   237
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   238
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   239
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   240
@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
   241
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
   242
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   243
#  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
   244
  problem = Problem.objects.get(id=int(problem_id))
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   245
  
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
   246
  if problem is None:
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   247
  
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
    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
   249
  
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   250
  print problem.id
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   251
  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
   252
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
def run(request):
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   254
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   255
   user = request.user 
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   256
   print user
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   257
   problem_id = request.POST.get('problem_id')
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   258
  
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   259
   if problem_id:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   260
     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
   261
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   262
     if problem is None:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   263
       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
   264
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   265
   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
   266
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   267
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   268
   if  user_code == '':
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   269
     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
   270
  
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   271
    
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   272
   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
   273
   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
   274
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   275
   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
   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
  
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   278
   print "ksmdlnjdns"
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
   279
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   280
   solved,errors = execute_test_cases(user_code,problem.solution)
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   281
   
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   282
   
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   283
   if solved==True:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   284
    
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   285
     #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
   286
     try:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   287
       print user.id
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   288
       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
   289
       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
   290
       score_for_user.save()
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   291
    
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   292
    # user has answered questions previously
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   293
     except Score.DoesNotExist:
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   294
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   295
       score_new_user=user.id
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   296
       score_total_credits=problem.credit
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   297
       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
   298
       score.save()
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   299
  
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   300
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   301
3
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   302
   else:
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   303
     http.HttpResponse('Wrong Answer')
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   304
     
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   305
 
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   306
   return http.HttpResponse("Right Answer")
34d0c21e3352 Checking if exam has been previously done by the user or not
amit@thunder
parents: 2
diff changeset
   307
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
   308
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
@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
   311
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
   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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  # internal indicates that it is being called internally by uploader
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   316
  
0
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   317
  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
   318
  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
   319
    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
   320
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   322
    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
   323
  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
   324
    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
   325
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  if request.method == 'POST':
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   327
    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
   328
  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
   329
    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
   330
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   331
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   332
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   334
    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
   335
  
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   340
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    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
   342
    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
   343
    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
   344
    session=form.cleaned_data['Session']
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   345
    credit=form.cleaned_data['Credit']
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   346
   # solution_image=form.cleaned_data['Solution_Image']
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   347
    solution_image=request.FILES['Solution_Image']
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   348
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
   349
    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
   350
    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
   351
    modified=date.today()
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   352
    
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   353
    # print request.FILES 
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   354
    # print "this is solution"+solution
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   355
    # print "this is solution_image"+solution_image
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   356
  
2
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   357
654c583fd78e Made some changes and templates
amit@thunder
parents: 1
diff changeset
   358
    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
   359
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
    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
   361
    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
   362
  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
   363
    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
   364
    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
   365
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   366
#  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
   367
  #  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
   368
  #    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
   369
      
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   370
1
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   371
  if form.errors:
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   372
    print "new world"
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   373
    return respond(request, user, 'new_edit_problem', 
0eda880b3d25 started the basic framework evaluating results
amit@thunder
parents: 0
diff changeset
   374
                         {'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
   375
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  # 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
   377
  #   # 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
   378
  #   #   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
   379
  #   #     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
   380
  #   #     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
   381
  #   #   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
   382
  #   #     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
   383
  #   # 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
   384
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   385
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   386
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   387
    
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
   
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
#  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
   391
  # 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
   392
  #   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
   393
  # 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
   394
  # 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
   395
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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
  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
   397
    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
   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
  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
   401
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata framework on django with some specific changes to Problems model and some views to suit an exam like system
amit@thunder
parents:
diff changeset
   402
0b061d58aea3 First commit to Fossee of testapp has the basic Pykata 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