# HG changeset patch # User amit@thunder # Date 1275313737 -19800 # Node ID 654c583fd78eee647c7f546ed12187b36010dd60 # Parent 0eda880b3d25a8b353b0d0dc2630ce9a1ef4bd14 Made some changes and templates diff -r 0eda880b3d25 -r 654c583fd78e testappproj/.database.sqlite3 Binary file testappproj/.database.sqlite3 has changed diff -r 0eda880b3d25 -r 654c583fd78e testappproj/settings.py --- 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). diff -r 0eda880b3d25 -r 654c583fd78e testappproj/settings.pyc Binary file testappproj/settings.pyc has changed diff -r 0eda880b3d25 -r 654c583fd78e testappproj/templates/appjs.js --- 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/" ); + +} diff -r 0eda880b3d25 -r 654c583fd78e testappproj/templates/appjs.js~ --- 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 + "/"); + +} diff -r 0eda880b3d25 -r 654c583fd78e testappproj/templates/code.html~ --- 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%}

{{ problem.name }}

@@ -23,8 +23,8 @@ {% ifequal pu.classname "ProblemUser" %}{{ pu.solution }}{% else %}{{ problem.skeleton }}{% endifequal %}

- -

+ +

solve

diff -r 0eda880b3d25 -r 654c583fd78e testappproj/templates/index.html --- 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%} -

Welcome to testapp

+

Welcome

+
+

+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 . +

+ +
+ + +Sign up for the test + + +
+
+Take the Test + + {%endblock%} diff -r 0eda880b3d25 -r 654c583fd78e testappproj/templates/new_edit_problem.html --- 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 %} -

Upload Problems

-
- - {{ upload_form.as_table }} -
- -
-
-{% endif %}

{% if creating %}Add{% else %}Edit{% endif %} Problem

-
+ {{ form.as_table }}
- +
{%endblock%} diff -r 0eda880b3d25 -r 654c583fd78e testappproj/templates/registration/login.html --- 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.as_p }}
diff -r 0eda880b3d25 -r 654c583fd78e testappproj/testapp/forms.py --- 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) diff -r 0eda880b3d25 -r 654c583fd78e testappproj/testapp/forms.pyc Binary file testappproj/testapp/forms.pyc has changed diff -r 0eda880b3d25 -r 654c583fd78e testappproj/testapp/views.py --- 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" diff -r 0eda880b3d25 -r 654c583fd78e testappproj/testapp/views.pyc Binary file testappproj/testapp/views.pyc has changed