Newer
Older
__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.
"""
Dong Zhuang
committed
from django.utils.translation import (
from course.models import (
Participation, ParticipationPermission,
ParticipationRole, ParticipationRolePermission,
ParticipationPreapproval,
FlowSession, FlowPageData,
FlowPageVisit, FlowPageVisitGrade,
GradingOpportunity, GradeChange, InstantMessage,
Exam, ExamTicket)
from django import forms
from relate.utils import string_concat
from course.enrollment import (approve_enrollment, deny_enrollment)
Andreas Klöckner
committed
from course.constants import (
participation_permission as pperm,
exam_ticket_states
)
from typing import Any, Text, Tuple # noqa
def _filter_courses_for_user(queryset, user):
if user.is_superuser:
return queryset
participations__roles__permissions__permission=pperm.use_admin_interface)
return z
def _filter_course_linked_obj_for_user(queryset, user):
if user.is_superuser:
return queryset
return queryset.filter(
course__participations__user=user,
course__participations__roles__permissions__permission # noqa
=pperm.use_admin_interface
)
def _filter_participation_linked_obj_for_user(queryset, user):
if user.is_superuser:
return queryset
return queryset.filter(
participation__course__participations__user=user,
participation__course__participations__roles__permissions__permission # noqa
Andreas Klöckner
committed
=pperm.use_admin_interface)
# {{{ list filter helper
def _filter_related_only(filter_arg: str) -> Tuple[str, Any]:
return (filter_arg, admin.RelatedOnlyFieldListFilter)
# }}}
class UnsafePasswordInput(forms.TextInput):
# This sends passwords back to the user--not ideal, but OK for the XMPP
# password.
input_type = "password"
class CourseAdminForm(forms.ModelForm):
class Meta:
model = Course
widgets = {
"course_xmpp_password": UnsafePasswordInput
}
exclude = ()
list_display = (
"identifier",
"number",
"name",
"time_period",
"start_date",
"end_date",
"hidden",
"listed",
"accepts_enrollment")
list_editable = (
"number",
"name",
"time_period",
"start_date",
"end_date",
"hidden",
"listed",
"accepts_enrollment")
list_filter = (
"number",
"time_period",
"hidden",
"listed",
"accepts_enrollment")
date_hierarchy = "start_date"
search_fields = (
"identifier",
"number",
"name",
"time_period")
readonly_fields = ("identifier",)
form = CourseAdminForm
# {{{ permissions
def has_add_permission(self, request):
# These are created only through the course creation form.
return False
def get_queryset(self, request):
qs = super().get_queryset(request)
return _filter_courses_for_user(qs, request.user)
list_display = (
"course",
"kind",
"ordinal",
"time",
"end_time",
"shown_in_calendar")
list_filter = (_filter_related_only("course"), "kind", "shown_in_calendar")
date_hierarchy = "time"
search_fields = (
"course__identifier",
"kind",
)
def __unicode__(self): # pragma: no cover # not used
return "{}{} in {}".format(
self.kind,
" (%s)" % str(self.ordinal) if self.ordinal is not None else "",
self.course)
list_editable = ("ordinal", "time", "end_time", "shown_in_calendar")
# {{{ permissions
def get_queryset(self, request):
qs = super().get_queryset(request)
return _filter_course_linked_obj_for_user(qs, request.user)
Loading
Loading full blame...