diff options
author | prathamesh | 2014-05-12 15:13:33 +0530 |
---|---|---|
committer | prathamesh | 2014-05-12 15:13:33 +0530 |
commit | fa1cdf5c8f92715f2b3866f0a17e2439d27557c5 (patch) | |
tree | c0020a1bbcc24d7ef7372e4ae53133dfc4b28523 /testapp/exam | |
parent | 3244b69143adb3f86ca2bbdfbbc1b8a93489de29 (diff) | |
download | online_test-fa1cdf5c8f92715f2b3866f0a17e2439d27557c5.tar.gz online_test-fa1cdf5c8f92715f2b3866f0a17e2439d27557c5.tar.bz2 online_test-fa1cdf5c8f92715f2b3866f0a17e2439d27557c5.zip |
Files modified according to the pep8 coding standard.
Diffstat (limited to 'testapp/exam')
-rw-r--r-- | testapp/exam/forms.py | 15 | ||||
-rw-r--r-- | testapp/exam/models.py | 55 | ||||
-rw-r--r-- | testapp/exam/views.py | 198 |
3 files changed, 142 insertions, 126 deletions
diff --git a/testapp/exam/forms.py b/testapp/exam/forms.py index 917bea7..d711f6a 100644 --- a/testapp/exam/forms.py +++ b/testapp/exam/forms.py @@ -13,12 +13,12 @@ from string import letters, punctuation, digits import datetime QUESTION_TYPE_CHOICES = ( - ("python", "Python"), - ("bash", "Bash"), - ("mcq", "MCQ"), - ("C", "C Language"), - ("C++", "C++ Language"), - ("java", "Java Language"), + ("python", "Python"), + ("bash", "Bash"), + ("mcq", "MCQ"), + ("C", "C Language"), + ("C++", "C++ Language"), + ("java", "Java Language"), ) UNAME_CHARS = letters + "._" + digits @@ -30,8 +30,7 @@ class UserRegisterForm(forms.Form): 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,\ + 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()) diff --git a/testapp/exam/models.py b/testapp/exam/models.py index babde0f..713260b 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -5,6 +5,8 @@ from taggit_autocomplete_modified.managers import TaggableManagerAutocomplete\ as TaggableManager from django.http import HttpResponse ################################################################################ + + class Profile(models.Model): """Profile for a user to store roll number and other details.""" user = models.OneToOneField(User) @@ -22,8 +24,9 @@ QUESTION_TYPE_CHOICES = ( ("C++", "C++ Language"), ("java", "Java Language"), ) - ################################################################################ + + class Question(models.Model): """A question in the database.""" @@ -32,10 +35,10 @@ class Question(models.Model): # The question text, should be valid HTML. description = models.TextField() - + # Number of points for the question. points = models.FloatField(default=1.0) - + # Test cases for the question in the form of code that is run. test = models.TextField(blank=True) @@ -48,7 +51,7 @@ class Question(models.Model): # Is this question active or not. If it is inactive it will not be used # when creating a QuestionPaper. active = models.BooleanField(default=True) - + #Code Snippet snippet = models.CharField(max_length=256) @@ -65,7 +68,7 @@ class Answer(models.Model): """ # The question for which we are an answer. question = models.ForeignKey(Question) - + # The answer submitted by the user. answer = models.TextField(null=True, blank=True) @@ -75,49 +78,51 @@ class Answer(models.Model): # Marks obtained for the answer. This can be changed by the teacher if the # grading is manual. marks = models.FloatField(default=0.0) - + # Is the answer correct. correct = models.BooleanField(default=False) - + def __unicode__(self): return self.answer + ################################################################################ class Quiz(models.Model): - """A quiz that students will participate in. One can think of this + """A quiz that students will participate in. One can think of this as the "examination" event. """ - + # The starting/ending date of the quiz. start_date = models.DateField("Date of the quiz") - + # This is always in minutes. duration = models.IntegerField("Duration of quiz in minutes", default=20) - - # Is the quiz active. The admin should deactivate the quiz once it is + + # Is the quiz active. The admin should deactivate the quiz once it is # complete. active = models.BooleanField(default=True) - + # Description of quiz. description = models.CharField(max_length=256) #Tags for the Quiz. tags = TaggableManager() - class Meta: verbose_name_plural = "Quizzes" - + def __unicode__(self): desc = self.description or 'Quiz' - return '%s: on %s for %d minutes'%(desc, self.start_date, self.duration) + return '%s: on %s for %d minutes' % (desc, self.start_date, self.duration) + ################################################################################ class QuestionPaper(models.Model): quiz = models.ForeignKey(Quiz) questions = models.ManyToManyField(Question) total_marks = models.FloatField() - + + ################################################################################ class AnswerPaper(models.Model): """A answer paper for a student -- one per student typically. @@ -134,25 +139,25 @@ class AnswerPaper(models.Model): # The Quiz to which this question paper is attached to. question_paper = models.ForeignKey(QuestionPaper) - + # The time when this paper was started by the user. start_time = models.DateTimeField() # The time when this paper was ended by the user. end_time = models.DateTimeField() - + # User's IP which is logged. user_ip = models.CharField(max_length=15) # The questions successfully answered (a list of ids separated by '|') questions_answered = models.CharField(max_length=128) - + # All the submitted answers. answers = models.ManyToManyField(Answer) # Teacher comments on the question paper. comments = models.TextField() - + def current_question(self): """Returns the current active question to display.""" qs = self.questions.split('|') @@ -160,7 +165,7 @@ class AnswerPaper(models.Model): return qs[0] else: return '' - + def questions_left(self): """Returns the number of questions left.""" qs = self.questions @@ -168,7 +173,7 @@ class AnswerPaper(models.Model): return 0 else: return qs.count('|') + 1 - + def completed_question(self, question_id): """Removes the question from the list of questions and returns the next.""" @@ -198,7 +203,7 @@ the next.""" self.questions = '|'.join(qs) self.save() return qs[0] - + def time_left(self): """Return the time remaining for the user in seconds.""" dt = datetime.datetime.now() - self.start_time @@ -233,7 +238,7 @@ the next.""" else: q_a[question] = [answer] return q_a - + 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 f21357e..f24215b 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -52,10 +52,10 @@ def get_user_dir(user): user_dir = join(OUTPUT_DIR, str(user.username)) if not exists(user_dir): os.mkdir(user_dir) - # Make it rwx by others. - os.chmod(user_dir, stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH\ - | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR\ - | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) + # Make it rwx by others. + os.chmod(user_dir, stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH + | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR + | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) return user_dir @@ -110,6 +110,7 @@ def user_register(request): Create a user and corresponding profile and store roll_number also.""" user = request.user + ci = RequestContext(request) if user.is_authenticated(): return my_redirect("/exam/start/") @@ -122,13 +123,11 @@ def user_register(request): login(request, new_user) return my_redirect("/exam/start/") else: - return my_render_to_response('exam/register.html', - {'form': form}, - context_instance=RequestContext(request)) + return my_render_to_response('exam/register.html', {'form': form}, + context_instance=ci) else: form = UserRegisterForm() - return my_render_to_response('exam/register.html', - {'form': form}, context_instance=RequestContext(request)) + return my_render_to_response('exam/register.html', {'form': form}) def quizlist_user(request): @@ -151,14 +150,15 @@ def quizlist_user(request): context = {'quizzes': avail_quiz, 'user': user} return my_render_to_response("exam/quizzes_user.html", context) + def intro(request, questionpaper_id): """Show introduction page before quiz starts""" user = request.user - context = {'user': user, 'paper_id': questionpaper_id } + context = {'user': user, 'paper_id': questionpaper_id} ci = RequestContext(request) return my_render_to_response('exam/intro.html', context, - context_instance=ci) - + context_instance=ci) + def results_user(request): """Show list of Results of Quizzes that is taken by logged-in user.""" @@ -168,7 +168,7 @@ def results_user(request): for paper in papers: marks_obtained = paper.get_total_marks() max_marks = paper.question_paper.total_marks - percentage = round((marks_obtained/max_marks)*100,2) + percentage = round((marks_obtained/max_marks)*100, 2) temp = paper.question_paper.quiz.description, marks_obtained,\ max_marks, percentage quiz_marks.append(temp) @@ -248,6 +248,7 @@ def add_question(request, question_id=None): """To add a new question in the database. Create a new question and store it.""" user = request.user + ci = RequestContext(request) if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') if request.method == "POST": @@ -283,12 +284,14 @@ def add_question(request, question_id=None): return my_redirect("/exam/manage/questions") else: return my_render_to_response('exam/add_question.html', - {'form': form}, context_instance=RequestContext(request)) + {'form': form}, + context_instance=ci) else: if question_id is None: form = QuestionForm() return my_render_to_response('exam/add_question.html', - {'form': form}, context_instance=RequestContext(request)) + {'form': form}, + context_instance=ci) else: d = Question.objects.get(id=question_id) form = QuestionForm() @@ -310,7 +313,7 @@ def add_question(request, question_id=None): form.initial['tags'] = initial_tags return my_render_to_response('exam/add_question.html', {'form': form}, - context_instance=RequestContext(request)) + context_instance=ci) def add_quiz(request, quiz_id=None): @@ -318,6 +321,7 @@ def add_quiz(request, quiz_id=None): Create a new quiz and store it.""" user = request.user + ci = RequestContext(request) if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') if request.method == "POST": @@ -350,13 +354,13 @@ def add_quiz(request, quiz_id=None): else: return my_render_to_response('exam/add_quiz.html', {'form': form}, - context_instance=RequestContext(request)) + context_instance=ci) else: if quiz_id is None: form = QuizForm() return my_render_to_response('exam/add_quiz.html', {'form': form}, - context_instance=RequestContext(request)) + context_instance=ci) else: d = Quiz.objects.get(id=quiz_id) form = QuizForm() @@ -374,24 +378,26 @@ def add_quiz(request, quiz_id=None): form.initial['tags'] = initial_tags return my_render_to_response('exam/add_quiz.html', {'form': form}, - context_instance=RequestContext(request)) + context_instance=ci) def design_questionpaper(request, questionpaper_id=None): user = request.user + ci = RequestContext(request) if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') return my_render_to_response('exam/add_questionpaper.html', {}, - context_instance=RequestContext(request)) + context_instance=ci) def show_all_questionpapers(request, questionpaper_id=None): user = request.user + ci = RequestContext(request) if not user.is_authenticated() or not is_moderator(user): 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/" + \ + return my_redirect("/exam/manage/designquestionpaper/" + questionpaper_id) if request.method == "POST" and request.POST.get('delete') == "delete": @@ -402,25 +408,26 @@ 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)) + context_instance=ci) if questionpaper_id is None: qu_papers = QuestionPaper.objects.all() context = {'papers': qu_papers} return my_render_to_response('exam/showquestionpapers.html', context, - context_instance=RequestContext(request)) + context_instance=ci) else: qu_papers = QuestionPaper.objects.get(id=questionpaper_id) quiz = qu_papers.quiz questions = qu_papers.questions.all() context = {'papers': {'quiz': quiz, 'questions': questions}} return my_render_to_response('exam/editquestionpaper.html', context, - context_instance=RequestContext(request)) + context_instance=ci) def automatic_questionpaper(request, questionpaper_id=None): """Generate automatic question paper for a particular quiz""" user = request.user + ci = RequestContext(request) if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') @@ -459,14 +466,14 @@ def automatic_questionpaper(request, questionpaper_id=None): context = {'data': {'questions': fetched_questions, 'tags': tags, 'msg': msg}} - return my_render_to_response(\ + return my_render_to_response( 'exam/automatic_questionpaper.html', context, - context_instance=RequestContext(request)) + context_instance=ci) else: tags = Tag.objects.all() context = {'data': {'tags': tags}} return my_render_to_response('exam/automatic_questionpaper.html', - context, context_instance=RequestContext(request)) + context, context_instance=ci) else: if request.method == "POST": @@ -501,18 +508,19 @@ def automatic_questionpaper(request, questionpaper_id=None): context = {'data': {'questions': fetched_questions, '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=ci) else: tags = Tag.objects.all() context = {'data': {'tags': tags}} return my_render_to_response('exam/automatic_questionpaper.html', - context, context_instance=RequestContext(request)) + context, context_instance=ci) def manual_questionpaper(request, questionpaper_id=None): user = request.user + ci = RequestContext(request) if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') @@ -541,16 +549,16 @@ def manual_questionpaper(request, questionpaper_id=None): if (n == 0): msg = 'No matching Question found...' tags = Tag.objects.all() - context = {'data': {'questions': fetched_questions,\ + context = {'data': {'questions': fetched_questions, 'tags': tags, 'msg': msg}} return my_render_to_response('exam/manual_questionpaper.html', context, - context_instance=RequestContext(request)) + context_instance=ci) else: tags = Tag.objects.all() context = {'data': {'tags': tags}} return my_render_to_response('exam/manual_questionpaper.html', - context, context_instance=RequestContext(request)) + context, context_instance=ci) else: if request.method == "POST": @@ -574,17 +582,16 @@ def manual_questionpaper(request, questionpaper_id=None): if (n == 0): msg = 'No matching Question found...' tags = Tag.objects.all() - context = {'data': {'questions': fetched_questions,\ + context = {'data': {'questions': fetched_questions, 'tags': tags, 'msg': msg}} return my_render_to_response('exam/manual_questionpaper.html', context, - context_instance=RequestContext(request)) + context_instance=ci) else: tags = Tag.objects.all() context = {'data': {'tags': tags}} return my_render_to_response('exam/manual_questionpaper.html', - context, context_instance=RequestContext(request)) - + context, context_instance=ci) def prof_manage(request): @@ -602,6 +609,7 @@ def user_login(request): """Take the credentials of the user and log the user in.""" user = request.user + ci = RequestContext(request) if user.is_authenticated(): if user.groups.filter(name='moderator').count() > 0: return my_redirect('/exam/manage/') @@ -618,12 +626,12 @@ def user_login(request): else: context = {"form": form} return my_render_to_response('exam/login.html', context, - context_instance=RequestContext(request)) + context_instance=ci) else: form = UserLoginForm() context = {"form": form} return my_render_to_response('exam/login.html', context, - context_instance=RequestContext(request)) + context_instance=ci) def start(request, questionpaper_id=None): @@ -642,7 +650,7 @@ def start(request, questionpaper_id=None): return complete(request, msg, questionpaper_id) try: - old_paper = AnswerPaper.objects.get(\ + old_paper = AnswerPaper.objects.get( question_paper=questionpaper, user=user) q = old_paper.current_question() return show_question(request, q, questionpaper_id) @@ -669,7 +677,8 @@ def start(request, questionpaper_id=None): new_paper.save() return start(request, questionpaper_id) -def question(request, q_id, questionpaper_id,success_msg=None): + +def question(request, q_id, questionpaper_id, success_msg=None): """Check the credentials of the user and start the exam.""" user = request.user @@ -678,12 +687,12 @@ def question(request, q_id, questionpaper_id,success_msg=None): q = get_object_or_404(Question, pk=q_id) try: q_paper = QuestionPaper.objects.get(id=questionpaper_id) - paper = AnswerPaper.objects.get(\ + 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: - reason='The quiz has been deactivated!' + reason = 'The quiz has been deactivated!' return complete(request, reason, questionpaper_id) #if new: # paper.start_time = datetime.datetime.now() @@ -695,30 +704,28 @@ def question(request, q_id, questionpaper_id,success_msg=None): if success_msg is None: context = {'question': q, 'paper': paper, 'user': user, 'quiz_name': quiz_name, - 'time_left': time_left,} - + 'time_left': time_left, } else: context = {'question': q, 'paper': paper, 'user': user, 'quiz_name': quiz_name, 'time_left': time_left, - 'success_msg':success_msg} - + 'success_msg': success_msg} ci = RequestContext(request) - return my_render_to_response('exam/question.html', context, + return my_render_to_response('exam/question.html', context, context_instance=ci) -def show_question(request, q_id, questionpaper_id,success_msg=None): +def show_question(request, q_id, questionpaper_id, success_msg=None): """Show a question if possible.""" if len(q_id) == 0: msg = 'Congratulations! You have successfully completed the quiz.' - return complete(request, msg,questionpaper_id) + return complete(request, msg, questionpaper_id) else: - return question(request, q_id, questionpaper_id,success_msg) + return question(request, q_id, questionpaper_id, success_msg) def check(request, q_id, questionpaper_id=None): - """Checks the answers of the user for particular question""" + """Checks the answers of the user for particular question""" user = request.user if not user.is_authenticated(): @@ -734,10 +741,10 @@ def check(request, q_id, questionpaper_id=None): if skip is not None: next_q = paper.skip() return show_question(request, next_q, questionpaper_id) - + if question.type == 'mcq': # Add the answer submitted, regardless of it being correct or not. - if user_answer is not None : + if user_answer is not None: new_answer = Answer(question=question, answer=user_answer, correct=False) new_answer.save() @@ -756,7 +763,7 @@ def check(request, q_id, questionpaper_id=None): # questions, we obtain the results via XML-RPC with the code executed # safely in a separate process (the code_server.py) running as nobody. if question.type == 'mcq': - if user_answer is not None: + if user_answer is not None: success = True # Only one attempt allowed for MCQ's. if user_answer.strip() == question.test.strip(): new_answer.correct = True @@ -765,10 +772,10 @@ def check(request, q_id, questionpaper_id=None): success_msg = True else: new_answer.error = 'Incorrect answer' - new_answer.save() + new_answer.save() else: user_dir = get_user_dir(user) - success, err_msg = code_server.run_code(answer_check, question.test, + success, err_msg = code_server.run_code(answer_check, question.test, user_dir, question.type) new_answer.error = err_msg if success: @@ -781,10 +788,10 @@ def check(request, q_id, questionpaper_id=None): time_left = paper.time_left() if not success: # Should only happen for non-mcq questions. if time_left == 0: - reason='Your time is up!' + reason = 'Your time is up!' return complete(request, reason, questionpaper_id) if not paper.question_paper.quiz.active: - reason='The quiz has been deactivated!' + reason = 'The quiz has been deactivated!' return complete(request, reason, questionpaper_id) context = {'question': question, 'error_message': err_msg, 'paper': paper, 'last_attempt': user_answer, @@ -792,27 +799,28 @@ def check(request, q_id, questionpaper_id=None): 'time_left': time_left} ci = RequestContext(request) - return my_render_to_response('exam/question.html', context, + return my_render_to_response('exam/question.html', context, context_instance=ci) else: if time_left <= 0: - reason='Your time is up!' + reason = 'Your time is up!' return complete(request, reason, questionpaper_id) else: next_q = paper.completed_question(question.id) - return show_question(request, next_q, questionpaper_id,success_msg) + return show_question(request, next_q, + questionpaper_id, success_msg) def quit(request, questionpaper_id=None): """Show the quit page when the user logs out.""" context = {'id': questionpaper_id} return my_render_to_response('exam/quit.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def complete(request, reason=None, questionpaper_id=None): """Show a page to inform user that the quiz has been compeleted.""" - + user = request.user if questionpaper_id is None: logout(request) @@ -826,16 +834,16 @@ def complete(request, reason=None, questionpaper_id=None): tot_marks = paper.question_paper.total_marks if obt_marks == paper.question_paper.total_marks: context = {'message': "Hurray ! You did an excellent job.\ - you answered all the questions correctly.\ - You have been logged out successfully,\ - Thank You !"} + you answered all the questions correctly.\ + You have been logged out successfully,\ + Thank You !"} logout(request) - return my_render_to_response('exam/complete.html',context) + return my_render_to_response('exam/complete.html', context) else: message = reason or "You are successfully logged out" - context = {'message': message } + context = {'message': message} logout(request) - return my_render_to_response('exam/complete.html',context) + 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: @@ -856,16 +864,17 @@ def monitor(request, questionpaper_id=None): """Monitor the progress of the papers taken so far.""" user = request.user + ci = RequestContext(request) if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page!') if questionpaper_id is None: q_paper = QuestionPaper.objects.all() - context = {'papers': [], - 'quiz': None, + context = {'papers': [], + 'quiz': None, 'quizzes': q_paper} return my_render_to_response('exam/monitor.html', context, - context_instance=RequestContext(request)) + context_instance=ci) # quiz_id is not None. try: q_paper = QuestionPaper.objects.get(id=questionpaper_id) @@ -878,7 +887,7 @@ def monitor(request, questionpaper_id=None): context = {'papers': papers, 'quiz': q_paper, 'quizzes': None} return my_render_to_response('exam/monitor.html', context, - context_instance=RequestContext(request)) + context_instance=ci) def get_user_data(username): @@ -896,7 +905,7 @@ def get_user_data(username): profile = None data['user'] = user data['profile'] = profile - data['papers'] = papers + data['papers'] = papers return data @@ -918,6 +927,7 @@ def show_all_quiz(request): that are currently in the database.""" user = request.user + ci = RequestContext(request) if not user.is_authenticated() or not is_moderator(user): raise Http404('You are not allowed to view this page !') @@ -926,20 +936,20 @@ def show_all_quiz(request): if data is None: quizzes = Quiz.objects.all() - context = {'papers': [], - 'quiz': None, + context = {'papers': [], + 'quiz': None, 'quizzes': quizzes} return my_render_to_response('exam/show_quiz.html', context, - context_instance=RequestContext(request)) + context_instance=ci) else: for i in data: quiz = Quiz.objects.get(id=i).delete() quizzes = Quiz.objects.all() - context = {'papers': [], - 'quiz': None, + context = {'papers': [], + 'quiz': None, 'quizzes': quizzes} return my_render_to_response('exam/show_quiz.html', context, - context_instance=RequestContext(request)) + context_instance=ci) elif request.method == 'POST' and request.POST.get('edit') == 'edit': data = request.POST.getlist('quiz') @@ -962,20 +972,21 @@ def show_all_quiz(request): forms.append(form) return my_render_to_response('exam/edit_quiz.html', {'forms': forms, 'data': data}, - context_instance=RequestContext(request)) + context_instance=ci) else: quizzes = Quiz.objects.all() - context = {'papers': [], - 'quiz': None, + context = {'papers': [], + 'quiz': None, 'quizzes': quizzes} return my_render_to_response('exam/show_quiz.html', context, - context_instance=RequestContext(request)) + context_instance=ci) def show_all_questions(request): """Show a list of all the questions currently in the databse.""" user = request.user + ci = RequestContext(request) if not user.is_authenticated() or not is_moderator(user): raise Http404("You are not allowed to view this page !") @@ -987,7 +998,7 @@ def show_all_questions(request): 'question': None, 'questions': questions} return my_render_to_response('exam/showquestions.html', context, - context_instance=RequestContext(request)) + context_instance=ci) else: for i in data: question = Question.objects.get(id=i).delete() @@ -996,7 +1007,7 @@ def show_all_questions(request): 'question': None, 'questions': questions} return my_render_to_response('exam/showquestions.html', context, - context_instance=RequestContext(request)) + context_instance=ci) elif request.method == 'POST' and request.POST.get('edit') == 'edit': data = request.POST.getlist('question') @@ -1023,14 +1034,14 @@ def show_all_questions(request): forms.append(form) return my_render_to_response('exam/edit_question.html', {'forms': forms, 'data': data}, - context_instance=RequestContext(request)) + context_instance=ci) else: questions = Question.objects.all() context = {'papers': [], 'question': None, 'questions': questions} return my_render_to_response('exam/showquestions.html', context, - context_instance=RequestContext(request)) + context_instance=ci) def user_data(request, username): @@ -1052,6 +1063,7 @@ def grade_user(request, username): and update all their marks and also give comments for each paper. """ current_user = request.user + ci = RequestContext(request) if not current_user.is_authenticated() or not is_moderator(current_user): raise Http404('You are not allowed to view this page!') @@ -1064,14 +1076,14 @@ def grade_user(request, username): last_ans = answers[-1] last_ans.marks = marks last_ans.save() - paper.comments = request.POST.get(\ + paper.comments = request.POST.get( 'comments_%d' % paper.question_paper.id) paper.save() context = {'data': data} return my_render_to_response('exam/user_data.html', context, - context_instance=RequestContext(request)) + context_instance=ci) else: context = {'data': data} return my_render_to_response('exam/grade_user.html', context, - context_instance=RequestContext(request)) + context_instance=ci) |