misc: remove django 1.11 compatibility code (#55895)
This commit is contained in:
parent
489198a8a6
commit
7f4c9d96df
|
@ -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:
|
||||
|
|
|
@ -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',
|
||||
)
|
||||
)
|
||||
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(
|
||||
Case(
|
||||
When(
|
||||
booking__cancellation_datetime__isnull=True,
|
||||
booking__in_waiting_list=True,
|
||||
booking__user_external_id=user_external_id,
|
||||
then='booking',
|
||||
)
|
||||
)
|
||||
),
|
||||
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,
|
||||
),
|
||||
)
|
||||
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,
|
||||
),
|
||||
),
|
||||
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):
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -16,12 +16,7 @@
|
|||
|
||||
# Decorating URL includes, <https://djangosnippets.org/snippets/2532/>
|
||||
|
||||
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):
|
||||
|
|
Loading…
Reference in New Issue