Projet

Général

Profil

0005-manager-account-for-time-period-weekday-indexes-in-c.patch

Valentin Deniaud, 10 mars 2022 16:02

Télécharger (4,6 ko)

Voir les différences:

Subject: [PATCH 5/5] manager: account for time period weekday indexes in
 calendar views (#45159)

 chrono/agendas/models.py  |  3 +++
 chrono/manager/views.py   |  8 ++++++-
 tests/manager/test_all.py | 49 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)
chrono/agendas/models.py
2176 2176

  
2177 2177
    def get_opening_hours(self, date):
2178 2178
        openslots = IntervalSet()
2179
        weekday_index = get_weekday_index(date)
2179 2180
        for timeperiod in self.timeperiod_set.all():
2181
            if timeperiod.weekday_indexes and weekday_index not in timeperiod.weekday_indexes:
2182
                continue
2180 2183
            # timeperiod_set.all() are prefetched, do not filter in queryset
2181 2184
            if timeperiod.weekday != date.weekday():
2182 2185
                continue
chrono/manager/views.py
78 78
    UnavailabilityCalendar,
79 79
    VirtualMember,
80 80
)
81
from chrono.utils.date import get_weekday_index
81 82

  
82 83
from .forms import (
83 84
    AbsenceReasonForm,
......
1214 1215

  
1215 1216
    def get_timetable_infos(self):
1216 1217
        timeperiods = itertools.chain(*(d.timeperiod_set.all() for d in self.agenda.prefetched_desks))
1217
        timeperiods = [t for t in timeperiods if t.weekday == self.date.weekday()]
1218
        timeperiods = [
1219
            t
1220
            for t in timeperiods
1221
            if t.weekday == self.date.weekday()
1222
            and (not t.weekday_indexes or get_weekday_index(self.date) in t.weekday_indexes)
1223
        ]
1218 1224
        timeperiods = sorted(timeperiods, key=lambda t: t.start_time)
1219 1225

  
1220 1226
        interval = datetime.timedelta(minutes=60)
tests/manager/test_all.py
3037 3037
    assert resp.text.count('Swimming') == 2  # 1 booking + legend
3038 3038
    assert 'Booking colors:' in resp.text
3039 3039
    assert len(resp.pyquery.find('div.booking-colors span.booking-color-label')) == 2
3040

  
3041

  
3042
@freezegun.freeze_time('2022-03-01 14:00')
3043
def test_agenda_day_and_month_views_weekday_indexes(app, admin_user):
3044
    agenda = Agenda.objects.create(label='New Example', kind='meetings')
3045
    desk = Desk.objects.create(agenda=agenda, label='New Desk')
3046
    MeetingType.objects.create(agenda=agenda, label='Bar', duration=30)
3047
    today = datetime.date.today()
3048
    TimePeriod.objects.create(
3049
        desk=desk,
3050
        weekday=today.weekday(),
3051
        start_time=datetime.time(10, 0),
3052
        end_time=datetime.time(14, 0),
3053
        weekday_indexes=[1, 3],
3054
    )
3055
    TimePeriod.objects.create(
3056
        desk=desk,
3057
        weekday=today.weekday(),
3058
        start_time=datetime.time(14, 0),
3059
        end_time=datetime.time(17, 0),
3060
        weekday_indexes=[3, 5],
3061
    )
3062
    login(app)
3063

  
3064
    # check day view
3065
    resp = app.get('/manage/agendas/%s/%s/%s/%s/' % (agenda.pk, today.year, today.month, today.day))
3066
    assert resp.text.count('<tr') == 5  # 10->14
3067
    assert 'style="height: 400%; top: 0%;"' in resp.text
3068

  
3069
    resp = app.get('/manage/agendas/%s/%s/%s/%s/' % (agenda.pk, today.year, today.month, today.day + 7))
3070
    assert 'No opening hours this day.' in resp.text
3071

  
3072
    resp = app.get('/manage/agendas/%s/%s/%s/%s/' % (agenda.pk, today.year, today.month, today.day + 14))
3073
    assert resp.text.count('<tr') == 8  # 10->14, 14->17
3074
    assert 'style="height: 700%; top: 0%;"' in resp.text
3075

  
3076
    resp = app.get('/manage/agendas/%s/%s/%s/%s/' % (agenda.pk, today.year, today.month, today.day + 21))
3077
    assert 'No opening hours this day.' in resp.text
3078

  
3079
    resp = app.get('/manage/agendas/%s/%s/%s/%s/' % (agenda.pk, today.year, today.month, today.day + 28))
3080
    assert resp.text.count('<tr') == 4  # 14->17
3081
    assert 'style="height: 300%; top: 0%;"' in resp.text
3082

  
3083
    # check month view
3084
    resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.pk, today.year, today.month))
3085
    assert resp.text.count('height:') == 3
3086
    assert resp.text.count('height:400.0%') == 1
3087
    assert resp.text.count('height:700.0%') == 1
3088
    assert resp.text.count('height:300.0%') == 1
3040
-