Skip to content

Commit

Permalink
Fixes compatibility between django 3.2 and 4.2 for next planned execu…
Browse files Browse the repository at this point in the history
…tion in admin
  • Loading branch information
nezhar committed Jan 15, 2024
1 parent b6a8b42 commit fa61e98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
22 changes: 7 additions & 15 deletions django_future_tasks/models.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import datetime
import uuid

import croniter
from cron_descriptor import (
CasingTypeEnum,
DescriptionTypeEnum,
ExpressionDescriptor,
Options,
)
from cron_descriptor import CasingTypeEnum, ExpressionDescriptor
from cronfield.models import CronField
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import JSONField, Q
from django.utils import timezone
from django.utils.dateformat import format
from django.utils.timezone import utc
from django.utils.translation import gettext_lazy as _


Expand Down Expand Up @@ -97,9 +91,9 @@ class PeriodicFutureTask(models.Model):
)

def next_planned_execution(self):
now = datetime.datetime.now()
next_planned_execution = utc.localize(
croniter.croniter(self.cron_string, now).get_next(datetime.datetime)
now = timezone.now()
next_planned_execution = croniter.croniter(self.cron_string, now).get_next(
timezone.datetime
)
if (
not self.is_active
Expand All @@ -111,15 +105,13 @@ def next_planned_execution(self):
or (
self.end_time is not None
and self.end_time
< utc.localize(
croniter.croniter(self.cron_string, now).get_next(datetime.datetime)
)
< croniter.croniter(self.cron_string, now).get_next(timezone.datetime)
)
):
return None

return format(
next_planned_execution,
timezone.template_localtime(next_planned_execution),
settings.DATETIME_FORMAT,
)

Expand Down
2 changes: 1 addition & 1 deletion tests/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"
TIME_ZONE = "Europe/Vienna"

USE_I18N = True

Expand Down

0 comments on commit fa61e98

Please sign in to comment.