Skip to content

Commit 8f9fd1b

Browse files
truthdougdougharrispre-commit-ci[bot]auvipy
authored
Adding human readable descriptions of crontab schedules (#622)
* Adding human-readable descriptions of crontab schedules * Adding helpful text to days of week. Updated all .po files with new help string. Added translations for es and de * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Updates to make flake8 happy --------- Co-authored-by: Doug Harris <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Asif Saif Uddin <[email protected]>
1 parent 5680798 commit 8f9fd1b

File tree

17 files changed

+884
-619
lines changed

17 files changed

+884
-619
lines changed

django_celery_beat/admin.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class PeriodicTaskAdmin(admin.ModelAdmin):
123123
'classes': ('extrapretty', 'wide'),
124124
}),
125125
(_('Schedule'), {
126-
'fields': ('interval', 'crontab', 'solar', 'clocked',
127-
'start_time', 'last_run_at', 'one_off'),
126+
'fields': ('interval', 'crontab', 'crontab_translation', 'solar',
127+
'clocked', 'start_time', 'last_run_at', 'one_off'),
128128
'classes': ('extrapretty', 'wide'),
129129
}),
130130
(_('Arguments'), {
@@ -138,9 +138,25 @@ class PeriodicTaskAdmin(admin.ModelAdmin):
138138
}),
139139
)
140140
readonly_fields = (
141-
'last_run_at',
141+
'last_run_at', 'crontab_translation',
142142
)
143143

144+
def crontab_translation(self, obj):
145+
return obj.crontab.human_readable
146+
147+
change_form_template = 'admin/djcelery/change_periodictask_form.html'
148+
149+
def changeform_view(self, request, object_id=None, form_url='',
150+
extra_context=None):
151+
extra_context = extra_context or {}
152+
crontabs = CrontabSchedule.objects.all()
153+
crontab_dict = {}
154+
for crontab in crontabs:
155+
crontab_dict[crontab.id] = crontab.human_readable
156+
extra_context['readable_crontabs'] = crontab_dict
157+
return super().changeform_view(request, object_id,
158+
extra_context=extra_context)
159+
144160
def changelist_view(self, request, extra_context=None):
145161
extra_context = extra_context or {}
146162
scheduler = getattr(settings, 'CELERY_BEAT_SCHEDULER', None)
@@ -247,8 +263,12 @@ class ClockedScheduleAdmin(admin.ModelAdmin):
247263
)
248264

249265

266+
class CrontabScheduleAdmin(admin.ModelAdmin):
267+
list_display = ('__str__', 'human_readable')
268+
269+
250270
admin.site.register(IntervalSchedule)
251-
admin.site.register(CrontabSchedule)
271+
admin.site.register(CrontabSchedule, CrontabScheduleAdmin)
252272
admin.site.register(SolarSchedule)
253273
admin.site.register(ClockedSchedule, ClockedScheduleAdmin)
254274
admin.site.register(PeriodicTask, PeriodicTaskAdmin)
-431 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)