summaryrefslogtreecommitdiff
path: root/testapp/exam
diff options
context:
space:
mode:
authorprathamesh2013-07-03 16:58:34 +0530
committerprathamesh2013-07-03 16:58:34 +0530
commit8de499263ec00be5e500693b8db7f4b5ee0d15bd (patch)
treea508cfbcd65d16ffb3801a218b6037a8b3bd555f /testapp/exam
parent156bb47ecebcca190683b8e59f917a5b742d11fd (diff)
parentb522a1ba1c1edff7648c6c7d69fa2867a08b4100 (diff)
downloadonline_test-8de499263ec00be5e500693b8db7f4b5ee0d15bd.tar.gz
online_test-8de499263ec00be5e500693b8db7f4b5ee0d15bd.tar.bz2
online_test-8de499263ec00be5e500693b8db7f4b5ee0d15bd.zip
Merge branch 'fresh_java' of https://github.com/prathamesh920/online_test into deploy_server
Conflicts: testapp/templates/exam/question.html
Diffstat (limited to 'testapp/exam')
-rw-r--r--testapp/exam/forms.py34
-rw-r--r--testapp/exam/models.py6
-rw-r--r--testapp/exam/views.py2
-rw-r--r--testapp/exam/xmlrpc_clients.py21
4 files changed, 37 insertions, 26 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py
index 7bbf601..8506de2 100644
--- a/testapp/exam/forms.py
+++ b/testapp/exam/forms.py
@@ -1,5 +1,5 @@
from django import forms
-from exam.models import Profile,Quiz,Question
+from exam.models import Profile, Quiz, Question
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
@@ -13,14 +13,18 @@ from string import letters, punctuation, digits
import datetime
QUESTION_TYPE_CHOICES = (
- ("python", "Python"),
- ("bash", "Bash"),
- ("mcq", "MCQ"),
- )
+ ("python", "Python"),
+ ("bash", "Bash"),
+ ("mcq", "MCQ"),
+ ("C", "C Language"),
+ ("C++", "C++ Language"),
+ ("java", "Java Language"),
+ )
UNAME_CHARS = letters + "._" + digits
PWD_CHARS = letters + punctuation + digits
+
class UserRegisterForm(forms.Form):
"""A Class to create new form for User's Registration.
It has the various fields and functions required to register
@@ -28,7 +32,7 @@ class UserRegisterForm(forms.Form):
username = forms.CharField\
(max_length=30, help_text='Letters, digits,\
- period and underscores only.')
+ period and underscores only.')
email = forms.EmailField()
password = forms.CharField(max_length=30, widget=forms.PasswordInput())
confirm_password = forms.CharField\
@@ -114,20 +118,20 @@ class UserLoginForm(forms.Form):
class QuizForm(forms.Form):
"""Creates a form to add or edit a Quiz.
It has the related fields and functions required."""
-
+
start_date = forms.DateField(initial=datetime.date.today)
duration = forms.IntegerField()
- active = forms.BooleanField(required = False)
+ active = forms.BooleanField(required=False)
tags = TagField(widget=TagAutocomplete())
description = forms.CharField(max_length=256, widget=forms.Textarea\
- (attrs={'cols':20,'rows':1}))
+ (attrs={'cols': 20, 'rows': 1}))
def save(self):
start_date = self.cleaned_data["start_date"]
duration = self.cleaned_data["duration"]
active = self.cleaned_data['active']
description = self.cleaned_data["description"]
-
+
new_quiz = Quiz()
new_quiz.start_date = start_date
new_quiz.duration = duration
@@ -136,7 +140,7 @@ class QuizForm(forms.Form):
new_quiz.save()
class QuestionForm(forms.Form):
- """Creates a form to add or edit a Question.
+ """Creates a form to add or edit a Question.
It has the related fields and functions required."""
summary = forms.CharField(widget=forms.Textarea\
@@ -147,13 +151,13 @@ class QuestionForm(forms.Form):
test = forms.CharField(widget=forms.Textarea\
(attrs={'cols': 40, 'rows': 1}))
options = forms.CharField(widget=forms.Textarea\
- (attrs={'cols': 40, 'rows': 1}),required=False)
+ (attrs={'cols': 40, 'rows': 1}), required=False)
type = forms.CharField(max_length=8, widget=forms.Select\
- (choices=QUESTION_TYPE_CHOICES))
+ (choices=QUESTION_TYPE_CHOICES))
active = forms.BooleanField(required=False)
- tags = TagField(widget=TagAutocomplete(),required=False)
+ tags = TagField(widget=TagAutocomplete(), required=False)
snippet = forms.CharField(widget=forms.Textarea\
- (attrs={'cols': 40, 'rows': 1}),required=False)
+ (attrs={'cols': 40, 'rows': 1}), required=False)
def save(self):
summary = self.cleaned_data["summary"]
diff --git a/testapp/exam/models.py b/testapp/exam/models.py
index da9bc0a..2aa02c9 100644
--- a/testapp/exam/models.py
+++ b/testapp/exam/models.py
@@ -18,7 +18,10 @@ QUESTION_TYPE_CHOICES = (
("python", "Python"),
("bash", "Bash"),
("mcq", "MultipleChoice"),
- )
+ ("C", "C Language"),
+ ("C++", "C++ Language"),
+ ("java", "Java Language"),
+ )
################################################################################
class Question(models.Model):
@@ -234,4 +237,3 @@ the next."""
def __unicode__(self):
u = self.user
return u'Question paper for {0} {1}'.format(u.first_name, u.last_name)
-
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index e2ff763..55ccd38 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -1016,7 +1016,7 @@ def user_data(request, username):
"""Render user data."""
current_user = request.user
- if not current_user.is_authenticated() or not is_moderator(user):
+ if not current_user.is_authenticated() or not is_moderator(current_user):
raise Http404('You are not allowed to view this page!')
data = get_user_data(username)
diff --git a/testapp/exam/xmlrpc_clients.py b/testapp/exam/xmlrpc_clients.py
index 817e37d..cc21e62 100644
--- a/testapp/exam/xmlrpc_clients.py
+++ b/testapp/exam/xmlrpc_clients.py
@@ -9,19 +9,25 @@ from settings import SERVER_PORTS, SERVER_POOL_PORT
class ConnectionError(Exception):
pass
-################################################################################
+###############################################################################
# `CodeServerProxy` class.
-################################################################################
+###############################################################################
+
+
class CodeServerProxy(object):
"""A class that manages accesing the farm of Python servers and making
calls to them such that no one XMLRPC server is overloaded.
"""
def __init__(self):
- pool_url = 'http://localhost:%d'%(SERVER_POOL_PORT)
+ pool_url = 'http://localhost:%d' % (SERVER_POOL_PORT)
self.pool_server = ServerProxy(pool_url)
self.methods = {"python": 'run_python_code',
- "bash": 'run_bash_code'}
-
+ "bash": 'run_bash_code',
+ "C": "run_c_code",
+ "C++": "run_cplus_code",
+ "java": "run_java_code",
+ }
+
def run_code(self, answer, test_code, user_dir, language):
"""Tests given code (`answer`) with the `test_code` supplied. If the
optional `in_dir` keyword argument is supplied it changes the directory
@@ -68,11 +74,10 @@ class CodeServerProxy(object):
else:
done = True
if not done:
- raise ConnectionError("Couldn't connect to a server!")
- proxy = ServerProxy('http://localhost:%d'%port)
+ raise ConnectionError("Couldn't connect to a server!")
+ proxy = ServerProxy('http://localhost:%d' % port)
return proxy
# views.py calls this Python server which forwards the request to one
# of the running servers.
code_server = CodeServerProxy()
-