Made some changes and templates
authoramit@thunder
Mon, 31 May 2010 19:18:57 +0530
changeset 2 654c583fd78e
parent 1 0eda880b3d25
child 3 34d0c21e3352
Made some changes and templates
testappproj/.database.sqlite3
testappproj/settings.py
testappproj/settings.pyc
testappproj/templates/appjs.js
testappproj/templates/appjs.js~
testappproj/templates/code.html~
testappproj/templates/index.html
testappproj/templates/new_edit_problem.html
testappproj/templates/registration/login.html
testappproj/testapp/forms.py
testappproj/testapp/forms.pyc
testappproj/testapp/views.py
testappproj/testapp/views.pyc
Binary file testappproj/.database.sqlite3 has changed
--- a/testappproj/settings.py	Fri May 21 02:40:17 2010 +0530
+++ b/testappproj/settings.py	Mon May 31 19:18:57 2010 +0530
@@ -39,7 +39,7 @@
 
 # Absolute path to the directory that holds media.
 # Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = ''
+MEDIA_ROOT = '/home/amit/spkt-testapp/testappproj/media-root/'
 
 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
 # trailing slash if there is a path component (optional in other cases).
Binary file testappproj/settings.pyc has changed
--- a/testappproj/templates/appjs.js	Fri May 21 02:40:17 2010 +0530
+++ b/testappproj/templates/appjs.js	Mon May 31 19:18:57 2010 +0530
@@ -2,4 +2,9 @@
   $("#solve_" + id).load(location.protocol + "//" + location.host +
 				 "/code/" + id + "/");
 
-}
\ No newline at end of file
+}
+function loadcode(id) {
+  $("#solve_" + id).load(location.protocol + "//" + location.host +
+				 "/run/" );
+
+}
--- a/testappproj/templates/appjs.js~	Fri May 21 02:40:17 2010 +0530
+++ b/testappproj/templates/appjs.js~	Mon May 31 19:18:57 2010 +0530
@@ -1,5 +1,10 @@
 function loadcode(id) {
-$("#solve_" + id).load(location.protocol + "//" + location.host +
+  $("#solve_" + id).load(location.protocol + "//" + location.host +
 				 "/code/" + id + "/");
 
 }
+function loadcode(id) {
+  $("#solve_" + id).load(location.protocol + "//" + location.host +
+				 "/run/" + id + "/");
+
+}
--- a/testappproj/templates/code.html~	Fri May 21 02:40:17 2010 +0530
+++ b/testappproj/templates/code.html~	Mon May 31 19:18:57 2010 +0530
@@ -1,4 +1,4 @@
-{%extends "base.html"%}
+{# {%extends "base.html"%} #}
 {%block body%}
 <h2>{{ problem.name }}</h2>
 
@@ -23,8 +23,8 @@
 {% ifequal pu.classname "ProblemUser" %}{{ pu.solution }}{% else %}{{ problem.skeleton }}{% endifequal %}
 
     </textarea></p>
-    <input type="hidden" name="problem_id" value="{{ problem.key.id }}" />
-    <p><input type="submit" name="submit" value="Run" /></p>
+    <input type="hidden" name="problem_id" value="{{ problem.id }}" />
+    <p><a  class="comment"  href="#solve"  onclick="return loadrun({{ entry.problem_id }})">solve</a></p>
   </form>
 
   <script language="javascript" type="text/javascript" src="/static/edit_area_full.js"></script>
--- a/testappproj/templates/index.html	Fri May 21 02:40:17 2010 +0530
+++ b/testappproj/templates/index.html	Mon May 31 19:18:57 2010 +0530
@@ -1,7 +1,23 @@
 {%extends "base.html"%} 
 {%block body%}
 
-<p> Welcome to testapp</p>
+<p> Welcome</p>
+<br/>
+<p>
+This is an Application where You can test your Python skills. This is an automated Test and in case you pass you will be given a certificate from the Fossee Team .
+</p>
+
+<br/>
+
+
+<a href="/accounts/register">Sign up for the test</a>
+
+
+<br/>
+<br/>
+<big><a href="/problems/">Take the Test</a></big>
+
+
 
 {%endblock%}
 
--- a/testappproj/templates/new_edit_problem.html	Fri May 21 02:40:17 2010 +0530
+++ b/testappproj/templates/new_edit_problem.html	Mon May 31 19:18:57 2010 +0530
@@ -1,22 +1,12 @@
 {%block body%}
 
-{% if creating %}
-<h2>Upload Problems</h2>
-  <form action="/upload/" method="post" enctype="multipart/form-data">
-    <table>
-      {{ upload_form.as_table }}
-    </table>
-    <input type="submit" value="upload" />
-  </form>
-<hr />
-{% endif %}
 
 <h2>{% if creating %}Add{% else %}Edit{% endif %} Problem</h2>
-  <form action="" method="post">
+  <form action="" method="post" enctype="multipart/form-data">
   <table>
     {{ form.as_table  }}
   </table>
   <input type="submit" value="Save" />
 </form>
-
+<hr />
 {%endblock%}
--- a/testappproj/templates/registration/login.html	Fri May 21 02:40:17 2010 +0530
+++ b/testappproj/templates/registration/login.html	Mon May 31 19:18:57 2010 +0530
@@ -1,5 +1,5 @@
 {% block content %}
-<form action="/accounts/login/?next=/" method="post">
+<form action="/accounts/login/?next=/problems" method="post">
 {{ form.as_p }}
 <input type="submit" value="Login" />
 </form>
--- a/testappproj/testapp/forms.py	Fri May 21 02:40:17 2010 +0530
+++ b/testappproj/testapp/forms.py	Mon May 31 19:18:57 2010 +0530
@@ -29,7 +29,7 @@
 class ProblemForm(forms.Form):
   Description = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),required=True,help_text="To be used as the question")
   Problem_type = forms.ChoiceField(choices=PROBLEM_CHOICES,required=True)
