admin.py 3.35 KB
Newer Older
Bruno Martin's avatar
Bruno Martin committed
1 2 3 4 5 6 7 8 9
from django.contrib import admin
from django.forms import Textarea
from django.db import models
# from ..activities.admin import ModelAdmin

from .videos.models import Video
from .models import (
    Course, Lesson, Unit, CourseProfessor, CourseStudent,
    StudentProgress, Class,
10
    ProfessorMessage,
11
    CourseAuthor,
Bruno Martin's avatar
Bruno Martin committed
12
)
Bruno Martin's avatar
Bruno Martin committed
13
from .course_material.models import CourseMaterial, File
Bruno Martin's avatar
Bruno Martin committed
14

Bruno Martin's avatar
Bruno Martin committed
15 16
from .workspaces.models import Workspace

Bruno Martin's avatar
Bruno Martin committed
17 18
from .classroom.models import Classroom, Event

Bruno Martin's avatar
Bruno Martin committed
19 20 21 22 23 24 25 26 27 28 29 30

class LessonInline(admin.TabularInline):
    model = Lesson
    formfield_overrides = {
        models.CharField: {'widget': Textarea(attrs={'rows': 3, 'class': 'span11'})},
    }


@admin.register(Course)
class CourseAdmin(admin.ModelAdmin):
    list_display = ('name', 'status', 'start_date',)
    inlines = (LessonInline,)
31 32 33
    filter_horizontal = [
        'groups',
    ]
Bruno Martin's avatar
Bruno Martin committed
34 35 36
    autocomplete_fields = [
        'forum',
    ]
Bruno Martin's avatar
Bruno Martin committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69


class UnitInline(admin.TabularInline):
    model = Unit
    fields = ('title', 'video', 'position',)


@admin.register(Lesson)
class LessonAdmin(admin.ModelAdmin):
    list_display = ('name', 'course',)
    search_fields = ('course__name',)
    inlines = (UnitInline,)


@admin.register(Unit)
class UnitAdmin(admin.ModelAdmin):
    search_fields = ('title', 'lesson__name')
    list_display = ('title', 'position', 'lesson', 'video',)
    list_select_related = ('lesson', 'video')


@admin.register(CourseProfessor)
class CourseProfessorAdmin(admin.ModelAdmin):
    list_display = ('user', 'course',)


@admin.register(Video)
class VideoAdmin(admin.ModelAdmin):
    pass


@admin.register(Class)
class ClassAdmin(admin.ModelAdmin):
Bruno Martin's avatar
Bruno Martin committed
70 71 72 73 74 75
    search_fields = (
        'name',
        'course__name',
        'assistants__first_name',
        'assistants__email',
    )
Bruno Martin's avatar
Bruno Martin committed
76
    list_display = ('name', 'course')
77 78 79 80
    filter_horizontal = (
        'students',
        'assistants',
    )
Bruno Martin's avatar
Bruno Martin committed
81 82 83 84 85 86 87 88 89 90 91 92


@admin.register(StudentProgress)
class StudentProgressAdmin(admin.ModelAdmin):
    search_fields = ('user__username', 'user__email', )
    list_display = ('user', 'unit', 'complete', 'last_access')


@admin.register(CourseStudent)
class CourseStudentAdmin(admin.ModelAdmin):
    search_fields = ('user__username',)
    list_display = ('user', 'course')
Bruno Martin's avatar
Bruno Martin committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113


# Course Materials admins
class FileInline(admin.TabularInline):
    model = File
    extra = 1


@admin.register(CourseMaterial)
class CourseMaterialAdmin(admin.ModelAdmin):
    search_fields = ('text',)
    list_display = ('course', 'text')
    inlines = [
        FileInline,
    ]


@admin.register(File)
class FileAdmin(admin.ModelAdmin):
    search_fields = ('file',)
    list_display = ('file', 'course_material')
Bruno Martin's avatar
Bruno Martin committed
114 115 116 117 118 119 120 121


@admin.register(Workspace)
class WorkspaceAdmin(admin.ModelAdmin):
    filter_horizontal = (
        'groups',
        'classes',
    )
122 123 124

@admin.register(ProfessorMessage)
class ProfessorMessageAdmin(admin.ModelAdmin):
125 126 127
    filter_horizontal = (
        'users',
    )
128 129 130 131 132


@admin.register(CourseAuthor)
class CourseAuthorAdmin(admin.ModelAdmin):
    pass
Bruno Martin's avatar
Bruno Martin committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

class EventInline(admin.TabularInline):
    model = Event

@admin.register(Classroom)
class ClassroomAdmin(admin.ModelAdmin):
    filter_horizontal = (
        'assistants',
        'coordinators',
        'access_groups',
    )
    autocomplete_fields = (
        'forum',
        'group',
    )
148
    inlines = (EventInline,)
Bruno Martin's avatar
Bruno Martin committed
149 150 151 152 153
    search_fields = (
        'name',
        'group__name',
        'assistants__name',
    )