admin.py 3.58 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,
Matheus Miranda's avatar
Matheus Miranda committed
10 11
    ProfessorMessage, CourseAuthor,
    CourseCategory, CourseTrack,
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


Matheus Miranda's avatar
Matheus Miranda committed
39 40 41 42 43 44 45 46
@admin.register(CourseTrack)
class CourseTrackAdmin(admin.ModelAdmin):
    list_display = ('name', 'home_position')
    filter_horizontal = [
        'courses',
    ]


Bruno Martin's avatar
Bruno Martin committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
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
78 79 80 81 82 83
    search_fields = (
        'name',
        'course__name',
        'assistants__first_name',
        'assistants__email',
    )
Bruno Martin's avatar
Bruno Martin committed
84
    list_display = ('name', 'course')
85 86 87 88
    filter_horizontal = (
        'students',
        'assistants',
    )
Bruno Martin's avatar
Bruno Martin committed
89 90 91 92 93 94 95 96 97 98 99 100


@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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121


# 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
122 123 124 125 126 127 128 129


@admin.register(Workspace)
class WorkspaceAdmin(admin.ModelAdmin):
    filter_horizontal = (
        'groups',
        'classes',
    )
130 131 132

@admin.register(ProfessorMessage)
class ProfessorMessageAdmin(admin.ModelAdmin):
133 134 135
    filter_horizontal = (
        'users',
    )
136 137 138 139 140


@admin.register(CourseAuthor)
class CourseAuthorAdmin(admin.ModelAdmin):
    pass
Bruno Martin's avatar
Bruno Martin committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

class EventInline(admin.TabularInline):
    model = Event

@admin.register(Classroom)
class ClassroomAdmin(admin.ModelAdmin):
    filter_horizontal = (
        'assistants',
        'coordinators',
        'access_groups',
    )
    autocomplete_fields = (
        'forum',
        'group',
    )
156
    inlines = (EventInline,)
Bruno Martin's avatar
Bruno Martin committed
157 158 159 160 161
    search_fields = (
        'name',
        'group__name',
        'assistants__name',
    )
Matheus Miranda's avatar
Matheus Miranda committed
162 163

admin.site.register(CourseCategory)