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 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 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
"""Result Task Admin interface."""
from django.conf import settings
from django.contrib import admin
from django.utils.translation import gettext_lazy as _
try:
ALLOW_EDITS = settings.DJANGO_CELERY_RESULTS['ALLOW_EDITS']
except (AttributeError, KeyError):
ALLOW_EDITS = False
pass
from .models import GroupResult, TaskResult
class TaskResultAdmin(admin.ModelAdmin):
"""Admin-interface for results of tasks."""
model = TaskResult
date_hierarchy = 'date_done'
list_display = ('task_id', 'periodic_task_name', 'task_name', 'date_done',
'status', 'worker')
list_filter = ('status', 'date_done', 'periodic_task_name', 'task_name',
'worker')
readonly_fields = ('date_created', 'date_done', 'result', 'meta')
search_fields = ('task_name', 'task_id', 'status', 'task_args',
'task_kwargs')
fieldsets = (
(None, {
'fields': (
'task_id',
'task_name',
'periodic_task_name',
'status',
'worker',
'content_type',
'content_encoding',
),
'classes': ('extrapretty', 'wide')
}),
(_('Parameters'), {
'fields': (
'task_args',
'task_kwargs',
),
'classes': ('extrapretty', 'wide')
}),
(_('Result'), {
'fields': (
'result',
'date_created',
'date_done',
'traceback',
'meta',
),
'classes': ('extrapretty', 'wide')
}),
)
def get_readonly_fields(self, request, obj=None):
if ALLOW_EDITS:
return self.readonly_fields
else:
return list({
field.name for field in self.opts.local_fields
})
admin.site.register(TaskResult, TaskResultAdmin)
class GroupResultAdmin(admin.ModelAdmin):
"""Admin-interface for results of grouped tasks."""
model = GroupResult
date_hierarchy = 'date_done'
list_display = ('group_id', 'date_done')
list_filter = ('date_done',)
readonly_fields = ('date_created', 'date_done', 'result')
search_fields = ('group_id',)
admin.site.register(GroupResult, GroupResultAdmin)
|