Skip to content

Commit

Permalink
Remove coresponing single tasks from periodic future task chage view
Browse files Browse the repository at this point in the history
  • Loading branch information
nezhar committed Jul 22, 2024
1 parent edd06fc commit 5dcbe8e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
13 changes: 0 additions & 13 deletions django_future_tasks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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
7 changes: 6 additions & 1 deletion django_future_tasks/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 3.2.24 on 2024-02-29 15:34
# Generated by Django 4.2.14 on 2024-07-22 11:43

from django.db import migrations

Expand All @@ -14,9 +14,9 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="periodicfuturetask",
name="cron_string",
field=django_future_tasks.fields.FuturetaskCronField(
default="* * * * *",
help_text="Minute Hour Day Month Weekday",
field=django_future_tasks.fields.FutureTaskCronField(
default="* * * * * *",
help_text="Minute Hour Day Month Weekday Second",
max_length=100,
),
),
Expand Down
4 changes: 2 additions & 2 deletions django_future_tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5dcbe8e

Please sign in to comment.