-  Solution = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),help_text="comma seperated in case of multiple solutions")
+  Solution = forms.CharField(widget=forms.Textarea(attrs={'rows': '10', 'cols': '80'}),help_text="comma seperated in case of multiple solutions",required=False)
   Solution_Image = forms.ImageField(required=False)
   Session = forms.ChoiceField(choices=SESSION_CHOICES, required=True)
   Credit=forms.IntegerField(required=True)
Binary file testappproj/testapp/forms.pyc has changed
--- a/testappproj/testapp/views.py	Fri May 21 02:40:17 2010 +0530
+++ b/testappproj/testapp/views.py	Mon May 31 19:18:57 2010 +0530
@@ -1,4 +1,3 @@
-
 # Python imports
 import doctest
 import logging
@@ -15,11 +14,6 @@
 from testappproj.testapp.models import *
 from django.http import HttpResponse
 
-# from google.appengine.api import users
-# from google.appengine.ext.webapp import template 
-
-# from google.appengine.ext import db
-# from google.appengine.ext.db import djangoforms
 
 
 # Django imports 
@@ -41,6 +35,17 @@
 from models import Problem
 from django.contrib.auth.decorators import login_required 
 from models import Score 
+import time
+
+
+# def handle_uploaded_file(f):
+#   print f  
+#   destination = open('some/file/name.txt', 'wb+')
+#   for chunk in f.chunks():
+#     destination.write(chunk)
+#   destination.close()
+
+
 
 def respond(request, user,template, params=None):
   """Helper to render a response, passing standard stuff to the response.
@@ -70,6 +75,60 @@
   template += '.html'
   return shortcuts.render_to_response(template, params)
 
+def execute_plotting_test_cases(user_code , solution_image,problem_id , username):
+  
+  print  user_code 
+  print "solution"+solution_image
+
+  image_name = username+'_'+str(problem_id)+'_'+time.time()
+  
+  code="""from pylab import *
+  %s
+  show()"""%user_code
+
+  solved=False
+  # create file-like string to capture output
+  codeOut = StringIO.StringIO()
+  codeErr = StringIO.StringIO()
+
+
+
+  # capture output and errors
+  sys.stdout = codeOut
+  sys.stderr = codeErr
+
+  exec code
+
+# restore stdout and stderr
+  sys.stdout = sys.__stdout__
+  sys.stderr = sys.__stderr__
+
+
+
+  
+  
+  s = codeOut.getvalue()
+  
+  s=unicode(s)
+  
+
+  print s.strip()
+  print solution.strip()
+  
+ 
+     
+  if solution.strip() == s.strip():
+    solved =True
+
+  errors=codeErr.getvalue()
+  
+  
+
+  codeOut.close()
+  codeErr.close()
+
+  return solved,errors
+
 def execute_test_cases(code , solution):
   
   print code 
@@ -111,7 +170,7 @@
     solved =True
 
   errors=codeErr.getvalue()
-  print "errors"+errors
+  
   
 
   codeOut.close()
@@ -121,7 +180,6 @@
 
 
 
-
 def index(request):
   """ need to change user in the django.contrib way"""
 
@@ -217,6 +275,9 @@
     
 
   return respond(request, user, 'problems',{'entries' : entries }  )
+
+
+
 @login_required(function=None, redirect_field_name='next')
 def code(request, problem_id):
   
@@ -320,10 +381,8 @@
 
 
   # internal indicates that it is being called internally by uploader
-  #
+  
   user = request.user
-#  print user.get_all_permissions()
-  print user.username
   if user.is_anonymous() :
     return http.HttpResponseForbidden('You must be an signed in to create edit a problem.')
 
@@ -332,20 +391,8 @@
   else:
     creating_new = False
     
-#  problem = None
-  # if problem_id:
-  #   problem = models.Problem.get(db.Key.from_path(models.Problem.kind(), int(problem_id)))
-  #   if problem.author != user and not users.is_current_user_admin():
-  #     return http.HttpResponseForbidden('You can only edit your own problems.')
-  #   if problem is None:
-  #     return http.HttpResponseNotFound('No such problem.')  
- 
-#   formset = ProblemForm(data=request.POST)  
-#   instance=formset.save()
-# #  upload_form = UploadForm(data=request.POST)
-
   if request.method == 'POST':
-    form = ProblemForm(request.POST)
+    form = ProblemForm(request.POST, request.FILES)
   else:
     form = ProblemForm()
 
@@ -354,13 +401,8 @@
   if not request.POST:
     return respond(request, user, 'new_edit_problem', {'form':form, 'problem':None, 'creating':creating_new })
   
-#  print form
-  #errors = form.errors
-  #print str(errors)+"errors"
 
   
-  #if not errors:
-  #  try:
   
   if form.is_valid():
     
@@ -369,13 +411,19 @@
     solution=form.cleaned_data['Solution']
     session=form.cleaned_data['Session']
     credit=form.cleaned_data['Credit']
+   # solution_image=form.cleaned_data['Solution_Image']
+    solution_image=request.FILES['Solution_Image']
 
-    
     author = user.username
     created = date.today()
     modified=date.today()
+    
+    # print request.FILES 
+    # print "this is solution"+solution
+    # print "this is solution_image"+solution_image
   
-    problem=Problem(description=description,problem_type=problem_type,solution=solution,session=session,author=author,created=created,modified=modified,credit=credit)
+
+    problem=Problem(description=description,problem_type=problem_type,solution_image=solution_image,session=session,author=author,created=created,modified=modified,credit=credit)
     
     problem.save() 
     print "saved"
Binary file testappproj/testapp/views.pyc has changed