Projet

Général

Profil

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

Valentin Deniaud, 29 juillet 2021 14:44

Télécharger (7,52 ko)

Voir les différences:

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

 .../0041_clean_event_slug_unicity.py          |  7 +--
 chrono/agendas/models.py                      | 59 +++++--------------
 chrono/api/views.py                           | 34 ++---------
 chrono/urls_utils.py                          |  7 +--
 setup.py                                      |  2 +-
 5 files changed, 25 insertions(+), 84 deletions(-)
chrono/agendas/migrations/0041_clean_event_slug_unicity.py
1
import django
2 1
from django.db import migrations
3 2

  
4 3

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

  
26
import django
27 26
import requests
28 27
import vobject
29 28
from dateutil.rrule import DAILY, WEEKLY, rrule, rruleset
......
1415 1414

  
1416 1415
    @staticmethod
1417 1416
    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
                    ),
1417
        return qs.annotate(
1418
            user_places_count=Count(
1419
                'booking',
1420
                filter=Q(
1421
                    booking__cancellation_datetime__isnull=True,
1422
                    booking__in_waiting_list=False,
1423
                    booking__user_external_id=user_external_id,
1452 1424
                ),
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
                    ),
1425
            ),
1426
            user_waiting_places_count=Count(
1427
                'booking',
1428
                filter=Q(
1429
                    booking__cancellation_datetime__isnull=True,
1430
                    booking__in_waiting_list=True,
1431
                    booking__user_external_id=user_external_id,
1460 1432
                ),
1461
            )
1433
            ),
1434
        )
1462 1435

  
1463 1436
    @property
1464 1437
    def booked_places(self):
chrono/api/views.py
19 19
import itertools
20 20
import uuid
21 21

  
22
import django
23 22
from django.conf import settings
24 23
from django.db import transaction
25
from django.db.models import BooleanField, Count, ExpressionWrapper, F, Prefetch, Q, Value
24
from django.db.models import BooleanField, Count, ExpressionWrapper, F, Prefetch, Q
26 25
from django.db.models.functions import TruncDay
27 26
from django.http import Http404, HttpResponse
28 27
from django.shortcuts import get_object_or_404
......
1616 1615

  
1617 1616
        with transaction.atomic():
1618 1617
            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
                )
1618
            events_to_book.update(
1619
                full=Q(booked_places_count__gte=F('places'), waiting_list_places=0)
1620
                | Q(waiting_list_places__gt=0, waiting_list_count__gte=F('waiting_list_places')),
1621
                almost_full=Q(booked_places_count__gte=0.9 * F('places')),
1622
            )
1645 1623

  
1646 1624
        response = {
1647 1625
            'err': 0,
chrono/urls_utils.py
16 16

  
17 17
# Decorating URL includes, <https://djangosnippets.org/snippets/2532/>
18 18

  
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
19
from django.urls.resolvers import URLPattern
25 20

  
26 21

  
27 22
class DecoratedURLPattern(URLPattern):
setup.py
160 160
        'Programming Language :: Python :: 3',
161 161
    ],
162 162
    install_requires=[
163
        'django>=1.11, <2.3',
163
        'django>=2.2, <2.3',
164 164
        'gadjo',
165 165
        'djangorestframework>=3.4',
166 166
        'django-filter',
167
-