Newer
Older
# -*- coding: utf-8 -*-
from __future__ import division
__copyright__ = "Copyright (C) 2014 Andreas Kloeckner"
__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
from django.utils.translation import (
ugettext_lazy as _, pgettext_lazy, ugettext, string_concat)
from django.contrib import messages # noqa
from django.core.exceptions import (
PermissionDenied, SuspiciousOperation, ObjectDoesNotExist)
from django.db import connection
from django import forms
from django.db import transaction
from django.urls import reverse
Andreas Klöckner
committed
from relate.utils import StyledForm, StyledModelForm
from crispy_forms.layout import Submit
Andreas Klöckner
committed
from bootstrap3_datetime.widgets import DateTimePicker
from course.utils import course_view, render_course_page
Andreas Klöckner
committed
Participation, participation_status,
GradingOpportunity, GradeChange, GradeStateMachine,
Andreas Klöckner
committed
from course.flow import adjust_flow_session_page_data
from course.views import get_now_or_fake_time
Andreas Klöckner
committed
from course.constants import (
participation_permission as pperm,
)
from typing import cast, Tuple, Text, Optional, Any, Iterable, List # noqa
from course.utils import CoursePageContext # noqa
from course.content import FlowDesc # noqa
from course.models import Course, FlowPageVisitGrade # noqa
# }}}
# {{{ student grade book
@course_view
def view_participant_grades(pctx, participation_id=None):
raise PermissionDenied(_("must be enrolled to view grades"))
if participation_id is not None:
grade_participation = Participation.objects.get(id=int(participation_id))
else:
grade_participation = pctx.participation
Andreas Klöckner
committed
is_privileged_view = pctx.has_permission(pperm.view_gradebook)
Andreas Klöckner
committed
if grade_participation != pctx.participation:
Andreas Klöckner
committed
raise PermissionDenied(_("may not view other people's grades"))
# NOTE: It's important that these two queries are sorted consistently,
# also consistently with the code below.
grading_opps = list((GradingOpportunity.objects
.filter(
course=pctx.course,
shown_in_grade_book=True,
)
.order_by("identifier")))
grade_changes = list(GradeChange.objects
.filter(
opportunity__course=pctx.course,
opportunity__shown_in_grade_book=True)
.order_by(
"participation__id",
.select_related("participation")
.select_related("participation__user")
.select_related("opportunity"))
idx = 0
grade_table = []
for opp in grading_opps:
Andreas Klöckner
committed
if not is_privileged_view:
if not (opp.shown_in_grade_book
Andreas Klöckner
committed
and opp.shown_in_participant_grade_book):
continue
else:
if not opp.shown_in_grade_book:
continue
while (
idx < len(grade_changes)
and grade_changes[idx].opportunity.identifier < opp.identifier
):
idx += 1
my_grade_changes = []
while (
idx < len(grade_changes)
and grade_changes[idx].opportunity.pk == opp.pk):
my_grade_changes.append(grade_changes[idx])
idx += 1
state_machine = GradeStateMachine()
state_machine.consume(my_grade_changes)
grade_table.append(
GradeInfo(
opportunity=opp,
grade_state_machine=state_machine))
return render_course_page(pctx, "course/gradebook-participant.html", {
"grade_table": grade_table,
"grade_participation": grade_participation,
"grading_opportunities": grading_opps,
"grade_state_change_types": grade_state_change_types,
Andreas Klöckner
committed
"is_privileged_view": is_privileged_view,
# {{{ participant list
@course_view
def view_participant_list(pctx):
Andreas Klöckner
committed
if not pctx.has_permission(pperm.view_gradebook):
raise PermissionDenied(_("may not view grade book"))
participations = list(Participation.objects
.filter(
.order_by("id")
.select_related("user"))
return render_course_page(pctx, "course/gradebook-participant-list.html", {
"participations": participations,
})
# }}}
# {{{ grading opportunity list
@course_view
def view_grading_opportunity_list(pctx):
Andreas Klöckner
committed
if not pctx.has_permission(pperm.view_gradebook):
raise PermissionDenied(_("may not view grade book"))
grading_opps = list((GradingOpportunity.objects
.filter(
course=pctx.course,
)
.order_by("identifier")))
return render_course_page(pctx, "course/gradebook-opp-list.html", {
"grading_opps": grading_opps,
})
# }}}
class GradeInfo:
def __init__(self, opportunity, grade_state_machine):
# type: (GradingOpportunity, GradeStateMachine) -> None
self.opportunity = opportunity
self.grade_state_machine = grade_state_machine
Loading
Loading full blame...