Newer
Older
from __future__ import annotations
__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.
"""
TYPE_CHECKING,
Any,
List,
Optional,
Tuple,
cast,
from crispy_forms.layout import Submit
from django import forms, http
from django.core.exceptions import (
ObjectDoesNotExist,
PermissionDenied,
SuspiciousOperation,
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils.timezone import now
from django.utils.translation import gettext, gettext_lazy as _, pgettext_lazy
from course.constants import participation_permission as pperm
Andreas Klöckner
committed
from course.flow import adjust_flow_session_page_data
FlowPageVisit,
FlowSession,
GradeChange,
GradeStateMachine,
GradingOpportunity,
Participation,
grade_state_change_types,
participation_status,
)
from course.utils import course_view, render_course_page
from course.views import get_now_or_fake_time
HTML5DateTimeInput,
StyledForm,
StyledModelForm,
string_concat,
if TYPE_CHECKING:
from course.content import FlowDesc
from course.models import Course, FlowPageVisitGrade
from course.utils import CoursePageContext
# {{{ 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.
gopp_extra_filter_kwargs = {}
if not is_privileged_view:
gopp_extra_filter_kwargs = {"shown_in_participant_grade_book": True}
grading_opps = list(GradingOpportunity.objects
.filter(
course=pctx.course,
shown_in_grade_book=True,
.order_by("identifier"))
grade_changes = list(GradeChange.objects
.filter(
opportunity__pk__in=[gopp.pk for gopp in grading_opps],
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
Loading
Loading full blame...