admin.py 3.12 KB
Newer Older
1
from funkwhale_api.common import admin
2
3
4

from . import models

5

6
7
@admin.register(models.Artist)
class ArtistAdmin(admin.ModelAdmin):
Eliot Berriot's avatar
Eliot Berriot committed
8
9
    list_display = ["name", "mbid", "creation_date"]
    search_fields = ["name", "mbid"]
10

11

12
13
@admin.register(models.Album)
class AlbumAdmin(admin.ModelAdmin):
Eliot Berriot's avatar
Eliot Berriot committed
14
15
    list_display = ["title", "artist", "mbid", "release_date", "creation_date"]
    search_fields = ["title", "artist__name", "mbid"]
16
17
    list_select_related = True

18

19
20
@admin.register(models.Track)
class TrackAdmin(admin.ModelAdmin):
Eliot Berriot's avatar
Eliot Berriot committed
21
22
    list_display = ["title", "artist", "album", "mbid"]
    search_fields = ["title", "artist__name", "album__title", "mbid"]
23
24
    list_select_related = True

25

26
27
@admin.register(models.ImportBatch)
class ImportBatchAdmin(admin.ModelAdmin):
Eliot Berriot's avatar
Eliot Berriot committed
28
29
30
31
    list_display = ["submitted_by", "creation_date", "import_request", "status"]
    list_select_related = ["submitted_by", "import_request"]
    list_filter = ["status"]
    search_fields = ["import_request__name", "source", "batch__pk", "mbid"]
32

33

34
35
@admin.register(models.ImportJob)
class ImportJobAdmin(admin.ModelAdmin):
Eliot Berriot's avatar
Eliot Berriot committed
36
37
    list_display = ["source", "batch", "upload", "status", "mbid"]
    list_select_related = ["upload", "batch"]
Eliot Berriot's avatar
Eliot Berriot committed
38
39
    search_fields = ["source", "batch__pk", "mbid"]
    list_filter = ["status"]
40
41
42
43


@admin.register(models.Work)
class WorkAdmin(admin.ModelAdmin):
Eliot Berriot's avatar
Eliot Berriot committed
44
    list_display = ["title", "mbid", "language", "nature"]
45
    list_select_related = True
Eliot Berriot's avatar
Eliot Berriot committed
46
47
    search_fields = ["title"]
    list_filter = ["language", "nature"]
48
49
50
51


@admin.register(models.Lyrics)
class LyricsAdmin(admin.ModelAdmin):
Eliot Berriot's avatar
Eliot Berriot committed
52
    list_display = ["url", "id", "url"]
53
    list_select_related = True
Eliot Berriot's avatar
Eliot Berriot committed
54
55
    search_fields = ["url", "work__title"]
    list_filter = ["work__language"]
56
57


Eliot Berriot's avatar
Eliot Berriot committed
58
59
@admin.register(models.Upload)
class UploadAdmin(admin.ModelAdmin):
60
    list_display = [
Eliot Berriot's avatar
Eliot Berriot committed
61
62
63
64
65
66
67
        "track",
        "audio_file",
        "source",
        "duration",
        "mimetype",
        "size",
        "bitrate",
68
        "import_status",
69
    ]
Eliot Berriot's avatar
Eliot Berriot committed
70
    list_select_related = ["track"]
71
    search_fields = [
Eliot Berriot's avatar
Eliot Berriot committed
72
73
74
75
76
77
        "source",
        "acoustid_track_id",
        "track__title",
        "track__album__title",
        "track__artist__name",
    ]
78
79
80
    list_filter = ["mimetype", "import_status", "library__privacy_level"]


Eliot Berriot's avatar
Eliot Berriot committed
81
82
83
84
85
86
87
88
def launch_scan(modeladmin, request, queryset):
    for library in queryset:
        library.schedule_scan(actor=request.user.actor, force=True)


launch_scan.short_description = "Launch scan"


89
90
91
92
93
94
@admin.register(models.Library)
class LibraryAdmin(admin.ModelAdmin):
    list_display = ["id", "name", "actor", "uuid", "privacy_level", "creation_date"]
    list_select_related = True
    search_fields = ["actor__username", "name", "description"]
    list_filter = ["privacy_level"]
Eliot Berriot's avatar
Eliot Berriot committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
    actions = [launch_scan]


@admin.register(models.LibraryScan)
class LibraryScanAdmin(admin.ModelAdmin):
    list_display = [
        "id",
        "library",
        "actor",
        "status",
        "creation_date",
        "modification_date",
        "status",
        "total_files",
        "processed_files",
        "errored_files",
    ]
    list_select_related = True
    search_fields = ["actor__username", "library__name"]
    list_filter = ["status"]