Skip to content
admin.py 4.76 KiB
Newer Older
Andreas Klöckner's avatar
Andreas Klöckner committed
from django.contrib import admin
from course.models import (
        UserStatus,
        Course, TimeMark,
        Participation, InstantFlowRequest,
        FlowVisit, FlowPageData, FlowPageVisit,
        FlowAccessException, FlowAccessExceptionEntry,
        GradingOpportunity, GradeChange)


# {{{ user status

class UserStatusAdmin(admin.ModelAdmin):
    list_display = ("user", "status", "key_time")
    list_filter = ("status",)

    date_hierarchy = "key_time"

    def __unicode__(self):
        return u"%s in status %s" % (self.user, self.status)

admin.site.register(UserStatus, UserStatusAdmin)

# }}}
Andreas Klöckner's avatar
Andreas Klöckner committed


class CourseAdmin(admin.ModelAdmin):
    pass

admin.site.register(Course, CourseAdmin)


# {{{ time marks

class TimeMarkAdmin(admin.ModelAdmin):
    list_display = ["course", "kind", "ordinal", "time"]
    list_filter = ["course", "kind"]

    date_hierarchy = "time"

    def __unicode__(self):
        return u"%s %d in %s" % (self.kind, self.ordinal, self.course)

admin.site.register(TimeMark, TimeMarkAdmin)

# }}}


# {{{ participation

Andreas Klöckner's avatar
Andreas Klöckner committed
class ParticipationAdmin(admin.ModelAdmin):
Andreas Klöckner's avatar
Andreas Klöckner committed
    list_display = ["user", "course", "role", "status", "enroll_time"]
    list_filter = ["course", "role", "status"]
Andreas Klöckner's avatar
Andreas Klöckner committed

admin.site.register(Participation, ParticipationAdmin)

Andreas Klöckner's avatar
Andreas Klöckner committed

class InstantFlowRequestAdmin(admin.ModelAdmin):
    pass

admin.site.register(InstantFlowRequest, InstantFlowRequestAdmin)


class FlowPageDataInline(admin.TabularInline):
    model = FlowPageData
    extra = 0
Andreas Klöckner's avatar
Andreas Klöckner committed

class FlowVisitAdmin(admin.ModelAdmin):
    def get_course(self, obj):
        return obj.participation.course
    get_course.short_description = "Course"
    get_course.admin_order_field = "participation__course"
    def get_participant(self, obj):
        return obj.participation.user
    get_participant.short_description = "Participant"
    get_participant.admin_order_field = "participation__user"

    list_display = (
            "flow_id",
            "get_participant",
            "get_course",
            "start_time",
            "state",
            )
    list_display_links = (
            "flow_id",
            "get_participant",
            )

    date_hierarchy = "start_time"

    list_filter = (
            "participation__course",
            "flow_id",
            "state",
            )

    inlines = (FlowPageDataInline,)

admin.site.register(FlowVisit, FlowVisitAdmin)


# }}}


# {{{ flow access

class FlowAccessExceptionEntryInline(admin.StackedInline):
    model = FlowAccessExceptionEntry
    extra = 2


class FlowAccessExceptionAdmin(admin.ModelAdmin):
    inlines = (FlowAccessExceptionEntryInline,)

    def get_course(self, obj):
        return obj.participation.course
    get_course.short_description = "Course"
    get_course.admin_order_field = "participation__course"

    def get_participant(self, obj):
        return obj.participation.user
    get_participant.short_description = "Participant"
    get_participant.admin_order_field = "participation__user"

    list_display = (
            "get_participant",
            "get_course",
            "flow_id",
            "expiration",
            "creation_time",
            )
    list_display_links = (
            "get_participant",
            "flow_id",
            )
    list_filter = (
            "participation__course",
            "flow_id",
            )

    date_hierarchy = "creation_time"


admin.site.register(FlowAccessException, FlowAccessExceptionAdmin)

# }}}


# {{{ grading

class GradingOpportunityAdmin(admin.ModelAdmin):
    list_display = ("course",  "name", "due_time", "identifier",)
    list_filter = ("course",)

admin.site.register(GradingOpportunity, GradingOpportunityAdmin)


class GradeChangeAdmin(admin.ModelAdmin):
    def get_course(self, obj):
        return obj.participation.course
    get_course.short_description = "Course"
    get_course.admin_order_field = "participation__course"

    def get_opportunity(self, obj):
        return obj.opportunity.name
    get_course.short_description = "Opportunity"
    get_course.admin_order_field = "opportunity"

    def get_participant(self, obj):
        return obj.participation.user
    get_participant.short_description = "Participant"
    get_participant.admin_order_field = "participation__user"

    list_display = (
            "get_opportunity",
            "get_participant",
            "get_course",
            "state",
            "points",
            "grade_time",
            )
    list_display_links = (
            "get_opportunity",
            "get_participant",
            )
    date_hierarchy = "grade_time"

    list_filter = (
            "opportunity__course",
            "opportunity",
            "participation",
            "state",
            )

admin.site.register(GradeChange, GradeChangeAdmin)

# }}}

# vim: foldmethod=marker