-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.py
executable file
·64 lines (45 loc) · 2.08 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
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
from django_celery_beat.models import PeriodicTask, IntervalSchedule, CrontabSchedule, SolarSchedule, ClockedSchedule
from django_celery_results.admin import TaskResult, GroupResult, TaskResultAdmin, GroupResultAdmin
import unfold
from django.contrib import admin
from django_superapp.helpers import SuperAppModelAdmin
from django_superapp.sites import superapp_admin_site
from unfold.decorators import action
from django.shortcuts import redirect
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from superapp.apps.tasks.management.commands.truncate_all_tasks import drop_all_tasks
# Celery Tasks
@admin.register(TaskResult, site=superapp_admin_site)
class BasePortalTaskResultAdmin(TaskResultAdmin, SuperAppModelAdmin):
actions_list = [
"drop_all_tasks_action",
]
list_display = ('task_id', 'periodic_task_name', 'task_name', 'date_created', 'date_done',
'status', 'worker')
date_hierarchy = 'date_created'
ordering = ('-date_created',)
@unfold.decorators.action(description=_("Drop all tasks"))
def drop_all_tasks_action(self, request):
drop_all_tasks()
self.message_user(request, f"Dropped all tasks.")
return redirect(reverse_lazy("admin:django_celery_results_taskresult_changelist"))
@admin.register(GroupResult, site=superapp_admin_site)
class BasePortalResultAdmin(GroupResultAdmin, SuperAppModelAdmin):
pass
# Celery Beat
@admin.register(PeriodicTask, site=superapp_admin_site)
class PeriodicTaskAdminBase(SuperAppModelAdmin):
pass
@admin.register(IntervalSchedule, site=superapp_admin_site)
class IntervalScheduleAdminBase(SuperAppModelAdmin):
pass
@admin.register(CrontabSchedule, site=superapp_admin_site)
class CrontabScheduleAdminBase(SuperAppModelAdmin):
pass
@admin.register(SolarSchedule, site=superapp_admin_site)
class SolarScheduleAdminBase(SuperAppModelAdmin):
pass
@admin.register(ClockedSchedule, site=superapp_admin_site)
class ClockedScheduleAdminBase(SuperAppModelAdmin):
pass