From b2a7f56e07f533d422cbd548a93946190dc2afb4 Mon Sep 17 00:00:00 2001 From: Valentina Khudiakova Date: Tue, 27 Aug 2024 21:21:26 +0100 Subject: [PATCH] Issue 796: remove days of the week from human readable description when the whole week is specified --- django_celery_beat/models.py | 5 ++++- t/unit/test_models.py | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/django_celery_beat/models.py b/django_celery_beat/models.py index 757e4c63..56ed7443 100644 --- a/django_celery_beat/models.py +++ b/django_celery_beat/models.py @@ -325,7 +325,10 @@ def human_readable(self): 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)) + if c.day_of_week and set(c.day_of_week) == set(range(7)): + day_of_week = "*" + else: + day_of_week = cronexp(",".join(map(str, c.day_of_week))) except ValueError: day_of_week = cronexp(self.day_of_week) diff --git a/t/unit/test_models.py b/t/unit/test_models.py index 9fffb909..956b97c7 100644 --- a/t/unit/test_models.py +++ b/t/unit/test_models.py @@ -234,11 +234,16 @@ def test_invalid(self): def test_long_name(self): """Long day name display.""" for day_day_of_week, expected in ( - ("1", "Monday"), - ("mon", "Monday"), - ("Monday,tue", "Monday and Tuesday"), - ("sat-sun/2", "Saturday"), - ("mon-wed", "Monday, Tuesday, and Wednesday"), + ("1", ", only on Monday"), + ("mon", ", only on Monday"), + ("Monday,tue", ", only on Monday and Tuesday"), + ("sat-sun/2", ", only on Saturday"), + ("mon-wed", ", only on Monday, Tuesday, and Wednesday"), + ("*", ""), + ("0-6", ""), + ("2-1", ""), + ("mon-sun", ""), + ("tue-mon", ""), ): cron = CrontabSchedule.objects.create( hour="2", @@ -247,5 +252,7 @@ def test_long_name(self): ) self.assertEqual( - cron.human_readable, f"At 02:00 AM, only on {expected} UTC" + cron.human_readable, + f"At 02:00 AM{expected} UTC", + day_day_of_week, )