Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 796: remove days of the week from human readable description when the whole week is specified #797

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion django_celery_beat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 13 additions & 6 deletions t/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
)