From 569e85a8e1de8187297fe28946e5848a5eb7d90f Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 29 Jul 2021 10:54:58 +0200 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(-) diff --git a/chrono/agendas/migrations/0041_clean_event_slug_unicity.py b/chrono/agendas/migrations/0041_clean_event_slug_unicity.py index e8e7612..6052f18 100644 --- a/chrono/agendas/migrations/0041_clean_event_slug_unicity.py +++ b/chrono/agendas/migrations/0041_clean_event_slug_unicity.py @@ -4,12 +4,8 @@ from django.db import migrations def clean_constraint(apps, schema_editor): Event = apps.get_model('agendas', 'Event') - if django.VERSION < (2, 0): - model = Event - else: - model = 'agendas_event' # remove _like index added for unicity if exists - index_to_remove = schema_editor._create_index_name(model, ['slug'], suffix='_like') + index_to_remove = schema_editor._create_index_name('agendas_event', ['slug'], suffix='_like') index_names = schema_editor._constraint_names(Event, ['slug'], index=True) for index_name in index_names: if index_name == index_to_remove: diff --git a/chrono/agendas/models.py b/chrono/agendas/models.py index 672bc6b..1e73265 100644 --- a/chrono/agendas/models.py +++ b/chrono/agendas/models.py @@ -1415,50 +1415,24 @@ class Event(models.Model): @staticmethod def annotate_queryset_for_user(qs, user_external_id): - if django.VERSION < (2, 0): - from django.db.models import Case, When - - return qs.annotate( - user_places_count=Count( - Case( - When( - booking__cancellation_datetime__isnull=True, - booking__in_waiting_list=False, - booking__user_external_id=user_external_id, - then='booking', - ) - ) - ), - user_waiting_places_count=Count( - Case( - When( - booking__cancellation_datetime__isnull=True, - booking__in_waiting_list=True, - booking__user_external_id=user_external_id, - then='booking', - ) - ) - ), - ) - else: - return qs.annotate( - user_places_count=Count( - 'booking', - filter=Q( - booking__cancellation_datetime__isnull=True, - booking__in_waiting_list=False, - booking__user_external_id=user_external_id, - ), + return qs.annotate( + user_places_count=Count( + 'booking', + filter=Q( + booking__cancellation_datetime__isnull=True, + booking__in_waiting_list=False, + booking__user_external_id=user_external_id, ), - user_waiting_places_count=Count( - 'booking', - filter=Q( - booking__cancellation_datetime__isnull=True, - booking__in_waiting_list=True, - booking__user_external_id=user_external_id, - ), + ), + user_waiting_places_count=Count( + 'booking', + filter=Q( + booking__cancellation_datetime__isnull=True, + booking__in_waiting_list=True, + booking__user_external_id=user_external_id, ), - ) + ), + ) @property def booked_places(self): diff --git a/chrono/api/views.py b/chrono/api/views.py index 17f1186..d83ecc7 100644 --- a/chrono/api/views.py +++ b/chrono/api/views.py @@ -1616,32 +1616,11 @@ class RecurringFillslots(APIView): with transaction.atomic(): Booking.objects.bulk_create(bookings) - if django.VERSION < (2, 0): - from django.db.models import Case, When - - events_to_book.update( - full=Case( - When( - Q(booked_places_count__gte=F('places'), waiting_list_places=0) - | Q( - waiting_list_places__gt=0, - waiting_list_count__gte=F('waiting_list_places'), - ), - then=Value(True), - ), - default=Value(False), - ), - almost_full=Case( - When(Q(booked_places_count__gte=0.9 * F('places')), then=Value(True)), - default=Value(False), - ), - ) - else: - events_to_book.update( - full=Q(booked_places_count__gte=F('places'), waiting_list_places=0) - | Q(waiting_list_places__gt=0, waiting_list_count__gte=F('waiting_list_places')), - almost_full=Q(booked_places_count__gte=0.9 * F('places')), - ) + events_to_book.update( + full=Q(booked_places_count__gte=F('places'), waiting_list_places=0) + | Q(waiting_list_places__gt=0, waiting_list_count__gte=F('waiting_list_places')), + almost_full=Q(booked_places_count__gte=0.9 * F('places')), + ) response = { 'err': 0, diff --git a/chrono/urls_utils.py b/chrono/urls_utils.py index 7f268cc..4d3ef1e 100644 --- a/chrono/urls_utils.py +++ b/chrono/urls_utils.py @@ -17,11 +17,7 @@ # Decorating URL includes, import django - -if django.VERSION < (2, 0, 0): - from django.urls.resolvers import RegexURLPattern as URLPattern # pylint: disable=no-name-in-module -else: - from django.urls.resolvers import URLPattern # pylint: disable=no-name-in-module +from django.urls.resolvers import URLPattern class DecoratedURLPattern(URLPattern): -- 2.20.1