-
Notifications
You must be signed in to change notification settings - Fork 13
/
admin.py
36 lines (29 loc) · 1.18 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import annotations
from django.contrib import admin, messages
from django.utils.translation import ngettext
from dandiapi.zarr.models import ZarrArchive
from dandiapi.zarr.tasks import ingest_zarr_archive
@admin.register(ZarrArchive)
class ZarrArchiveAdmin(admin.ModelAdmin):
search_fields = ['zarr_id', 'name']
list_display = ['id', 'zarr_id', 'name', 'dandiset', 'public']
list_display_links = ['id', 'zarr_id', 'name']
actions = ('ingest_zarr_archive',)
@admin.display(boolean=True, description='Public Access', ordering='embargoed')
def public(self, obj: ZarrArchive):
return not obj.embargoed
@admin.action(description='Ingest selected zarr archives')
def ingest_zarr_archive(self, request, queryset):
for zarr in queryset:
ingest_zarr_archive.delay(zarr_id=(str(zarr.zarr_id)), force=True)
# Return message
self.message_user(
request,
ngettext(
'%d zarr archive has begun ingesting.',
'%d zarr archives have begun ingesting.',
queryset.count(),
)
% queryset.count(),
messages.SUCCESS,
)