Skip to content

Commit

Permalink
Remove code for unsupported django.VERSION < (3, 2) (#729)
Browse files Browse the repository at this point in the history
* Remove code for unsupported django.VERSION < (3, 2)

* pre-commit: Add django-upgrade

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
cclauss and pre-commit-ci[bot] committed Feb 18, 2024
1 parent acd10a3 commit ee3b500
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ repos:
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/adamchainz/django-upgrade
rev: 1.16.0
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]
5 changes: 0 additions & 5 deletions django_celery_beat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import re
from collections import namedtuple

import django

__version__ = '2.5.0'
__author__ = 'Asif Saif Uddin, Ask Solem'
__contact__ = 'auvipy@gmail.com, ask@celeryproject.org'
Expand All @@ -29,6 +27,3 @@
del re

__all__ = []

if django.VERSION < (3, 2):
default_app_config = 'django_celery_beat.apps.BeatConfig'
22 changes: 15 additions & 7 deletions django_celery_beat/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def clean_kwargs(self):
return self._clean_json('kwargs')


@admin.register(PeriodicTask)
class PeriodicTaskAdmin(admin.ModelAdmin):
"""Admin-interface for periodic tasks."""

Expand Down Expand Up @@ -184,30 +185,39 @@ def _message_user_about_update(self, request, rows_updated, verb):
),
)

@admin.action(
description=_('Enable selected tasks')
)
def enable_tasks(self, request, queryset):
rows_updated = queryset.update(enabled=True)
PeriodicTasks.update_changed()
self._message_user_about_update(request, rows_updated, 'enabled')
enable_tasks.short_description = _('Enable selected tasks')

@admin.action(
description=_('Disable selected tasks')
)
def disable_tasks(self, request, queryset):
rows_updated = queryset.update(enabled=False, last_run_at=None)
PeriodicTasks.update_changed()
self._message_user_about_update(request, rows_updated, 'disabled')
disable_tasks.short_description = _('Disable selected tasks')

def _toggle_tasks_activity(self, queryset):
return queryset.update(enabled=Case(
When(enabled=True, then=Value(False)),
default=Value(True),
))

@admin.action(
description=_('Toggle activity of selected tasks')
)
def toggle_tasks(self, request, queryset):
rows_updated = self._toggle_tasks_activity(queryset)
PeriodicTasks.update_changed()
self._message_user_about_update(request, rows_updated, 'toggled')
toggle_tasks.short_description = _('Toggle activity of selected tasks')

@admin.action(
description=_('Run selected tasks')
)
def run_tasks(self, request, queryset):
self.celery_app.loader.import_default_modules()
tasks = [(self.celery_app.tasks.get(task.task),
Expand Down Expand Up @@ -249,9 +259,9 @@ def run_tasks(self, request, queryset):
pluralize(tasks_run, _('was,were')),
),
)
run_tasks.short_description = _('Run selected tasks')


@admin.register(ClockedSchedule)
class ClockedScheduleAdmin(admin.ModelAdmin):
"""Admin-interface for clocked schedules."""

Expand All @@ -263,14 +273,12 @@ class ClockedScheduleAdmin(admin.ModelAdmin):
)


@admin.register(CrontabSchedule)
class CrontabScheduleAdmin(admin.ModelAdmin):
"""Admin class for CrontabSchedule."""

list_display = ('__str__', 'human_readable')


admin.site.register(IntervalSchedule)
admin.site.register(CrontabSchedule, CrontabScheduleAdmin)
admin.site.register(SolarSchedule)
admin.site.register(ClockedSchedule, ClockedScheduleAdmin)
admin.site.register(PeriodicTask, PeriodicTaskAdmin)

0 comments on commit ee3b500

Please sign in to comment.