Projet

Général

Profil

0002-manager-refine-messages-when-adding-exception-47393.patch

Emmanuel Cazenave, 18 novembre 2020 14:37

Télécharger (5,22 ko)

Voir les différences:

Subject: [PATCH 2/2] manager: refine messages when adding exception (#47393)

 chrono/manager/views.py | 13 +++++--------
 tests/test_manager.py   | 22 ++++++++++++----------
 2 files changed, 17 insertions(+), 18 deletions(-)
chrono/manager/views.py
1956 1956
                        end_datetime=self.object.end_datetime,
1957 1957
                    )
1958 1958
                )
1959
        message = ungettext('Exception added.', 'Exceptions added.', len(exceptions),)
1960
        messages.info(self.request, message)
1959 1961
        for exception in exceptions:
1960 1962
            if exception.has_booking_within_time_slot():
1961
                message = ungettext(
1962
                    'Exception added. Note: one or several bookings exists within this time slot.',
1963
                    'Exceptions added. Note: one or several bookings exists within this time slot.',
1964
                    len(exceptions),
1965
                )
1966
                messages.info(self.request, message)
1963
                messages.warning(self.request, _('One or several bookings exists within this time slot.'))
1967 1964
                break
1968 1965
        return result
1969 1966

  
......
1994 1991
    def form_valid(self, form):
1995 1992
        result = super().form_valid(form)
1996 1993
        if self.object.has_booking_within_time_slot():
1997
            message = _('Exception updated. Note: one or several bookings exists within this time slot.')
1998
            messages.info(self.request, message)
1994
            messages.info(self.request, _('Exception updated.'))
1995
            messages.warning(self.request, _('One or several bookings exists within this time slot.'))
1999 1996
        return result
2000 1997

  
2001 1998

  
tests/test_manager.py
2148 2148
    resp.form['all_desks'] = True
2149 2149
    resp = resp.form.submit().follow()
2150 2150
    assert TimePeriodException.objects.count() == 4
2151
    assert 'Exceptions added. Note: one or several bookings exists within this time slot.' in resp.text
2151
    assert 'Exceptions added.' in resp.text
2152
    assert 'One or several bookings exists within this time slot.' in resp.text
2152 2153

  
2153 2154
    exception = TimePeriodException.objects.first()
2154 2155
    resp = app.get('/manage/time-period-exceptions/%s/edit' % exception.pk)
......
2173 2174
    resp.form['all_desks'] = False
2174 2175
    resp = resp.form.submit().follow()
2175 2176
    assert TimePeriodException.objects.count() == 5
2176
    assert 'Exception added. Note: one or several bookings exists within this time slot.' in resp.text
2177
    assert 'Exception added.' in resp.text
2178
    assert 'One or several bookings exists within this time slot.' in resp.text
2177 2179

  
2178 2180

  
2179 2181
def test_meetings_agenda_add_time_period_exception_when_booking_exists(app, admin_user):
......
2199 2201
    resp.form['end_datetime_0'] = '2017-05-26'
2200 2202
    resp.form['end_datetime_1'] = '17:30'
2201 2203
    resp = resp.form.submit().follow()
2202
    assert 'Exception added. Note: one or several bookings exists within this time slot.' in resp.text
2204
    assert 'Exception added.' in resp.text
2205
    assert 'One or several bookings exists within this time slot.' in resp.text
2203 2206
    assert TimePeriodException.objects.count() == 1
2204 2207

  
2205 2208

  
......
2256 2259
        login(app)
2257 2260
        resp = app.get('/manage/time-period-exceptions/%s/edit' % time_period_exception.pk)
2258 2261
        resp = resp.form.submit().follow()
2259
        assert (
2260
            'Exception updated. Note: one or several bookings exists within this time slot.' not in resp.text
2261
        )
2262
        assert 'Exception updated.' not in resp.text
2263
        assert 'One or several bookings exists within this time slot.' not in resp.text
2262 2264

  
2263 2265
        booking = Booking.objects.create(event=event)
2264 2266
        resp = app.get('/manage/time-period-exceptions/%s/edit' % time_period_exception.pk)
2265 2267
        resp = resp.form.submit().follow()
2266
        assert 'Exception updated. Note: one or several bookings exists within this time slot.' in resp.text
2268
        assert 'Exception updated.' in resp.text
2269
        assert 'One or several bookings exists within this time slot.' in resp.text
2267 2270

  
2268 2271
        booking.cancel()
2269 2272
        resp = app.get('/manage/time-period-exceptions/%s/edit' % time_period_exception.pk)
2270 2273
        resp = resp.form.submit().follow()
2271
        assert (
2272
            'Exception updated. Note: one or several bookings exists within this time slot.' not in resp.text
2273
        )
2274
        assert 'Exception updated.' not in resp.text
2275
        assert 'One or several bookings exists within this time slot.' not in resp.text
2274 2276

  
2275 2277
        booking.delete()
2276 2278
        event.delete()
2277
-