Projet

Général

Profil

0001-booking-calendar-cell-display-first-available-slot-i.patch

Josué Kouka, 17 octobre 2017 17:51

Télécharger (4,45 ko)

Voir les différences:

Subject: [PATCH] booking calendar cell: display first available slot if any
 (#19460)

 .../templates/calendar/booking_calendar_cell.html    |  7 ++++++-
 combo/apps/calendar/utils.py                         | 15 ++++++++++++++-
 tests/test_calendar.py                               | 20 ++++++++++++++++++--
 3 files changed, 38 insertions(+), 4 deletions(-)
combo/apps/calendar/templates/calendar/booking_calendar_cell.html
2 2

  
3 3
<div id="cal-{{cell.id}}">
4 4
    {% if cell.title %}
5
    <h2>{{cell.title}}</h2>
5
    <h2>
6
        <span>{{cell.title}}</span>
7
        {% if calendar %}
8
        <span>{{ calendar.get_info }}</span>
9
        {% endif %}
10
    </h2>
6 11
    {% endif %}
7 12
    <div>
8 13
        {% if calendar.days %}
combo/apps/calendar/utils.py
18 18
import datetime
19 19

  
20 20
from django.conf import settings
21
from django.utils.dateformat import DateFormat
21 22
from django.utils.dateparse import parse_datetime
23
from django.utils.formats import get_format
24
from django.utils.timezone import localtime, make_aware
25
from django.utils.translation import ugettext_lazy as _
22 26

  
23 27
from combo.utils import requests
24 28

  
......
109 113
class DaySlot(object):
110 114

  
111 115
    def __init__(self, date_time, available, exist=True):
112
        self.date_time = date_time
116
        self.date_time = localtime(make_aware(date_time))
113 117
        self.available = available
114 118
        self.exist = exist
115 119

  
116 120
    def __repr__(self):
117 121
        return '<DaySlot date_time=%s - available=%s>' % (self.date_time.isoformat(), self.available)
118 122

  
123
    def __str__(self):
124
        return '%s' % DateFormat(self.date_time).format(get_format('DATETIME_FORMAT'))
125

  
119 126
    @property
120 127
    def label(self):
121 128
        return '%s' % self.date_time.isoformat()
......
159 166
            return '<Calendar: %s -> %s >' % (self.days[0], self.days[-1])
160 167
        return '<Calendar>'
161 168

  
169
    def get_info(self):
170
        if self.days:
171
            first_slot = self.days[0].slots[0]
172
            return _('(Next available slot on %s.)') % first_slot
173
        return _('No slot available.')
174

  
162 175
    def get_slots(self):
163 176
        start = self.get_minimum_slot()
164 177
        end = self.get_maximum_slot()
tests/test_calendar.py
215 215
    assert parsed.path == '/test/'
216 216
    qs = urlparse.parse_qs(parsed.query)
217 217
    assert qs['session_var_booking_agenda_slug'] == ['test']
218
    assert qs['session_var_booking_start'] == ['2017-06-13T08:00:00']
219
    assert qs['session_var_booking_end'] == ['2017-06-13T09:30:00']
218
    assert qs['session_var_booking_start'] == ['2017-06-13T08:00:00+00:00']
219
    assert qs['session_var_booking_end'] == ['2017-06-13T09:30:00+00:00']
220 220

  
221 221

  
222 222
@mock.patch('combo.apps.calendar.utils.requests.get', side_effect=mocked_requests_get)
......
236 236
    assert cal.get_minimum_slot() == min_slot.time()
237 237
    assert cal.get_maximum_slot() == max_slot.time()
238 238
    assert cal.get_day(max_slot.date()).slots[-1].available is False
239

  
240

  
241
@mock.patch('combo.apps.calendar.utils.requests.get', side_effect=mocked_requests_get)
242
def test_cell_rendering_cal_info(mocked_get, client, cell):
243
    page = client.get('/booking/')
244
    assert 'Next available slot on June 13' in page.content
245
    # test when no slot is available
246
    with mock.patch('combo.utils.requests.get') as request_get:
247
        def side_effect(*args, **kwargs):
248
            if 'chrono' in kwargs['remote_service']['url']:
249
                return MockedRequestResponse(content=json.dumps({"data": []}))
250
            return MockedRequestResponse(content=json.dumps(WCS_FORMDEFS))
251

  
252
        request_get.side_effect = side_effect
253
        page = client.get('/booking/')
254
        assert 'No slot available.' in page.content
239
-