Skip to content

Commit

Permalink
Merge pull request #9 from anexia/django-4x-fix
Browse files Browse the repository at this point in the history
Fixes compatibility between django 3.2 and 4.2 for next planned execution in admin
  • Loading branch information
nezhar authored Jan 15, 2024
2 parents b6a8b42 + e7ffa81 commit 08d6a11
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.2]

### Fixed

- Fixes compatibility between django 3.2 and 4.2 for next planned execution in admin

## [1.1.1]

### Fixed

- Use custom css to fix external depenceny upload restriction

## [1.1.0]

### Added
Expand All @@ -16,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial setup.

[Unreleased]: https://github.com/anexia/django-future-tasks/compare/1.0.0...HEAD
[Unreleased]: https://github.com/anexia/django-future-tasks/compare/1.1.2...HEAD
[1.1.2]: https://github.com/anexia/django-future-tasks/releases/tag/1.1.2
[1.1.1]: https://github.com/anexia/django-future-tasks/releases/tag/1.1.1
[1.1.0]: https://github.com/anexia/django-future-tasks/releases/tag/1.1.0
[1.0.0]: https://github.com/anexia/django-future-tasks/releases/tag/1.0.0
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 setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="django-future-tasks",
version=os.getenv("PACKAGE_VERSION", "1.1.0").replace("refs/tags/", ""),
version=os.getenv("PACKAGE_VERSION", "1.1.2").replace("refs/tags/", ""),
packages=find_packages(),
include_package_data=True,
install_requires=[
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 08d6a11

Please sign in to comment.