diff options
author | prathamesh | 2013-07-02 13:15:24 +0530 |
---|---|---|
committer | prathamesh | 2013-07-02 13:15:24 +0530 |
commit | 37625e5c91f2bf957c6739981f7698e0d880b6ed (patch) | |
tree | 387e52fa104f9f3562dad3f7690bec7493730310 /testapp/exam | |
parent | fe868c043487af8ea390165325309ad29daacc8e (diff) | |
parent | 610709c2ff35263741ca6e41c3648439806b564a (diff) | |
download | online_test-37625e5c91f2bf957c6739981f7698e0d880b6ed.tar.gz online_test-37625e5c91f2bf957c6739981f7698e0d880b6ed.tar.bz2 online_test-37625e5c91f2bf957c6739981f7698e0d880b6ed.zip |
Merge branch 'C-Cpp' of https://github.com/prathamesh920/online_test into fresh_C_Cpp
Diffstat (limited to 'testapp/exam')
-rw-r--r-- | testapp/exam/forms.py | 33 | ||||
-rw-r--r-- | testapp/exam/models.py | 5 | ||||
-rw-r--r-- | testapp/exam/xmlrpc_clients.py | 20 |
3 files changed, 33 insertions, 25 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index 7bbf601..1b60a71 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,17 @@ 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"), + ) 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 +31,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 +117,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 +139,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 +150,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 00d32e4..fac01ec 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -18,7 +18,9 @@ QUESTION_TYPE_CHOICES = ( ("python", "Python"), ("bash", "Bash"), ("mcq", "MultipleChoice"), - ) + ("C", "C Language"), + ("C++", "C++ Language"), + ) ################################################################################ class Question(models.Model): @@ -233,4 +235,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/xmlrpc_clients.py b/testapp/exam/xmlrpc_clients.py index 817e37d..b846212 100644 --- a/testapp/exam/xmlrpc_clients.py +++ b/testapp/exam/xmlrpc_clients.py @@ -9,19 +9,24 @@ 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", + } + 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 +73,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() - |