From 9346d388f2ed5c33ace80d98f502906a585ae328 Mon Sep 17 00:00:00 2001 From: Harald Nezbeda Date: Tue, 23 Apr 2024 11:32:52 +0200 Subject: [PATCH] Remove coresponing single tasks from periodic future task chage view --- django_future_tasks/admin.py | 13 ------------- django_future_tasks/fields.py | 7 ++++++- .../0007_alter_periodicfuturetask_cron_string.py | 2 +- django_future_tasks/models.py | 4 ++-- requirements.txt | 2 +- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/django_future_tasks/admin.py b/django_future_tasks/admin.py index 2494082..7a6ddf7 100644 --- a/django_future_tasks/admin.py +++ b/django_future_tasks/admin.py @@ -36,18 +36,6 @@ class Media: css = {"all": ("django_future_tasks/cronfield.css",)} -class FutureTaskInline(admin.TabularInline): - verbose_name = "Corresponding single task" - verbose_name_plural = "Corresponding single tasks" - model = FutureTask - fields = ["task_id", "eta", "status"] - readonly_fields = ["task_id", "eta", "status"] - extra = 0 - classes = ["collapse"] - ordering = ["-eta"] - max_num = 100 - - @admin.register(PeriodicFutureTask) class PeriodicFutureTaskAdmin(admin.ModelAdmin): readonly_fields = [ @@ -62,6 +50,5 @@ class PeriodicFutureTaskAdmin(admin.ModelAdmin): "next_planned_execution", ] list_editable = ["cron_string", "is_active"] - inlines = [FutureTaskInline] list_filter = ["type", "is_active"] form = PeriodicFutureTaskAdminForm diff --git a/django_future_tasks/fields.py b/django_future_tasks/fields.py index 507b3b1..1eab4c6 100644 --- a/django_future_tasks/fields.py +++ b/django_future_tasks/fields.py @@ -23,8 +23,13 @@ def _validate_CRON_string(value): raise ValidationError("Incorrect value {} in column {}".format(c, i + 1)) -class FuturetaskCronField(CronField): +class FutureTaskCronField(CronField): def validate(self, value, model_instance): super(CronField, self).validate(value, model_instance) if self.editable: # Skip validation for non-editable fields. _validate_CRON_string(value) + + def __init__(self, *args, **kwargs): + kwargs["default"] = "* * * * * *" + kwargs["help_text"] = "Minute Hour Day Month Weekday Second" + super().__init__(*args, **kwargs) diff --git a/django_future_tasks/migrations/0007_alter_periodicfuturetask_cron_string.py b/django_future_tasks/migrations/0007_alter_periodicfuturetask_cron_string.py index e65f171..1283b40 100644 --- a/django_future_tasks/migrations/0007_alter_periodicfuturetask_cron_string.py +++ b/django_future_tasks/migrations/0007_alter_periodicfuturetask_cron_string.py @@ -14,7 +14,7 @@ class Migration(migrations.Migration): migrations.AlterField( model_name="periodicfuturetask", name="cron_string", - field=django_future_tasks.fields.FuturetaskCronField( + field=django_future_tasks.fields.FutureTaskCronField( default="* * * * *", help_text="Minute Hour Day Month Weekday", max_length=100, diff --git a/django_future_tasks/models.py b/django_future_tasks/models.py index b467cee..07ce091 100644 --- a/django_future_tasks/models.py +++ b/django_future_tasks/models.py @@ -9,7 +9,7 @@ from django.utils.dateformat import format from django.utils.translation import gettext_lazy as _ -from .fields import FuturetaskCronField +from .fields import FutureTaskCronField class FutureTask(models.Model): @@ -77,7 +77,7 @@ class PeriodicFutureTask(models.Model): blank=True, null=True, ) - cron_string = FuturetaskCronField() + cron_string = FutureTaskCronField() is_active = models.BooleanField(_("Active"), default=True) max_number_of_executions = models.IntegerField( _("Maximal number of executions"), null=True, blank=True diff --git a/requirements.txt b/requirements.txt index 94bd4be..9697fbe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ coverage>=7.2.3,<7.3 pre-commit>=3.2.2,<3.3 # TestApp dependencies -django>=3.2,<4 +django>=4.2,<5 # Cron croniter>=1.4.1,<1.5