manager: prevent emtpy first row in monthly view (#38700)

It could occur when weekend was hidden.
This commit is contained in:
Valentin Deniaud 2019-12-24 12:16:16 +01:00
parent ba94214d55
commit d63a039bf2
3 changed files with 18 additions and 1 deletions

View File

@ -411,6 +411,10 @@ class AgendaMonthView(AgendaDateView, MonthArchiveView):
hide_sunday = not timeperiods.filter(weekday=6).exists()
hide_weekend = hide_sunday and not timeperiods.filter(weekday=5).exists()
# avoid displaying empty first week
first_week_offset = int(
(hide_sunday and self.date.weekday() == 6) or (hide_weekend and self.date.weekday() == 5)
)
first_week_number = self.date.isocalendar()[1]
last_month_day = self.get_next_month(self.date.date()) - datetime.timedelta(days=1)
@ -419,7 +423,7 @@ class AgendaMonthView(AgendaDateView, MonthArchiveView):
if last_week_number < first_week_number: # new year
last_week_number = 53
for week_number in range(first_week_number, last_week_number + 1):
for week_number in range(first_week_number + first_week_offset, last_week_number + 1):
yield self.get_week_timetable_infos(
week_number - first_week_number,
timeperiods,

View File

@ -1788,6 +1788,17 @@ def test_agenda_month_view_weekend(app, admin_user, manager_user, api_user):
resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, year, month))
assert not 'Sunday' in resp.text
assert not 'Saturday' in resp.text
# No Monday on first row since month starts a Tuesday
assert len(resp.pyquery.find('tbody tr:first th.weekday:empty')) == 1
# When weekend is hidden, do not display an empty first week
month, year = 12, 2019 # month starts a Sunday
resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, year, month))
assert len(resp.pyquery.find('tbody tr:first th.weekday:empty')) == 0
month, year = 6, 2019 # month starts a Saturday
resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, year, month))
assert len(resp.pyquery.find('tbody tr:first th.weekday:empty')) == 0
saturday = 5
timeperiod_sat = TimePeriod.objects.create(
@ -1796,6 +1807,7 @@ def test_agenda_month_view_weekend(app, admin_user, manager_user, api_user):
resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, year, month))
assert not 'Sunday' in resp.text
assert 'Saturday' in resp.text
assert len(resp.pyquery.find('tbody tr:first th.weekday:empty')) == 5
sunday = 6
timeperiod = TimePeriod.objects.create(

View File

@ -21,6 +21,7 @@ deps =
pylint-django<0.8.1
django-webtest
pytz
pyquery
django111: django-mellon>=1.2.35,!=1.6
django22: django-mellon>=1.6.1
pytest-freezegun