Projet

Général

Profil

0001-misc-remove-django-1.11-compatibility-code-55895.patch

Valentin Deniaud, 29 juillet 2021 10:55

Télécharger (6,49 ko)

Voir les différences:

Subject: [PATCH] misc: remove django 1.11 compatibility code (#55895)

 .../0041_clean_event_slug_unicity.py          |  6 +-
 chrono/agendas/models.py                      | 58 +++++--------------
 chrono/api/views.py                           | 31 ++--------
 chrono/urls_utils.py                          |  6 +-
 4 files changed, 23 insertions(+), 78 deletions(-)
chrono/agendas/migrations/0041_clean_event_slug_unicity.py
4 4

  
5 5
def clean_constraint(apps, schema_editor):
6 6
    Event = apps.get_model('agendas', 'Event')
7
    if django.VERSION < (2, 0):
8
        model = Event
9
    else:
10
        model = 'agendas_event'
11 7
    # remove _like index added for unicity if exists
12
    index_to_remove = schema_editor._create_index_name(model, ['slug'], suffix='_like')
8
    index_to_remove = schema_editor._create_index_name('agendas_event', ['slug'], suffix='_like')
13 9
    index_names = schema_editor._constraint_names(Event, ['slug'], index=True)
14 10
    for index_name in index_names:
15 11
        if index_name == index_to_remove:
chrono/agendas/models.py
1415 1415

  
1416 1416
    @staticmethod
1417 1417
    def annotate_queryset_for_user(qs, user_external_id):
1418
        if django.VERSION < (2, 0):
1419
            from django.db.models import Case, When
1420

  
1421
            return qs.annotate(
1422
                user_places_count=Count(
1423
                    Case(
1424
                        When(
1425
                            booking__cancellation_datetime__isnull=True,
1426
                            booking__in_waiting_list=False,
1427
                            booking__user_external_id=user_external_id,
1428
                            then='booking',
1429
                        )
1430
                    )
1431
                ),
1432
                user_waiting_places_count=Count(
1433
                    Case(
1434
                        When(
1435
                            booking__cancellation_datetime__isnull=True,
1436
                            booking__in_waiting_list=True,
1437
                            booking__user_external_id=user_external_id,
1438
                            then='booking',
1439
                        )
1440
                    )
1441
                ),
1442
            )
1443
        else:
1444
            return qs.annotate(
1445
                user_places_count=Count(
1446
                    'booking',
1447
                    filter=Q(
1448
                        booking__cancellation_datetime__isnull=True,
1449
                        booking__in_waiting_list=False,
1450
                        booking__user_external_id=user_external_id,
1451
                    ),
1418
        return qs.annotate(
1419
            user_places_count=Count(
1420
                'booking',
1421
                filter=Q(
1422
                    booking__cancellation_datetime__isnull=True,
1423
                    booking__in_waiting_list=False,
1424
                    booking__user_external_id=user_external_id,
1452 1425
                ),
1453
                user_waiting_places_count=Count(
1454
                    'booking',
1455
                    filter=Q(
1456
                        booking__cancellation_datetime__isnull=True,
1457
                        booking__in_waiting_list=True,
1458
                        booking__user_external_id=user_external_id,
1459
                    ),
1426
            ),
1427
            user_waiting_places_count=Count(
1428
                'booking',
1429
                filter=Q(
1430
                    booking__cancellation_datetime__isnull=True,
1431
                    booking__in_waiting_list=True,
1432
                    booking__user_external_id=user_external_id,
1460 1433
                ),
1461
            )
1434
            ),
1435
        )
1462 1436

  
1463 1437
    @property
1464 1438
    def booked_places(self):
chrono/api/views.py
1616 1616

  
1617 1617
        with transaction.atomic():
1618 1618
            Booking.objects.bulk_create(bookings)
1619
            if django.VERSION < (2, 0):
1620
                from django.db.models import Case, When
1621

  
1622
                events_to_book.update(
1623
                    full=Case(
1624
                        When(
1625
                            Q(booked_places_count__gte=F('places'), waiting_list_places=0)
1626
                            | Q(
1627
                                waiting_list_places__gt=0,
1628
                                waiting_list_count__gte=F('waiting_list_places'),
1629
                            ),
1630
                            then=Value(True),
1631
                        ),
1632
                        default=Value(False),
1633
                    ),
1634
                    almost_full=Case(
1635
                        When(Q(booked_places_count__gte=0.9 * F('places')), then=Value(True)),
1636
                        default=Value(False),
1637
                    ),
1638
                )
1639
            else:
1640
                events_to_book.update(
1641
                    full=Q(booked_places_count__gte=F('places'), waiting_list_places=0)
1642
                    | Q(waiting_list_places__gt=0, waiting_list_count__gte=F('waiting_list_places')),
1643
                    almost_full=Q(booked_places_count__gte=0.9 * F('places')),
1644
                )
1619
            events_to_book.update(
1620
                full=Q(booked_places_count__gte=F('places'), waiting_list_places=0)
1621
                | Q(waiting_list_places__gt=0, waiting_list_count__gte=F('waiting_list_places')),
1622
                almost_full=Q(booked_places_count__gte=0.9 * F('places')),
1623
            )
1645 1624

  
1646 1625
        response = {
1647 1626
            'err': 0,
chrono/urls_utils.py
17 17
# Decorating URL includes, <https://djangosnippets.org/snippets/2532/>
18 18

  
19 19
import django
20

  
21
if django.VERSION < (2, 0, 0):
22
    from django.urls.resolvers import RegexURLPattern as URLPattern  # pylint: disable=no-name-in-module
23
else:
24
    from django.urls.resolvers import URLPattern  # pylint: disable=no-name-in-module
20
from django.urls.resolvers import URLPattern
25 21

  
26 22

  
27 23
class DecoratedURLPattern(URLPattern):
28
-