From 151352ec756a41fedf07b9b0e89bfe4f74cb3133 Mon Sep 17 00:00:00 2001 From: Tekin TOPUZ Date: Mon, 5 Aug 2024 22:22:15 +0300 Subject: [PATCH 1/2] Update models.py validators warning for min and max values for models.DecimalField. --- django_celery_beat/models.py | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/django_celery_beat/models.py b/django_celery_beat/models.py index 6aa02d88..fb8002d1 100644 --- a/django_celery_beat/models.py +++ b/django_celery_beat/models.py @@ -5,7 +5,7 @@ from backports.zoneinfo import available_timezones from datetime import timedelta - +import decimal import timezone_field from celery import current_app, schedules from cron_descriptor import (FormatException, MissingFieldException, @@ -93,13 +93,13 @@ class SolarSchedule(models.Model): max_digits=9, decimal_places=6, verbose_name=_('Latitude'), help_text=_('Run the task when the event happens at this latitude'), - validators=[MinValueValidator(-90), MaxValueValidator(90)], + validators=[MinValueValidator(decimal.Decimal(-90)), MaxValueValidator(decimal.Decimal(90))], ) longitude = models.DecimalField( max_digits=9, decimal_places=6, verbose_name=_('Longitude'), help_text=_('Run the task when the event happens at this longitude'), - validators=[MinValueValidator(-180), MaxValueValidator(180)], + validators=[MinValueValidator(decimal.Decimal(-180)), MaxValueValidator(decimal.Decimal(180))], ) class Meta: @@ -317,22 +317,10 @@ class Meta: @property def human_readable(self): - try: - c = schedules.crontab( - minute=self.minute, - hour=self.hour, - day_of_week=self.day_of_week, - day_of_month=self.day_of_month, - month_of_year=self.month_of_year, - ) - day_of_week = cronexp(",".join(str(day) for day in c.day_of_week)) - except ValueError: - day_of_week = cronexp(self.day_of_week) - cron_expression = '{} {} {} {} {}'.format( cronexp(self.minute), cronexp(self.hour), cronexp(self.day_of_month), cronexp(self.month_of_year), - day_of_week + cronexp(self.day_of_week) ) try: human_readable = get_description(cron_expression) From f814e79f4b2e45905730c6197efaf8eabbb04ae5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 19:22:38 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- django_celery_beat/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django_celery_beat/models.py b/django_celery_beat/models.py index fb8002d1..f702abe5 100644 --- a/django_celery_beat/models.py +++ b/django_celery_beat/models.py @@ -4,8 +4,9 @@ except ImportError: from backports.zoneinfo import available_timezones -from datetime import timedelta import decimal +from datetime import timedelta + import timezone_field from celery import current_app, schedules from cron_descriptor import (FormatException, MissingFieldException,