manager: prevent emtpy first row in monthly view (#38700)
It could occur when weekend was hidden.
This commit is contained in:
parent
ba94214d55
commit
d63a039bf2
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue