From 7f4c9d96df3c7a7a69f267e41da823e1ca8ef0f6 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 | 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(-) diff --git a/chrono/agendas/migrations/0041_clean_event_slug_unicity.py b/chrono/agendas/migrations/0041_clean_event_slug_unicity.py index e8e7612..9dea61d 100644 --- a/chrono/agendas/migrations/0041_clean_event_slug_unicity.py +++ b/chrono/agendas/migrations/0041_clean_event_slug_unicity.py @@ -1,15 +1,10 @@ -import django 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..5ad7b13 100644 --- a/chrono/agendas/models.py +++ b/chrono/agendas/models.py @@ -23,7 +23,6 @@ import math import sys import uuid -import django import requests import vobject from dateutil.rrule import DAILY, WEEKLY, rrule, rruleset @@ -1415,50 +1414,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..b11444a 100644 --- a/chrono/api/views.py +++ b/chrono/api/views.py @@ -19,10 +19,9 @@ import datetime import itertools import uuid -import django from django.conf import settings from django.db import transaction -from django.db.models import BooleanField, Count, ExpressionWrapper, F, Prefetch, Q, Value +from django.db.models import BooleanField, Count, ExpressionWrapper, F, Prefetch, Q from django.db.models.functions import TruncDay from django.http import Http404, HttpResponse from django.shortcuts import get_object_or_404 @@ -1616,32 +1615,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..eeb5c7f 100644 --- a/chrono/urls_utils.py +++ b/chrono/urls_utils.py @@ -16,12 +16,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): diff --git a/setup.py b/setup.py index 487b96a..a9ea794 100644 --- a/setup.py +++ b/setup.py @@ -160,7 +160,7 @@ setup( 'Programming Language :: Python :: 3', ], install_requires=[ - 'django>=1.11, <2.3', + 'django>=2.2, <2.3', 'gadjo', 'djangorestframework>=3.4', 'django-filter', -- 2.20.1