diff options
author | Hardik Ghaghada | 2013-04-26 14:02:28 +0530 |
---|---|---|
committer | Hardik Ghaghada | 2013-04-26 14:02:28 +0530 |
commit | 340e9b28961a4a927e9f039a5cef7111bbf69bf0 (patch) | |
tree | 056d7b16a104ce7afd375505feab7a879d3f7f99 /testapp | |
parent | ca63599e6fecbd513d47092f5aeb03726024bd98 (diff) | |
parent | 29beb24fe345e7e20919a6122ffb3e0f13371143 (diff) | |
download | online_test-340e9b28961a4a927e9f039a5cef7111bbf69bf0.tar.gz online_test-340e9b28961a4a927e9f039a5cef7111bbf69bf0.tar.bz2 online_test-340e9b28961a4a927e9f039a5cef7111bbf69bf0.zip |
Resolved Conflicts
Diffstat (limited to 'testapp')
-rw-r--r-- | testapp/exam/forms.py | 74 | ||||
-rw-r--r-- | testapp/exam/models.py | 3 | ||||
-rw-r--r-- | testapp/exam/urls.py | 16 | ||||
-rw-r--r-- | testapp/exam/views.py | 158 | ||||
-rw-r--r-- | testapp/settings.py | 4 | ||||
-rw-r--r-- | testapp/static/exam/js/add_question.js | 4 | ||||
-rw-r--r-- | testapp/templates/exam/editquestionpaper.html | 2 | ||||
-rw-r--r-- | testapp/test_server.py | 22 | ||||
-rw-r--r-- | testapp/urls.py | 3 |
9 files changed, 123 insertions, 163 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index 9bcd04f..7bbf601 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -22,18 +22,27 @@ 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 a new user to the system""" + """A Class to create new form for User's Registration. + It has the various fields and functions required to register + a new user to the system""" - username = forms.CharField(max_length=30, help_text='Letters, digits, period and underscores only.') + username = forms.CharField\ + (max_length=30, help_text='Letters, digits,\ + period and underscores only.') email = forms.EmailField() password = forms.CharField(max_length=30, widget=forms.PasswordInput()) - confirm_password = forms.CharField(max_length=30, widget=forms.PasswordInput()) + confirm_password = forms.CharField\ + (max_length=30, widget=forms.PasswordInput()) first_name = forms.CharField(max_length=30) last_name = forms.CharField(max_length=30) - roll_number = forms.CharField(max_length=30, help_text="Use a dummy if you don't have one.") - institute = forms.CharField(max_length=128, help_text='Institute/Organization') - department = forms.CharField(max_length=64, help_text='Department you work/study at') - position = forms.CharField(max_length=64, help_text='Student/Faculty/Researcher/Industry/etc.') + roll_number = forms.CharField\ + (max_length=30, help_text="Use a dummy if you don't have one.") + institute = forms.CharField\ + (max_length=128, help_text='Institute/Organization') + department = forms.CharField\ + (max_length=64, help_text='Department you work/study at') + position = forms.CharField\ + (max_length=64, help_text='Student/Faculty/Researcher/Industry/etc.') def clean_username(self): u_name = self.cleaned_data["username"] @@ -42,7 +51,7 @@ class UserRegisterForm(forms.Form): "allowed in username" raise forms.ValidationError(msg) try: - User.objects.get(username__exact = u_name) + User.objects.get(username__exact=u_name) raise forms.ValidationError("Username already exists.") except User.DoesNotExist: return u_name @@ -50,8 +59,8 @@ class UserRegisterForm(forms.Form): def clean_password(self): pwd = self.cleaned_data['password'] if pwd.strip(PWD_CHARS): - raise forms.ValidationError("Only letters, digits and punctuation are \ - allowed in password") + raise forms.ValidationError("Only letters, digits and punctuation\ + are allowed in password") return pwd def clean_confirm_password(self): @@ -86,28 +95,32 @@ class UserRegisterForm(forms.Form): class UserLoginForm(forms.Form): """Creates a form which will allow the user to log into the system.""" - username = forms.CharField(max_length = 30) + username = forms.CharField(max_length=30) password = forms.CharField(max_length=30, widget=forms.PasswordInput()) def clean(self): super(UserLoginForm, self).clean() try: - u_name, pwd = self.cleaned_data["username"], self.cleaned_data["password"] - user = authenticate(username = u_name, password = pwd) + u_name, pwd = self.cleaned_data["username"],\ + self.cleaned_data["password"] + user = authenticate(username=u_name, password=pwd) except Exception: - raise forms.ValidationError("Username and/or Password is not entered") + raise forms.ValidationError\ + ("Username and/or Password is not entered") if not user: raise forms.ValidationError("Invalid username/password") return user class QuizForm(forms.Form): - """Creates a form to add or edit a Quiz. It has the related fields and functions required.""" + """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) tags = TagField(widget=TagAutocomplete()) - description = forms.CharField(max_length=256, widget=forms.Textarea(attrs={'cols':20,'rows':1})) + description = forms.CharField(max_length=256, widget=forms.Textarea\ + (attrs={'cols':20,'rows':1})) def save(self): start_date = self.cleaned_data["start_date"] @@ -116,24 +129,31 @@ class QuizForm(forms.Form): description = self.cleaned_data["description"] new_quiz = Quiz() - new_quiz.start_date=start_date - new_quiz.duration=duration - new_quiz.active=active - new_quiz.description=description + new_quiz.start_date = start_date + new_quiz.duration = duration + new_quiz.active = active + new_quiz.description = description new_quiz.save() class QuestionForm(forms.Form): - """Creates a form to add or edit a Question. It has the related fields and functions required.""" + """Creates a form to add or edit a Question. + It has the related fields and functions required.""" - summary = forms.CharField(widget = forms.Textarea(attrs={'cols': 40, 'rows': 1})) - description = forms.CharField(widget = forms.Textarea(attrs={'cols': 40, 'rows': 1})) + summary = forms.CharField(widget=forms.Textarea\ + (attrs={'cols': 40, 'rows': 1})) + description = forms.CharField(widget=forms.Textarea\ + (attrs={'cols': 40, 'rows': 1})) points = forms.FloatField() - test = forms.CharField(widget = forms.Textarea(attrs={'cols': 40, 'rows': 1})) - options = forms.CharField(widget = forms.Textarea(attrs={'cols': 40, 'rows': 1}),required=False) - type = forms.CharField(max_length=8, widget=forms.Select(choices=QUESTION_TYPE_CHOICES)) + test = forms.CharField(widget=forms.Textarea\ + (attrs={'cols': 40, 'rows': 1})) + options = forms.CharField(widget=forms.Textarea\ + (attrs={'cols': 40, 'rows': 1}),required=False) + type = forms.CharField(max_length=8, widget=forms.Select\ + (choices=QUESTION_TYPE_CHOICES)) active = forms.BooleanField(required=False) tags = TagField(widget=TagAutocomplete(),required=False) - snippet = forms.CharField(widget = forms.Textarea(attrs={'cols': 40, 'rows': 1}),required=False) + snippet = forms.CharField(widget=forms.Textarea\ + (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 708c7af..00d32e4 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -1,7 +1,8 @@ import datetime from django.db import models from django.contrib.auth.models import User -from taggit_autocomplete_modified.managers import TaggableManagerAutocomplete as TaggableManager +from taggit_autocomplete_modified.managers import TaggableManagerAutocomplete\ +as TaggableManager from django.http import HttpResponse ################################################################################ class Profile(models.Model): diff --git a/testapp/exam/urls.py b/testapp/exam/urls.py index ff1545a..b3cfceb 100644 --- a/testapp/exam/urls.py +++ b/testapp/exam/urls.py @@ -30,15 +30,17 @@ urlpatterns = patterns('exam.views', url(r'^manage/showquiz/$','show_all_quiz'), url(r'^manage/monitor/$', 'monitor'), url(r'^manage/showquestionpapers/$','show_all_questionpapers'), - url(r'^manage/showquestionpapers/(?P<questionpaper_id>\d+)/$', 'show_all_questionpapers'), + url(r'^manage/showquestionpapers/(?P<questionpaper_id>\d+)/$',\ + 'show_all_questionpapers'), url(r'^manage/monitor/(?P<quiz_id>\d+)/$', 'monitor'), - url(r'^manage/user_data/(?P<username>[a-zA-Z0-9_.]+)/$', 'user_data'), + url(r'^manage/user_data/(?P<username>[a-zA-Z0-9_.]+)/$','user_data'), url(r'^manage/designquestionpaper/$','design_questionpaper'), - url(r'^manage/designquestionpaper/(?P<questionpaper_id>\d+)/$', 'design_questionpaper'), - url(r'^manage/designquestionpaper/automatic/(?P<questionpaper_id>\d+)/$','automatic_questionpaper'), + url(r'^manage/designquestionpaper/(?P<questionpaper_id>\d+)/$',\ + 'design_questionpaper'), + url(r'^manage/designquestionpaper/automatic/(?P<questionpaper_id>\d+)/$',\ + 'automatic_questionpaper'), url(r'^manage/designquestionpaper/automatic$','automatic_questionpaper'), url(r'^manage/designquestionpaper/manual$','manual_questionpaper'), - url(r'^manage/designquestionpaper/manual/(?P<questionpaper_id>\d+)/$','manual_questionpaper'), - + url(r'^manage/designquestionpaper/manual/(?P<questionpaper_id>\d+)/$',\ + 'manual_questionpaper'), ) - diff --git a/testapp/exam/views.py b/testapp/exam/views.py index 3e7f4a8..a1e8ece 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -14,8 +14,7 @@ from django.db.models import Sum from taggit.models import Tag from itertools import chain # Local imports. -from exam.models import Quiz, Question, QuestionPaper -from exam.models import Profile, Answer, AnswerPaper, User +from exam.models import Quiz, Question, QuestionPaper, Profile, Answer, AnswerPaper, User from exam.forms import UserRegisterForm, UserLoginForm, QuizForm , QuestionForm from exam.xmlrpc_clients import code_server from settings import URL_ROOT @@ -53,11 +52,6 @@ def get_user_dir(user): | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR \ | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) return user_dir - -def is_moderator(user): - """Check if the user is having moderator rights""" - if user.groups.filter(name='moderator').count() == 1: - return True def index(request): """The start page. @@ -111,8 +105,7 @@ def quizlist_user(request): for paper in user_answerpapers: for quiz in avail_quiz: - if paper.question_paper.id == quiz.id and \ - paper.end_time != paper.start_time: + if paper.question_paper.id == quiz.id and paper.end_time != paper.start_time: avail_quiz.remove(quiz) context = {'quizzes':avail_quiz,'user':user} @@ -135,14 +128,13 @@ def edit_quiz(request): """Edit the list of quizzes seleted by the user for editing.""" user = request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0: raise Http404('You are not allowed to view this page!') quizzes = request.POST.getlist('quizzes') start_date = request.POST.getlist('start_date') duration = request.POST.getlist('duration') active = request.POST.getlist('active') description = request.POST.getlist('description') - tags = request.POST.getlist('tags') j = 0 for i in quizzes: @@ -166,7 +158,7 @@ def edit_quiz(request): def edit_question(request): """Edit the list of questions seleted by the user for editing.""" user = request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0: raise Http404('You are not allowed to view this page!') questions = request.POST.getlist('questions') @@ -203,16 +195,15 @@ def edit_question(request): def add_question(request,question_id=None): - """To add a new question in the database. - Create a new question and store it.""" + """To add a new question in the database. Create a new question and store it.""" user = request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : raise Http404('You are not allowed to view this page!') if request.method == "POST": form = QuestionForm(request.POST) if form.is_valid(): data = form.cleaned_data - if question_id is None: + if question_id == None: form.save() question = Question.objects.order_by("-id")[0] tags = form['tags'].data.split(',') @@ -246,7 +237,7 @@ def add_question(request,question_id=None): {'form':form}, context_instance=RequestContext(request)) else: - if question_id is None: + if question_id == None: form = QuestionForm() return my_render_to_response('exam/add_question.html', {'form':form}, @@ -272,21 +263,20 @@ def add_question(request,question_id=None): if (initial_tags == ","): initial_tags = "" form.initial['tags']=initial_tags - return my_render_to_response('exam/add_question.html', - {'form':form},context_instance=RequestContext(request)) + return my_render_to_response('exam/add_question.html',{'form':form},context_instance=RequestContext(request)) def add_quiz(request,quiz_id=None): """To add a new quiz in the database. Create a new question and store it.""" user = request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : raise Http404('You are not allowed to view this page!') if request.method == "POST": form = QuizForm(request.POST) if form.is_valid(): data = form.cleaned_data - if quiz_id is None: + if quiz_id == None: form.save() quiz = Quiz.objects.order_by("-id")[0] tags = form['tags'].data.split(',') @@ -315,7 +305,7 @@ def add_quiz(request,quiz_id=None): {'form':form}, context_instance=RequestContext(request)) else: - if quiz_id is None: + if quiz_id == None: form = QuizForm() return my_render_to_response('exam/add_quiz.html', {'form':form}, @@ -336,26 +326,23 @@ def add_quiz(request,quiz_id=None): if (initial_tags == ","): initial_tags = "" form.initial['tags']=initial_tags - return my_render_to_response('exam/add_quiz.html', - {'form':form},context_instance=RequestContext(request)) + return my_render_to_response('exam/add_quiz.html',{'form':form},context_instance=RequestContext(request)) def design_questionpaper(request,questionpaper_id=None): user=request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : raise Http404('You are not allowed to view this page!') - return my_render_to_response('exam/add_questionpaper.html',{}, - context_instance=RequestContext(request)) + return my_render_to_response('exam/add_questionpaper.html',{},context_instance=RequestContext(request)) def show_all_questionpapers(request,questionpaper_id=None): user=request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : raise Http404('You are not allowed to view this page!') if request.method=="POST" and request.POST.get('add') == "add": - return my_redirect("/exam/manage/designquestionpaper/" + \ - questionpaper_id) + return my_redirect("/exam/manage/designquestionpaper/" + questionpaper_id) if request.method=="POST" and request.POST.get('delete') == "delete": data = request.POST.getlist('papers') @@ -365,12 +352,11 @@ def show_all_questionpapers(request,questionpaper_id=None): question_paper= QuestionPaper.objects.all() context = {'papers': question_paper } return my_render_to_response('exam/showquestionpapers.html', context, - context_instance=RequestContext(request)) - if questionpaper_id is None: + context_instance=RequestContext(request)) + if questionpaper_id == None: qu_papers = QuestionPaper.objects.all() context = {'papers':qu_papers} - return my_render_to_response('exam/showquestionpapers.html',context, - context_instance=RequestContext(request)) + return my_render_to_response('exam/showquestionpapers.html',context,context_instance=RequestContext(request)) else: qu_papers = QuestionPaper.objects.get(id=questionpaper_id) quiz = qu_papers.quiz @@ -379,8 +365,7 @@ def show_all_questionpapers(request,questionpaper_id=None): for i in questions: q.append(i) context = {'papers':{'quiz':quiz,'questions':q}} - return my_render_to_response('exam/editquestionpaper.html',context, - context_instance=RequestContext(request)) + return my_render_to_response('exam/editquestionpaper.html',context,context_instance=RequestContext(request)) def automatic_questionpaper(request,questionpaper_id=None): @@ -388,10 +373,10 @@ def automatic_questionpaper(request,questionpaper_id=None): user=request.user set1 = set() set2 = set() - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : raise Http404('You are not allowed to view this page!') - if questionpaper_id is None: + if questionpaper_id == None: if request.method=="POST": if request.POST.get('save') == 'save' : quiz = Quiz.objects.order_by("-id")[0] @@ -433,19 +418,14 @@ def automatic_questionpaper(request,questionpaper_id=None): for i in range(0,i): set2.pop() elif( no_questions > n): - msg = 'The given Criteria does not satisfy the \ - number of Questions...' + msg = 'The given Criteria does not satisfy the number of Questions...' tags = Tag.objects.all() context = {'data':{'questions':set2,'tags':tags,'msg':msg}} - return my_render_to_response\ - ('exam/automatic_questionpaper.html', - context, - context_instance=RequestContext(request)) + return my_render_to_response('exam/automatic_questionpaper.html',context,context_instance=RequestContext(request)) else: tags = Tag.objects.all() context = {'data':{'tags':tags}} - return my_render_to_response('exam/automatic_questionpaper.html', - context,context_instance=RequestContext(request)) + return my_render_to_response('exam/automatic_questionpaper.html',context,context_instance=RequestContext(request)) else: if request.method=="POST": @@ -486,27 +466,23 @@ def automatic_questionpaper(request,questionpaper_id=None): for i in range(0,i): set2.pop() elif( no_questions > n): - msg = 'The given Criteria does not satisfy \ - the number of Questions...' + msg = 'The given Criteria does not satisfy the number of Questions...' tags = Tag.objects.all() context = {'data':{'questions':set2,'tags':tags,'msg':msg}} - return my_render_to_response('exam/automatic_questionpaper.html', - context, - context_instance=RequestContext(request)) + return my_render_to_response('exam/automatic_questionpaper.html',context,context_instance=RequestContext(request)) else: tags = Tag.objects.all() context = {'data':{'tags':tags}} - return my_render_to_response('exam/automatic_questionpaper.html', - context,context_instance=RequestContext(request)) + return my_render_to_response('exam/automatic_questionpaper.html',context,context_instance=RequestContext(request)) def manual_questionpaper(request,questionpaper_id=None): user=request.user set1 = set() set2 = set() - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : raise Http404('You are not allowed to view this page!') - if questionpaper_id is None: + if questionpaper_id == None: if request.method=="POST": if request.POST.get('save') == 'save' : questions = request.POST.getlist('questions') @@ -545,13 +521,11 @@ def manual_questionpaper(request,questionpaper_id=None): msg = 'No matching Question found...' tags = Tag.objects.all() context = {'data':{'questions':set2,'tags':tags,'msg':msg}} - return my_render_to_response('exam/manual_questionpaper.html', - context,context_instance=RequestContext(request)) + return my_render_to_response('exam/manual_questionpaper.html',context,context_instance=RequestContext(request)) else: tags = Tag.objects.all() context = {'data':{'tags':tags}} - return my_render_to_response('exam/manual_questionpaper.html', - context,context_instance=RequestContext(request)) + return my_render_to_response('exam/manual_questionpaper.html',context,context_instance=RequestContext(request)) else: if request.method=="POST": @@ -589,24 +563,20 @@ def manual_questionpaper(request,questionpaper_id=None): msg = 'No matching Question found...' tags = Tag.objects.all() context = {'data':{'questions':set2,'tags':tags,'msg':msg}} - return my_render_to_response('exam/manual_questionpaper.html', - context,context_instance=RequestContext(request)) + return my_render_to_response('exam/manual_questionpaper.html',context,context_instance=RequestContext(request)) else: tags = Tag.objects.all() context = {'data':{'tags':tags}} - return my_render_to_response('exam/manual_questionpaper.html', - context,context_instance=RequestContext(request)) + return my_render_to_response('exam/manual_questionpaper.html',context,context_instance=RequestContext(request)) def prof_manage(request): - """Take credentials of the user with professor/moderator - rights/permissions and log in.""" + """Take credentials of the user with professor/moderator rights/permissions and log in.""" user = request.user - if user.is_authenticated() and\ - user.groups.filter(name='moderator').count() > 0: + if user.is_authenticated() and user.groups.filter(name='moderator').count() > 0: context = {'user':user} return my_render_to_response('manage.html',context) return my_redirect('/exam/login/') @@ -639,10 +609,9 @@ def user_login(request): context_instance=RequestContext(request)) def start(request,questionpaper_id=None): - """Check the user cedentials and if any quiz is available, - start the exam.""" + """Check the user cedentials and if any quiz is available, start the exam.""" user = request.user - if questionpaper_id is None: + if questionpaper_id == None: return my_redirect('/exam/quizzes/') try: # Right now the app is designed so there is only one active quiz @@ -654,8 +623,7 @@ def start(request,questionpaper_id=None): return complete(request, reason=msg) try: - old_paper = AnswerPaper.objects.get\ - (question_paper=questionpaper, user=user) + old_paper = AnswerPaper.objects.get(question_paper=questionpaper, user=user) q = old_paper.current_question() return show_question(request, q,questionpaper_id) except AnswerPaper.DoesNotExist: @@ -697,8 +665,7 @@ def question(request, q_id, questionpaper_id): q = get_object_or_404(Question, pk=q_id) try: q_paper = QuestionPaper.objects.get(id=questionpaper_id) - paper = AnswerPaper.objects.get\ - (user=request.user, question_paper=q_paper) + paper = AnswerPaper.objects.get(user=request.user, question_paper=q_paper) except AnswerPaper.DoesNotExist: return my_redirect('/exam/start/') if not paper.question_paper.quiz.active: @@ -789,22 +756,21 @@ def check(request, q_id, questionpaper_id=None): def quit(request, answerpaper_id=None): """Show the quit page when the user logs out.""" context = { 'id':answerpaper_id} - return my_render_to_response('exam/quit.html',context, - context_instance=RequestContext(request)) + return my_render_to_response('exam/quit.html',context,context_instance=RequestContext(request)) def complete(request,reason = None,answerpaper_id=None): """Show a page to inform user that the quiz has been compeleted.""" user = request.user - if answerpaper_id is None: + if answerpaper_id == None: logout(request) context = {'message': "You are successfully Logged out."} return my_render_to_response('exam/complete.html', context) no = False message = reason or 'The quiz has been completed. Thank you.' if user.groups.filter(name='moderator').count() > 0: - message = 'You are successfully Logged out.' + message = 'You are successfully Logged out. Thanks for spending some time with the application' if request.method == 'POST' and 'no' in request.POST: no = True if not no: @@ -820,7 +786,7 @@ def monitor(request, quiz_id=None): """Monitor the progress of the papers taken so far.""" user = request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0: raise Http404('You are not allowed to view this page!') if quiz_id is None: @@ -866,26 +832,24 @@ def show_all_users(request): """Shows all the users who have taken various exams/quiz.""" user = request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0: raise Http404('You are not allowed to view this page !') user = User.objects.filter(username__contains="") questionpaper = AnswerPaper.objects.all() context = { 'question': questionpaper } - return my_render_to_response('exam/showusers.html',context, - context_instance=RequestContext(request)) + return my_render_to_response('exam/showusers.html',context,context_instance=RequestContext(request)) def show_all_quiz(request): - """Generates a list of all the quizzes - that are currently in the database.""" + """Generates a list of all the quizzes that are currently in the database.""" user = request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0: raise Http404('You are not allowed to view this page !') if request.method == 'POST' and request.POST.get('delete')=='delete': data = request.POST.getlist('quiz') - if data is None: + if data == None: quizzes = Quiz.objects.all() context = {'papers': [], 'quiz': None, @@ -900,7 +864,7 @@ def show_all_quiz(request): 'quiz': None, 'quizzes':quizzes} return my_render_to_response('exam/show_quiz.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) elif request.method == 'POST' and request.POST.get('edit')=='edit': data = request.POST.getlist('quiz') @@ -921,9 +885,8 @@ def show_all_quiz(request): initial_tags = "" form.initial['tags']=initial_tags forms.append(form) - return my_render_to_response('exam/edit_quiz.html', - {'forms':forms,'data':data}, - context_instance=RequestContext(request)) + return my_render_to_response('exam/edit_quiz.html',{'forms':forms,'data':data}, + context_instance=RequestContext(request)) else: quizzes = Quiz.objects.all() @@ -938,12 +901,12 @@ def show_all_questions(request): """Show a list of all the questions currently in the databse.""" user = request.user - if not user.is_authenticated() or not is_moderator(user): + if not user.is_authenticated() or user.groups.filter(name='moderator').count() == 0 : raise Http404("You are not allowed to view this page !") if request.method == 'POST' and request.POST.get('delete')=='delete': data = request.POST.getlist('question') - if data is None: + if data == None: questions = Question.objects.all() context = {'papers': [], 'question': None, @@ -983,9 +946,7 @@ def show_all_questions(request): initial_tags = "" form.initial['tags']=initial_tags forms.append(form) - return my_render_to_response('exam/edit_question.html', - {'forms':forms,'data':data}, - context_instance=RequestContext(request)) + return my_render_to_response('exam/edit_question.html',{'forms':forms,'data':data},context_instance=RequestContext(request)) else: questions = Question.objects.all() @@ -999,7 +960,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 current_user.groups.filter(name='moderator').count() == 0: raise Http404('You are not allowed to view this page!') data = get_user_data(username) @@ -1013,7 +974,7 @@ def grade_user(request, username): and update all their marks and also give comments for each paper. """ current_user = request.user - if not current_user.is_authenticated() or not is_moderator(user): + if not current_user.is_authenticated() or current_user.groups.filter(name='moderator').count() == 0: raise Http404('You are not allowed to view this page!') data = get_user_data(username) @@ -1025,8 +986,7 @@ def grade_user(request, username): last_ans = answers[-1] last_ans.marks = marks last_ans.save() - paper.comments = request.POST.get\ - ('comments_%d'%paper.question_paper.id) + paper.comments = request.POST.get('comments_%d'%paper.question_paper.id) paper.save() context = {'data': data} diff --git a/testapp/settings.py b/testapp/settings.py index 10d0919..0002476 100644 --- a/testapp/settings.py +++ b/testapp/settings.py @@ -148,11 +148,9 @@ INSTALLED_APPS = ( 'taggit', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', -# 'south', 'exam', 'taggit_autocomplete_modified', - 'debug_toolbar', - #'django_extensions', + 'debug_toolbar', ) # A sample logging configuration. The only tangible logging diff --git a/testapp/static/exam/js/add_question.js b/testapp/static/exam/js/add_question.js index 1f08c79..24af127 100644 --- a/testapp/static/exam/js/add_question.js +++ b/testapp/static/exam/js/add_question.js @@ -98,9 +98,9 @@ function autosubmit() if (document.getElementById('id_type').value == 'mcq') { var value = document.getElementById('id_options').value; - if(value.split('\n').length != 4) + if(value.split('\n').length < 4) { - alert("Enter 4 options. One option per line."); + alert("Please Enter 4 options. One option per line."); return false; } return true; diff --git a/testapp/templates/exam/editquestionpaper.html b/testapp/templates/exam/editquestionpaper.html index ee36cc8..819ff06 100644 --- a/testapp/templates/exam/editquestionpaper.html +++ b/testapp/templates/exam/editquestionpaper.html @@ -15,7 +15,7 @@ <input type="checkbox" name="papers" value="{{ i.id }}"> <a href="{{URL_ROOT}}/exam/manage/addquestion/{{ i.id }}">{{ i.summary}}</a><br> {% endfor %} <br> -<button class="btn" type="submit" name=add value=add>Add Question</button> +<button class="btn" type="submit" name='add' value=add>Add Question</button> <button class="btn" type="submit" onClick="return confirm_delete(frm);" name='delete' value='delete'>Delete Selected</button> </form> {% endblock %} diff --git a/testapp/test_server.py b/testapp/test_server.py index e81daf2..0790816 100644 --- a/testapp/test_server.py +++ b/testapp/test_server.py @@ -35,28 +35,6 @@ def test_python(): language="python") check_result(result, 'nameerror') -def test_c(): - """Test if server runs Python code as expected.""" - src = 'while True: pass' - result = code_server.run_code(src, '', '/tmp', language="c") - check_result(result, 'more than ') - - src = 'x = 1' - result = code_server.run_code(src, 'assert x == 1', '/tmp', - language="c") - check_result(result, 'correct answer') - - result = code_server.run_code(src, 'assert x == 0', '/tmp', - language="c") - check_result(result, 'assertionerror') - - src = 'C lang. Code' - result = code_server.run_code(src, 'assert x == 0', '/tmp', - language="c") - check_result(result, 'nameerror') - - - def test_bash(): """Test if server runs Bash code as expected.""" src = """ diff --git a/testapp/urls.py b/testapp/urls.py index 55bb877..c82ecb6 100644 --- a/testapp/urls.py +++ b/testapp/urls.py @@ -24,5 +24,6 @@ urlpatterns = patterns('', ) urlpatterns += patterns('', - url(r'^taggit_autocomplete_modified/', include('taggit_autocomplete_modified.urls')), + url(r'^taggit_autocomplete_modified/', include\ + ('taggit_autocomplete_modified.urls')), ) |