Projet

Général

Profil

0001-api-add-more-infos-on-places-for-an-event-agenda-404.patch

Emmanuel Cazenave, 31 mars 2020 14:47

Télécharger (5,4 ko)

Voir les différences:

Subject: [PATCH] api: add more infos on places for an event agenda (#40412)

 chrono/api/views.py | 11 ++++++++++-
 tests/test_api.py   | 11 +++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
chrono/api/views.py
176 176

  
177 177

  
178 178
def get_event_places(event):
179
    available = event.places - event.booked_places
179 180
    places = {
180 181
        'total': event.places,
181 182
        'reserved': event.booked_places,
182
        'available': event.places - event.booked_places,
183
        'available': available,
184
        'full': event.full,
185
        'has_waiting_list': False,
183 186
    }
184 187
    if event.waiting_list_places:
188
        places['has_waiting_list'] = True
185 189
        places['waiting_list_total'] = event.waiting_list_places
186 190
        places['waiting_list_reserved'] = event.waiting_list
187 191
        places['waiting_list_available'] = event.waiting_list_places - event.waiting_list
192
        places['waiting_list_activated'] = event.waiting_list > 0 or available <= 0
193
        # 'waiting_list_activated' means next booking will go into the waiting list
194

  
188 195
    return places
189 196

  
190 197

  
......
766 773
            response['cancelled_booking_id'] = cancelled_booking_id
767 774
        if agenda.kind == 'events' and not multiple_booking:
768 775
            event = events[0]
776
            # event.full is not up to date, it might have been changed by previous new_booking.save().
777
            event.refresh_from_db()
769 778
            response['places'] = get_event_places(event)
770 779
        if agenda.kind == 'events' and multiple_booking:
771 780
            response['events'] = [
tests/test_api.py
971 971
    assert resp.json['places']['total'] == 10
972 972
    assert resp.json['places']['available'] == 9
973 973
    assert resp.json['places']['reserved'] == 1
974
    assert resp.json['places']['full'] is False
974 975
    assert 'waiting_list_total' not in resp.json['places']
975 976

  
976 977
    Booking.objects.create(event=event, in_waiting_list=True)
......
982 983
    assert resp.json['places']['total'] == 10
983 984
    assert resp.json['places']['available'] == 9
984 985
    assert resp.json['places']['reserved'] == 1
986
    assert resp.json['places']['full'] is False
985 987
    assert resp.json['places']['waiting_list_total'] == 5
986 988
    assert resp.json['places']['waiting_list_available'] == 3
987 989
    assert resp.json['places']['waiting_list_reserved'] == 2
990
    assert resp.json['places']['waiting_list_activated'] is True
988 991

  
989 992
    # not for mettings agenda
990 993
    meeting_type = MeetingType.objects.get(agenda=meetings_agenda)
......
1029 1032
    assert resp.json['places']['total'] == 10
1030 1033
    assert resp.json['places']['available'] == 9
1031 1034
    assert resp.json['places']['reserved'] == 1
1035
    assert resp.json['places']['full'] is False
1032 1036
    assert resp.json['places']['waiting_list_total'] == 2
1033 1037
    assert resp.json['places']['waiting_list_available'] == 2
1034 1038
    assert resp.json['places']['waiting_list_reserved'] == 0
1039
    assert resp.json['places']['waiting_list_activated'] is False
1035 1040

  
1036 1041
    # add another booking
1037 1042
    resp = app.post_json(
......
1041 1046
    assert resp.json['places']['total'] == 10
1042 1047
    assert resp.json['places']['available'] == 8
1043 1048
    assert resp.json['places']['reserved'] == 2
1049
    assert resp.json['places']['full'] is False
1044 1050
    assert resp.json['places']['waiting_list_total'] == 2
1045 1051
    assert resp.json['places']['waiting_list_available'] == 2
1046 1052
    assert resp.json['places']['waiting_list_reserved'] == 0
1053
    assert resp.json['places']['waiting_list_activated'] is False
1047 1054

  
1048 1055
    # add a booking, but in waiting list
1049 1056
    resp = app.post_json(
......
1053 1060
    assert resp.json['places']['total'] == 10
1054 1061
    assert resp.json['places']['available'] == 8
1055 1062
    assert resp.json['places']['reserved'] == 2
1063
    assert resp.json['places']['full'] is False
1056 1064
    assert resp.json['places']['waiting_list_total'] == 2
1057 1065
    assert resp.json['places']['waiting_list_available'] == 1
1058 1066
    assert resp.json['places']['waiting_list_reserved'] == 1
1067
    assert resp.json['places']['waiting_list_activated'] is True
1059 1068

  
1060 1069
    # add a booking => booked in waiting list
1061 1070
    resp = app.post_json('/api/agenda/%s/fillslot/%s/' % (agenda.pk, event.pk))
......
1063 1072
    assert resp.json['places']['total'] == 10
1064 1073
    assert resp.json['places']['available'] == 8
1065 1074
    assert resp.json['places']['reserved'] == 2
1075
    assert resp.json['places']['full'] is True
1066 1076
    assert resp.json['places']['waiting_list_total'] == 2
1067 1077
    assert resp.json['places']['waiting_list_available'] == 0
1068 1078
    assert resp.json['places']['waiting_list_reserved'] == 2
1079
    assert resp.json['places']['waiting_list_activated'] is True
1069 1080

  
1070 1081
    # waiting list is full
1071 1082
    resp = app.post_json(
1072
-