Skip to content

Commit 8444a51

Browse files
committed
black
1 parent 8cd41d8 commit 8444a51

File tree

2 files changed

+29
-147
lines changed

2 files changed

+29
-147
lines changed

scheduler/admin/task_admin.py

Lines changed: 29 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -20,129 +20,18 @@ class Media:
2020
class JobArgInline(HiddenMixin, GenericStackedInline):
2121
model = TaskArg
2222
extra = 0
23-
fieldsets = (
24-
(
25-
None,
26-
{
27-
"fields": (
28-
(
29-
"arg_type",
30-
"val",
31-
),
32-
),
33-
},
34-
),
35-
)
23+
fieldsets = ((None, dict(fields=("arg_type", "val"))),)
3624

3725

3826
class JobKwargInline(HiddenMixin, GenericStackedInline):
3927
model = TaskKwarg
4028
extra = 0
41-
fieldsets = (
42-
(
43-
None,
44-
{
45-
"fields": (
46-
("key",),
47-
(
48-
"arg_type",
49-
"val",
50-
),
51-
),
52-
},
53-
),
54-
)
55-
56-
57-
_LIST_DISPLAY_EXTRA = dict(
58-
CronTask=(
59-
"cron_string",
60-
"next_run",
61-
"successful_runs",
62-
"last_successful_run",
63-
"failed_runs",
64-
"last_failed_run",
65-
),
66-
ScheduledTask=("scheduled_time",),
67-
RepeatableTask=(
68-
"scheduled_time",
69-
"interval_display",
70-
"successful_runs",
71-
"last_successful_run",
72-
"failed_runs",
73-
"last_failed_run",
74-
),
75-
Task=(
76-
"scheduled_time",
77-
"interval_display",
78-
"cron_string",
79-
"next_run",
80-
"successful_runs",
81-
"last_successful_run",
82-
"failed_runs",
83-
"last_failed_run",
84-
),
85-
)
86-
_FIELDSET_EXTRA = dict(
87-
CronTask=(
88-
"cron_string",
89-
"timeout",
90-
"result_ttl",
91-
(
92-
"successful_runs",
93-
"last_successful_run",
94-
),
95-
(
96-
"failed_runs",
97-
"last_failed_run",
98-
),
99-
),
100-
ScheduledTask=("scheduled_time", "timeout", "result_ttl"),
101-
RepeatableTask=(
102-
"scheduled_time",
103-
(
104-
"interval",
105-
"interval_unit",
106-
),
107-
"repeat",
108-
"timeout",
109-
"result_ttl",
110-
(
111-
"successful_runs",
112-
"last_successful_run",
113-
),
114-
(
115-
"failed_runs",
116-
"last_failed_run",
117-
),
118-
),
119-
Task=(
120-
"scheduled_time",
121-
"cron_string",
122-
(
123-
"interval",
124-
"interval_unit",
125-
),
126-
"repeat",
127-
"timeout",
128-
"result_ttl",
129-
(
130-
"successful_runs",
131-
"last_successful_run",
132-
),
133-
(
134-
"failed_runs",
135-
"last_failed_run",
136-
),
137-
),
138-
)
29+
fieldsets = ((None, dict(fields=("key", ("arg_type", "val")))),)
13930

14031

14132
@admin.register(Task)
14233
class TaskAdmin(admin.ModelAdmin):
143-
"""TaskAdmin admin view for all task models.
144-
Using the _LIST_DISPLAY_EXTRA and _FIELDSET_EXTRA additional data for each model.
145-
"""
34+
"""TaskAdmin admin view for all task models."""
14635

14736
save_on_top = True
14837
change_form_template = "admin/scheduler/change_form.html"
@@ -163,49 +52,44 @@ class TaskAdmin(admin.ModelAdmin):
16352
"function_string",
16453
"is_scheduled",
16554
"queue",
55+
"scheduled_time",
56+
"interval_display",
57+
"cron_string",
58+
"next_run",
59+
"successful_runs",
60+
"last_successful_run",
61+
"failed_runs",
62+
"last_failed_run",
16663
)
16764
list_display_links = ("name",)
168-
readonly_fields = ("job_id",)
65+
readonly_fields = (
66+
"job_id",
67+
"successful_runs",
68+
"last_successful_run",
69+
"failed_runs",
70+
"last_failed_run",
71+
)
72+
radio_fields = {"task_type": admin.HORIZONTAL}
16973
fieldsets = (
17074
(
17175
None,
172-
{
173-
"fields": (
76+
dict(
77+
fields=(
17478
"name",
17579
"callable",
176-
"enabled",
177-
"at_front",
178-
),
179-
},
80+
"task_type",
81+
("enabled", "timeout", "result_ttl"),
82+
("scheduled_time", "cron_string", "interval", "interval_unit", "repeat"),
83+
)
84+
),
18085
),
86+
(_("RQ Settings"), dict(fields=(("queue", "at_front"), "job_id"))),
18187
(
182-
_("RQ Settings"),
183-
{
184-
"fields": (
185-
"queue",
186-
"job_id",
187-
),
188-
},
88+
_("Previous runs info"),
89+
dict(fields=(("successful_runs", "last_successful_run"), ("failed_runs", "last_failed_run"))),
18990
),
19091
)
19192

192-
def get_list_display(self, request):
193-
if self.model.__name__ not in _LIST_DISPLAY_EXTRA:
194-
raise ValueError(f"Unrecognized model {self.model}")
195-
return TaskAdmin.list_display + _LIST_DISPLAY_EXTRA[self.model.__name__]
196-
197-
def get_fieldsets(self, request, obj=None):
198-
if self.model.__name__ not in _FIELDSET_EXTRA:
199-
raise ValueError(f"Unrecognized model {self.model}")
200-
return TaskAdmin.fieldsets + (
201-
(
202-
_("Scheduling"),
203-
{
204-
"fields": _FIELDSET_EXTRA[self.model.__name__],
205-
},
206-
),
207-
)
208-
20993
@admin.display(description="Next run")
21094
def next_run(self, o: Task):
21195
return tools.get_next_cron_time(o.cron_string)

scheduler/models/task.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ class TimeUnits(models.TextChoices):
9898
at_front = models.BooleanField(
9999
_("At front"),
100100
default=False,
101-
blank=True,
102-
null=True,
103101
help_text=_("When queuing the job, add it in the front of the queue"),
104102
)
105103
timeout = models.IntegerField(

0 commit comments

Comments
 (0)