From 6eab6722046625f8bc02966be6a32e1fd43b4ac4 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 27 Apr 2016 00:13:49 +0530 Subject: modified grade user, get_user_data, user_data --- yaksh/views.py | 75 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 31 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 5cc9f99..ff5ff7e 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -759,16 +759,17 @@ def monitor(request, questionpaper_id=None): return my_render_to_response('yaksh/monitor.html', context, context_instance=ci) - -def get_user_data(username, questionpaper_id=None): +def get_user_data(user_id, questionpaper_id=None, attempt_number = None): """For a given username, this returns a dictionary of important data related to the user including all the user's answers submitted. """ - user = User.objects.get(username=username) + user = User.objects.get(id=user_id) papers = AnswerPaper.objects.filter(user=user) - if questionpaper_id is not None: - papers = papers.filter(question_paper_id=questionpaper_id).order_by( + if questionpaper_id and attempt_number is not None: + papers = papers.filter(question_paper_id=questionpaper_id, attempt_number = attempt_number).order_by( '-attempt_number') + if attempt_number == None: + papers = papers.filter(question_paper_id=questionpaper_id).order_by("-attempt_number") data = {} profile = user.profile if hasattr(user, 'profile') else None @@ -779,6 +780,7 @@ def get_user_data(username, questionpaper_id=None): return data + @login_required def show_all_users(request): """Shows all the users who have taken various exams/quiz.""" @@ -842,14 +844,12 @@ def show_all_questions(request): context_instance=ci) @login_required -def user_data(request, username, questionpaper_id=None): +def user_data(request, user_id, questionpaper_id=None): """Render user data.""" - current_user = request.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, questionpaper_id) + data = get_user_data(user_id, questionpaper_id) context = {'data': data} return my_render_to_response('yaksh/user_data.html', context, @@ -901,9 +901,9 @@ def download_csv(request, questionpaper_id): writer.writerow(row) return response - @login_required -def grade_user(request, username, questionpaper_id=None): +def grade_user(request, quiz_id = None, user_id=None, attempt_number = None): + """Present an interface with which we can easily grade a user's papers and update all their marks and also give comments for each paper. """ @@ -911,26 +911,39 @@ def grade_user(request, username, questionpaper_id=None): 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!') - data = get_user_data(username, questionpaper_id) - if request.method == 'POST': - papers = data['papers'] - for paper in papers: - for question, answers in paper.get_question_answers().iteritems(): - marks = float(request.POST.get('q%d_marks' % question.id, 0)) - last_ans = answers[-1] - last_ans.marks = marks - last_ans.save() - paper.comments = request.POST.get( - 'comments_%d' % paper.question_paper.id, 'No comments') - paper.save() - - context = {'data': data} - return my_render_to_response('yaksh/user_data.html', context, - context_instance=ci) - else: - context = {'data': data} - return my_render_to_response('yaksh/grade_user.html', context, - context_instance=ci) + + course_details =Course.objects.filter(creator = current_user) + context = {"course_details": course_details} + + if quiz_id != None: + questionpaper_id = QuestionPaper.objects.filter(quiz_id = quiz_id).values("id") + user_details = AnswerPaper.objects.get_users_for_questionpaper(questionpaper_id) + context = {"users": user_details, "quiz_id": quiz_id} + + if user_id !=None: + attempts = AnswerPaper.objects.get_user_all_attempts(questionpaper_id, user_id) + + if attempt_number == None: + attempt_number = attempts[0].attempt_number + + data = get_user_data(user_id, questionpaper_id, attempt_number) + if request.method == "POST": + papers = data['papers'] + for paper in papers: + for question, answers in paper.get_question_answers().iteritems(): + marks = float(request.POST.get('q%d_marks' % question.id, 0)) + last_ans = answers[-1] + last_ans.marks = marks + last_ans.save() + paper.comments = request.POST.get( + 'comments_%d' % paper.question_paper.id, 'No comments') + paper.save() + + context = {'data': data,"quiz_id": quiz_id, "users": user_details, + "attempts": attempts,"user_id":user_id + } + + return my_render_to_response('yaksh/grade_user.html', context, context_instance=ci) @csrf_exempt -- cgit From 2537f5cf9ed24009eda1fe21dd2cda91574ca60e Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 27 Apr 2016 00:14:35 +0530 Subject: added new css elements --- yaksh/static/yaksh/css/gradeuser.css | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/static/yaksh/css/gradeuser.css b/yaksh/static/yaksh/css/gradeuser.css index 07b1079..af5de3f 100644 --- a/yaksh/static/yaksh/css/gradeuser.css +++ b/yaksh/static/yaksh/css/gradeuser.css @@ -36,7 +36,7 @@ color: #9EB6FF; border: 1px solid #C9C9C9; border-radius: 5px 5px 5px 5px; margin-bottom: 10px; - min-width: 805px; + min-width: 685px; } @@ -50,3 +50,9 @@ margin: 10px 10px 5px 5px; } #headerDiv a:hover { color: #FFFFFF; +} + +#attempt { + width: 157px; + position: relative; left:20%; +} -- cgit From 7b0764cc8e6e03fee849c9d72bada7abb4e109e9 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 27 Apr 2016 00:15:17 +0530 Subject: added manager methods for grade user --- yaksh/models.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index a4ea6c3..86d718e 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -499,6 +499,19 @@ class AnswerPaperManager(models.Manager): def get_total_attempt(self, questionpaper, user): return self.filter(question_paper=questionpaper, user=user).count() + def get_users_for_questionpaper(self, questionpaper_id): + return self.get_answerpapers_for_quiz(questionpaper_id)\ + .values("user__id", "user__first_name", "user__last_name")\ + .distinct() + + def get_user_all_attempts(self, questionpaper, user): + return self.filter(question_paper=questionpaper, user=user)\ + .order_by('-attempt_number') + + def get_user_all_attempts(self, questionpaper,user): + return self.filter(question_paper=questionpaper, user= user).order_by('-attempt_number') + + ############################################################################### class AnswerPaper(models.Model): """A answer paper for a student -- one per student typically. @@ -695,5 +708,3 @@ class TestCase(models.Model): # Test case Expected answer in list form expected_answer = models.TextField(blank=True, null = True) - - -- cgit From 3833fa423daaf55e30c89d2cd3b02d5bf5f080f5 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 27 Apr 2016 00:15:53 +0530 Subject: changed urls for gradeuser, user_data --- yaksh/urls.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'yaksh') diff --git a/yaksh/urls.py b/yaksh/urls.py index ea1922d..b32bc36 100644 --- a/yaksh/urls.py +++ b/yaksh/urls.py @@ -44,19 +44,19 @@ urlpatterns += [ url(r'^manage/addquestion/(?P\d+)/$', views.add_question), url(r'^manage/addquiz/$', views.add_quiz), url(r'^manage/addquiz/(?P\d+)/$', views.add_quiz), - url(r'^manage/gradeuser/$', views.show_all_users), - url(r'^manage/gradeuser/(?P.*)/(?P\d+)/$', - views.grade_user), - url(r'^manage/gradeuser/(?P.*)/$', views.grade_user), + url(r'^manage/gradeuser/$', views.grade_user), + url(r'^manage/gradeuser/(?P\d+)/$',views.grade_user), + url(r'^manage/gradeuser/(?P\d+)/(?P\d+)/$',views.grade_user), + url(r'^manage/gradeuser/(?P\d+)/(?P\d+)/(?P\d+)/$',views.grade_user), url(r'^manage/questions/$', views.show_all_questions), url(r'^manage/monitor/$', views.monitor), url(r'^manage/showquestionpapers/$', views.show_all_questionpapers), url(r'^manage/showquestionpapers/(?P\d+)/$',\ views.show_all_questionpapers), url(r'^manage/monitor/(?P\d+)/$', views.monitor), - url(r'^manage/user_data/(?P.*)/(?P\d+)/$', + url(r'^manage/user_data/(?P\d+)/(?P\d+)/$', views.user_data), - url(r'^manage/user_data/(?P.*)/$', views.user_data), + url(r'^manage/user_data/(?P\d+)/$', views.user_data), url(r'^manage/designquestionpaper/$', views.design_questionpaper), url(r'^manage/designquestionpaper/(?P\d+)/$',\ views.design_questionpaper), -- cgit From b121bc18fd60e3f3f42f0093bf3a74b6d66cd006 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 27 Apr 2016 00:16:50 +0530 Subject: changed from username to user_id --- yaksh/templates/yaksh/user_data.html | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/user_data.html b/yaksh/templates/yaksh/user_data.html index 22be3ed..04544f9 100644 --- a/yaksh/templates/yaksh/user_data.html +++ b/yaksh/templates/yaksh/user_data.html @@ -22,11 +22,11 @@ Last login: {{ data.user.last_login }} {% if data.papers %} {% if data.questionpaperid %} -

+

Grade/correct paper

{% else %} -

+

Grade/correct paper {% endif %} @@ -41,7 +41,7 @@ Last login: {{ data.user.last_login }} Attempt Number: {{ paper.attempt_number }}
Questions correctly answered: {{ paper.get_answered_str }}
Total attempts at questions: {{ paper.answers.count }}
-Marks obtained: {{ paper.get_total_marks }}
+Marks obtained: {{ paper.marks_obtained }}
Start time: {{ paper.start_time }}
User IP address: {{ paper.user_ip }}

@@ -75,9 +75,12 @@ User IP address: {{ paper.user_ip }} {% endif %} {# if data.papers #}

- - Grade/correct paper -
+ +{% with data.papers.0 as paper %} +Grade/correct paper +{% endwith %} +
+ {% if data.papers.count > 1 %} Monitor quiz {% else %} -- cgit From 71c800cfff1fca003f1bdc5e0e53e857cbd7a6d6 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 27 Apr 2016 00:17:31 +0530 Subject: changed from username to user_id --- yaksh/templates/yaksh/monitor.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/monitor.html b/yaksh/templates/yaksh/monitor.html index b81c9f2..80ad06c 100644 --- a/yaksh/templates/yaksh/monitor.html +++ b/yaksh/templates/yaksh/monitor.html @@ -9,13 +9,13 @@ {% endblock %} {% block subtitle %} {% if not quizzes and not quiz %} - Quiz Results + Quiz Results {% endif %} {% if quizzes %} - Available Quizzes + Available Quizzes {% endif %} {% if quiz %} - {{ quiz.description }} Results + {{ quiz.description }} Results {% endif %} {% endblock %} {% block manage %} @@ -54,7 +54,7 @@ {% for paper in latest_attempts %} - {{ paper.user.get_full_name.title }} + {{ paper.user.get_full_name.title }} {{ paper.user.username }} {{ paper.user.profile.roll_number }} {{ paper.user.profile.institute }} @@ -69,4 +69,4 @@

No answer papers so far.

{% endif %} {# if papers #} {% endif %} -{% endblock %} +{% endblock %} \ No newline at end of file -- cgit From 93cccd1e3b579eed644756e86100444b2d346f64 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 27 Apr 2016 00:18:12 +0530 Subject: changed template to reflect new grade_user design --- yaksh/templates/yaksh/grade_user.html | 109 ++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 24 deletions(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index dd05670..d2de194 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -1,46 +1,101 @@ {% extends "manage.html" %} -{% block title %} Grading papers for {{ data.user.get_full_name.title }} {% endblock title %} +{% block title %} Grade User {% endblock title %} -{% block subtitle %}Grading papers for {{ data.user.get_full_name.title }}{% endblock %} +{% block subtitle %} Grade User {% endblock %} {% block css %} - + {% endblock %} {% block script %} - + {% endblock %} + {% block manage %} -

-Name: {{ data.user.get_full_name.title }} +{% if course_details %} + + + + + + + {% for course in course_details %} + + + + {% if course.get_quizzes %} + + {% else %} + + {% endif %} + + {% endfor %} +
Courses Quizzes
    {{course.name}}
+ {% for quiz in course.get_quizzes %} +
  • {{quiz.description}}
  • + + {% endfor %} +
    No quiz
    +{% endif %} + +

    +{%if users %} +
    + {% for user in users %} +

    {{user.user__first_name}} {{user.user__last_name}}

    + {% endfor %} +
    +{% endif %} + + + +
    {#not found yet#} +{% if data %} + + +

    Showing paper for {{data.user.get_full_name.title}}

    +

    Name:{{ data.user.get_full_name.title }} {% if data.profile %} -(roll number: {{ data.profile.roll_number }})
    -Position: {{ data.profile.position }}
    -Department: {{ data.profile.department }}
    -Institute: {{ data.profile.institute }}
    + +

    Roll number: {{ data.profile.roll_number }} +

    Position: {{ data.profile.position }} +

    Department: {{ data.profile.department }} +

    Institute: {{ data.profile.institute }} {% endif %} -

    {% if data.papers %} {% for paper in data.papers %} - -{% if forloop.counter == 2 and data.questionpaperid %}
    -

    Previous attempts

    -{% endif %} {{ paper.total_marks }} -

    Quiz: {{ paper.question_paper.quiz.description }}

    +

    Quiz: {{ paper.question_paper.quiz.description }}

    -Attempt Number: {{ paper.attempt_number }}
    -Questions correctly answered: {{ paper.get_answered_str }}
    +Attempt Number: {{paper.attempt_number}} + + +
    Questions correctly answered: {{ paper.get_answered_str }}
    Total attempts at questions: {{ paper.answers.count }}
    -Marks obtained: {{ paper.get_total_marks }}
    +Marks obtained: {{ paper.marks_obtained }}
    Start time: {{ paper.start_time }}
    +{%if paper.percent%} +Percentage obtained: {{paper.percent}}%
    +{% endif %} +{% if paper.passed == 0 %} +Status : Failed
    +{% else %} +Status : Passed
    +{% endif %}

    {% if paper.answers.count %} @@ -59,12 +114,13 @@ Start time: {{ paper.start_time }}
    {% endfor %} +

    Answers


    {% csrf_token %} @@ -72,13 +128,13 @@ Start time: {{ paper.start_time }}

    - Question: {{ question.id }}. {{ question.summary }} (Points: {{ question.points }}) + Question: {{ question.id }}. {{ question.summary }} (Points: {{ question.points }}) Details

    @@ -113,10 +169,15 @@ Marks: +
    + {% endif %} {# if paper.answers.count #} {% endfor %} {# for paper in data.papers #} -{% endif %} {# if data.papers #} +{% endif %} {# if data.papers #} +{% endif %} {#if data#} +
    +
    {% endblock%} -- cgit From 1341166e68e94c9cfccad403acaa24f2fd26668f Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 27 Apr 2016 00:20:46 +0530 Subject: removed a duplicated method --- yaksh/models.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 86d718e..af52e22 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -508,9 +508,6 @@ class AnswerPaperManager(models.Manager): return self.filter(question_paper=questionpaper, user=user)\ .order_by('-attempt_number') - def get_user_all_attempts(self, questionpaper,user): - return self.filter(question_paper=questionpaper, user= user).order_by('-attempt_number') - ############################################################################### class AnswerPaper(models.Model): -- cgit From ee8fde58fff03b1ce955ae0a554959d3317c5f60 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 27 Apr 2016 00:24:48 +0530 Subject: removed a duplicated method --- yaksh/views.py | 1 - 1 file changed, 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index ff5ff7e..6426a6d 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -903,7 +903,6 @@ def download_csv(request, questionpaper_id): @login_required def grade_user(request, quiz_id = None, user_id=None, attempt_number = None): - """Present an interface with which we can easily grade a user's papers and update all their marks and also give comments for each paper. """ -- cgit From ccf25eabf2ff430443c0f64e4a48188607f51bc5 Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 2 May 2016 16:13:34 +0530 Subject: made changes to grade_user --- yaksh/views.py | 64 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 29 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 6426a6d..e01c224 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -472,6 +472,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): new_answer.error = result.get('error') new_answer.save() paper.update_marks('inprogress') + paper.update_time(datetime.now()) if not result.get('success'): # Should only happen for non-mcq questions. new_answer.answer = user_code new_answer.save() @@ -548,6 +549,7 @@ def complete(request, reason=None, attempt_num=None, questionpaper_id=None): paper = AnswerPaper.objects.get(user=user, question_paper=q_paper, attempt_number=attempt_num) paper.update_marks() + paper.set_end_time(datetime.now()) if paper.percent == 100: message = "You answered all the questions correctly.\ You have been logged out successfully,\ @@ -766,8 +768,7 @@ def get_user_data(user_id, questionpaper_id=None, attempt_number = None): user = User.objects.get(id=user_id) papers = AnswerPaper.objects.filter(user=user) if questionpaper_id and attempt_number is not None: - papers = papers.filter(question_paper_id=questionpaper_id, attempt_number = attempt_number).order_by( - '-attempt_number') + papers = papers.filter(question_paper_id=questionpaper_id, attempt_number = attempt_number) if attempt_number == None: papers = papers.filter(question_paper_id=questionpaper_id).order_by("-attempt_number") @@ -901,8 +902,9 @@ def download_csv(request, questionpaper_id): writer.writerow(row) return response + @login_required -def grade_user(request, quiz_id = None, user_id=None, attempt_number = None): +def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): """Present an interface with which we can easily grade a user's papers and update all their marks and also give comments for each paper. """ @@ -910,38 +912,42 @@ def grade_user(request, quiz_id = None, user_id=None, attempt_number = None): 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!') - - course_details =Course.objects.filter(creator = current_user) + course_details = Course.objects.filter(creator=current_user) context = {"course_details": course_details} - - if quiz_id != None: - questionpaper_id = QuestionPaper.objects.filter(quiz_id = quiz_id).values("id") - user_details = AnswerPaper.objects.get_users_for_questionpaper(questionpaper_id) + if quiz_id is not None: + questionpaper_id = QuestionPaper.objects.filter(quiz_id=quiz_id)\ + .values("id") + user_details = AnswerPaper.objects.get_users_for_questionpaper\ + (questionpaper_id) context = {"users": user_details, "quiz_id": quiz_id} - - if user_id !=None: - attempts = AnswerPaper.objects.get_user_all_attempts(questionpaper_id, user_id) - - if attempt_number == None: - attempt_number = attempts[0].attempt_number + if user_id is not None: + try: + attempts = AnswerPaper.objects.get_user_all_attempts\ + (questionpaper_id, user_id) + if attempt_number is None: + attempt_number = attempts[0].attempt_number + except IndexError: + raise Http404('No attempts for paper') data = get_user_data(user_id, questionpaper_id, attempt_number) - if request.method == "POST": - papers = data['papers'] - for paper in papers: - for question, answers in paper.get_question_answers().iteritems(): - marks = float(request.POST.get('q%d_marks' % question.id, 0)) - last_ans = answers[-1] - last_ans.marks = marks - last_ans.save() - paper.comments = request.POST.get( - 'comments_%d' % paper.question_paper.id, 'No comments') - paper.save() context = {'data': data,"quiz_id": quiz_id, "users": user_details, - "attempts": attempts,"user_id":user_id - } - + "attempts": attempts,"user_id":user_id + } + if request.method == "POST": + papers = data['papers'] + for paper in papers: + for question, answers in paper.get_question_answers().iteritems(): + marks = float(request.POST.get('q%d_marks' % question.id, 0)) + answers = answers[-1] + answers.set_marks(marks) + answers.save() + paper.update_marks() + paper.comments = request.POST.get( + 'comments_%d' % paper.question_paper.id, 'No comments') + paper.save() + + return my_render_to_response('yaksh/grade_user.html', context, context_instance=ci) -- cgit From c5eb9787a2363a9e54a4ee21a87b3d6029413a92 Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 2 May 2016 16:15:48 +0530 Subject: added/modified model methods and manager methods --- yaksh/models.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index af52e22..4029579 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -235,10 +235,15 @@ class Answer(models.Model): # Whether skipped or not. skipped = models.BooleanField(default=False) + def set_marks(self, marks): + if marks > self.question.points: + self.marks = self.question.points + else: + self.marks = marks + def __unicode__(self): return self.answer - ############################################################################### class QuizManager(models.Manager): def get_active_quizzes(self): @@ -470,8 +475,13 @@ class AnswerPaperManager(models.Manager): question_stats[question] = [0, questions[question.id]] return question_stats - def get_answerpapers_for_quiz(self, questionpaper_id): - return self.filter(question_paper_id=questionpaper_id) + def _get_answerpapers_for_quiz(self, questionpaper_id, status=False): + if not status: + return self.filter(question_paper_id=questionpaper_id) + else: + return self.filter(question_paper_id=questionpaper_id, + status="completed") + def _get_answerpapers_users(self, answerpapers): return answerpapers.values_list('user', flat=True).distinct() @@ -500,7 +510,7 @@ class AnswerPaperManager(models.Manager): return self.filter(question_paper=questionpaper, user=user).count() def get_users_for_questionpaper(self, questionpaper_id): - return self.get_answerpapers_for_quiz(questionpaper_id)\ + return self._get_answerpapers_for_quiz(questionpaper_id, status=True)\ .values("user__id", "user__first_name", "user__last_name")\ .distinct() @@ -639,7 +649,11 @@ class AnswerPaper(models.Model): self._update_percent() self._update_passed() self._update_status(state) - self.end_time = datetime.now() + self.save() + + def set_end_time(self,datetime): + """ Sets end time """ + self.end_time = datetime self.save() def get_question_answers(self): @@ -705,3 +719,4 @@ class TestCase(models.Model): # Test case Expected answer in list form expected_answer = models.TextField(blank=True, null = True) +################################################################################# -- cgit From 7ada338fa018affd304be25c1c0efb935213e4b5 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 4 May 2016 11:45:00 +0530 Subject: rebase changes --- yaksh/tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'yaksh') diff --git a/yaksh/tests.py b/yaksh/tests.py index cc3100e..1a5c8ee 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -355,6 +355,11 @@ class AnswerPaperTestCases(unittest.TestCase): self.assertTrue(self.answerpaper.passed) self.assertFalse(self.answerpaper.is_attempt_inprogress()) + def test_set_end_time(self): + current_time = datetime.now() + self.answerpaper.set_end_time(current_time) + self.assertEqual(self.answerpaper.end_time,current_time) + def test_get_question_answer(self): """ Test get_question_answer() method of Answer Paper""" answered = self.answerpaper.get_question_answers() @@ -375,6 +380,11 @@ class AnswerPaperTestCases(unittest.TestCase): self.assertEqual(answers.count(), 1) self.assertTrue(answers[0], self.answer_wrong) + def test_set_marks (self): + self.answer_wrong.set_marks(0.5) + self.assertEqual(self.answer_wrong.marks, 0.5) + + ############################################################################### class CourseTestCases(unittest.TestCase): def setUp(self): -- cgit From f3379350276ecd73f4856c4fca006ffb1e857066 Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 2 May 2016 17:57:45 +0530 Subject: removed get_user_data --- yaksh/views.py | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index e01c224..587ca57 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -761,26 +761,6 @@ def monitor(request, questionpaper_id=None): return my_render_to_response('yaksh/monitor.html', context, context_instance=ci) -def get_user_data(user_id, questionpaper_id=None, attempt_number = None): - """For a given username, this returns a dictionary of important data - related to the user including all the user's answers submitted. - """ - user = User.objects.get(id=user_id) - papers = AnswerPaper.objects.filter(user=user) - if questionpaper_id and attempt_number is not None: - papers = papers.filter(question_paper_id=questionpaper_id, attempt_number = attempt_number) - if attempt_number == None: - papers = papers.filter(question_paper_id=questionpaper_id).order_by("-attempt_number") - - data = {} - profile = user.profile if hasattr(user, 'profile') else None - data['user'] = user - data['profile'] = profile - data['papers'] = papers - data['questionpaperid'] = questionpaper_id - return data - - @login_required def show_all_users(request): @@ -850,7 +830,8 @@ def user_data(request, user_id, questionpaper_id=None): current_user = request.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(user_id, questionpaper_id) + user = User.objects.get(id=user_id) + data = AnswerPaper.objects.get_user_data(user, questionpaper_id) context = {'data': data} return my_render_to_response('yaksh/user_data.html', context, @@ -928,8 +909,10 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): attempt_number = attempts[0].attempt_number except IndexError: raise Http404('No attempts for paper') - - data = get_user_data(user_id, questionpaper_id, attempt_number) + user = User.objects.get(id=user_id) + data = AnswerPaper.objects.get_user_data(user,questionpaper_id, + attempt_number + ) context = {'data': data,"quiz_id": quiz_id, "users": user_details, "attempts": attempts,"user_id":user_id -- cgit From 4341bf83f9eef904a9dd5f515dd0159f9c05de7d Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 2 May 2016 17:58:31 +0530 Subject: added get_user_data in answerpaper manager method --- yaksh/models.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 4029579..f3b8e52 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -518,6 +518,23 @@ class AnswerPaperManager(models.Manager): return self.filter(question_paper=questionpaper, user=user)\ .order_by('-attempt_number') + def get_user_data(self, user, questionpaper_id, attempt_number = None): + + if attempt_number is not None: + papers = self.filter( user=user, question_paper_id=questionpaper_id, + attempt_number = attempt_number) + else: + papers = self.filter(user=user, question_paper_id=questionpaper_id)\ + .order_by("-attempt_number") + + data = {} + profile = user.profile if hasattr(user, 'profile') else None + data['user'] = user + data['profile'] = profile + data['papers'] = papers + data['questionpaperid'] = questionpaper_id + return data + ############################################################################### class AnswerPaper(models.Model): @@ -692,6 +709,8 @@ class AnswerPaper(models.Model): if question.type == 'code': return self.answers.filter(question=question).order_by('-id') + + def __unicode__(self): u = self.user return u'Question paper for {0} {1}'.format(u.first_name, u.last_name) @@ -719,4 +738,3 @@ class TestCase(models.Model): # Test case Expected answer in list form expected_answer = models.TextField(blank=True, null = True) -################################################################################# -- cgit From 7746a43a84b58b3234553f458e146d7294e8e4f8 Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 3 May 2016 15:10:30 +0530 Subject: modified try statement in grade_user --- yaksh/views.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 587ca57..f6045d8 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -902,21 +902,23 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): (questionpaper_id) context = {"users": user_details, "quiz_id": quiz_id} if user_id is not None: + + attempts = AnswerPaper.objects.get_user_all_attempts\ + (questionpaper_id, user_id) try: - attempts = AnswerPaper.objects.get_user_all_attempts\ - (questionpaper_id, user_id) if attempt_number is None: attempt_number = attempts[0].attempt_number except IndexError: raise Http404('No attempts for paper') - user = User.objects.get(id=user_id) - data = AnswerPaper.objects.get_user_data(user,questionpaper_id, + + user = User.objects.get(id=user_id) + data = AnswerPaper.objects.get_user_data(user, questionpaper_id, attempt_number ) - context = {'data': data,"quiz_id": quiz_id, "users": user_details, - "attempts": attempts,"user_id":user_id - } + context = {'data': data, "quiz_id": quiz_id, "users": user_details, + "attempts": attempts, "user_id": user_id + } if request.method == "POST": papers = data['papers'] for paper in papers: @@ -930,8 +932,10 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): 'comments_%d' % paper.question_paper.id, 'No comments') paper.save() - - return my_render_to_response('yaksh/grade_user.html', context, context_instance=ci) + + return my_render_to_response('yaksh/grade_user.html', + context, context_instance=ci + ) @csrf_exempt -- cgit From aa8b9a89eba24d96d51884b9b7d74a8e916dae10 Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 3 May 2016 15:13:58 +0530 Subject: modified test_set_marks test case method --- yaksh/tests.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'yaksh') diff --git a/yaksh/tests.py b/yaksh/tests.py index 1a5c8ee..d3ff4fc 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -383,6 +383,8 @@ class AnswerPaperTestCases(unittest.TestCase): def test_set_marks (self): self.answer_wrong.set_marks(0.5) self.assertEqual(self.answer_wrong.marks, 0.5) + self.answer_wrong.set_marks(10.0) + self.assertEqual(self.answer_wrong.marks,1.0) ############################################################################### -- cgit From d05e570ea102e517fa43d95d26b9a4cd95d69ba3 Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 3 May 2016 15:16:43 +0530 Subject: modified to make more PEP8 compliant --- yaksh/models.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index f3b8e52..561b334 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -477,11 +477,11 @@ class AnswerPaperManager(models.Manager): def _get_answerpapers_for_quiz(self, questionpaper_id, status=False): if not status: - return self.filter(question_paper_id=questionpaper_id) + return self.filter(question_paper_id=questionpaper_id) else: return self.filter(question_paper_id=questionpaper_id, status="completed") - + def _get_answerpapers_users(self, answerpapers): return answerpapers.values_list('user', flat=True).distinct() @@ -518,15 +518,13 @@ class AnswerPaperManager(models.Manager): return self.filter(question_paper=questionpaper, user=user)\ .order_by('-attempt_number') - def get_user_data(self, user, questionpaper_id, attempt_number = None): - + def get_user_data(self, user, questionpaper_id, attempt_number=None): if attempt_number is not None: - papers = self.filter( user=user, question_paper_id=questionpaper_id, - attempt_number = attempt_number) + papers = self.filter(user=user, question_paper_id=questionpaper_id, + attempt_number=attempt_number) else: papers = self.filter(user=user, question_paper_id=questionpaper_id)\ .order_by("-attempt_number") - data = {} profile = user.profile if hasattr(user, 'profile') else None data['user'] = user @@ -600,7 +598,7 @@ class AnswerPaper(models.Model): def completed_question(self, question_id): """ - Adds the completed question to the list of answered + Adds the completed question to the list of answered questions and returns the next question. """ self.questions_answered.add(question_id) @@ -668,7 +666,7 @@ class AnswerPaper(models.Model): self._update_status(state) self.save() - def set_end_time(self,datetime): + def set_end_time(self, datetime): """ Sets end time """ self.end_time = datetime self.save() @@ -709,8 +707,6 @@ class AnswerPaper(models.Model): if question.type == 'code': return self.answers.filter(question=question).order_by('-id') - - def __unicode__(self): u = self.user return u'Question paper for {0} {1}'.format(u.first_name, u.last_name) -- cgit From 775ca4bf396cabe5b6ff6b4a665ed8d400fabc7c Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 3 May 2016 15:26:57 +0530 Subject: closed div tag --- yaksh/templates/yaksh/grade_user.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'yaksh') diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index d2de194..2c5403c 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -51,7 +51,7 @@ -
    {#not found yet#} +
    {% if data %} @@ -176,8 +176,9 @@ Marks: {% endif %} {#if data#} -
    +
    {% endblock%} -- cgit From a7ef62d72766aff059ae121009cd073a8c5cefc7 Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 3 May 2016 23:57:32 +0530 Subject: importing datetime object from datetime module --- yaksh/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index f6045d8..1cda4ab 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3,7 +3,7 @@ import string import os import stat from os.path import dirname, pardir, abspath, join, exists -import datetime +from datetime import datetime import collections import csv from django.http import HttpResponse -- cgit From 9dd0bc4a93d2a45381d4c6829c272b9d14a95462 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 4 May 2016 00:34:48 +0530 Subject: minor changes in views --- yaksh/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 1cda4ab..9be2c02 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -472,7 +472,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): new_answer.error = result.get('error') new_answer.save() paper.update_marks('inprogress') - paper.update_time(datetime.now()) + paper.set_end_time(datetime.now()) if not result.get('success'): # Should only happen for non-mcq questions. new_answer.answer = user_code new_answer.save() -- cgit From f150f1c54ee5941d72f2e4057af8c90cca588292 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 4 May 2016 16:33:18 +0530 Subject: teachers added to course can grade user --- yaksh/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index 9be2c02..a91da29 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -893,7 +893,8 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None): 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!') - course_details = Course.objects.filter(creator=current_user) + course_details = Course.objects.filter(Q(creator=current_user)| + Q(teachers=current_user)).distinct() context = {"course_details": course_details} if quiz_id is not None: questionpaper_id = QuestionPaper.objects.filter(quiz_id=quiz_id)\ -- cgit