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
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
def clean_constraint(apps, schema_editor):
|
def clean_constraint(apps, schema_editor):
|
||||||
Event = apps.get_model('agendas', 'Event')
|
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
|
# 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)
|
index_names = schema_editor._constraint_names(Event, ['slug'], index=True)
|
||||||
for index_name in index_names:
|
for index_name in index_names:
|
||||||
if index_name == index_to_remove:
|
if index_name == index_to_remove:
|
||||||
|
|
|
@ -23,7 +23,6 @@ import math
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import django
|
|
||||||
import requests
|
import requests
|
||||||
import vobject
|
import vobject
|
||||||
from dateutil.rrule import DAILY, WEEKLY, rrule, rruleset
|
from dateutil.rrule import DAILY, WEEKLY, rrule, rruleset
|
||||||
|
@ -1415,50 +1414,24 @@ class Event(models.Model):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def annotate_queryset_for_user(qs, user_external_id):
|
def annotate_queryset_for_user(qs, user_external_id):
|
||||||
if django.VERSION < (2, 0):
|
return qs.annotate(
|
||||||
from django.db.models import Case, When
|
user_places_count=Count(
|
||||||
|
'booking',
|
||||||
return qs.annotate(
|
filter=Q(
|
||||||
user_places_count=Count(
|
booking__cancellation_datetime__isnull=True,
|
||||||
Case(
|
booking__in_waiting_list=False,
|
||||||
When(
|
booking__user_external_id=user_external_id,
|
||||||
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(
|
user_waiting_places_count=Count(
|
||||||
When(
|
'booking',
|
||||||
booking__cancellation_datetime__isnull=True,
|
filter=Q(
|
||||||
booking__in_waiting_list=True,
|
booking__cancellation_datetime__isnull=True,
|
||||||
booking__user_external_id=user_external_id,
|
booking__in_waiting_list=True,
|
||||||
then='booking',
|
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
|
@property
|
||||||
def booked_places(self):
|
def booked_places(self):
|
||||||
|
|
|
@ -19,10 +19,9 @@ import datetime
|
||||||
import itertools
|
import itertools
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import django
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import transaction
|
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.db.models.functions import TruncDay
|
||||||
from django.http import Http404, HttpResponse
|
from django.http import Http404, HttpResponse
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
|
@ -1616,32 +1615,11 @@ class RecurringFillslots(APIView):
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
Booking.objects.bulk_create(bookings)
|
Booking.objects.bulk_create(bookings)
|
||||||
if django.VERSION < (2, 0):
|
events_to_book.update(
|
||||||
from django.db.models import Case, When
|
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')),
|
||||||
events_to_book.update(
|
almost_full=Q(booked_places_count__gte=0.9 * F('places')),
|
||||||
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')),
|
|
||||||
)
|
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
'err': 0,
|
'err': 0,
|
||||||
|
|
|
@ -16,12 +16,7 @@
|
||||||
|
|
||||||
# Decorating URL includes, <https://djangosnippets.org/snippets/2532/>
|
# Decorating URL includes, <https://djangosnippets.org/snippets/2532/>
|
||||||
|
|
||||||
import django
|
from django.urls.resolvers import URLPattern
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class DecoratedURLPattern(URLPattern):
|
class DecoratedURLPattern(URLPattern):
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -160,7 +160,7 @@ setup(
|
||||||
'Programming Language :: Python :: 3',
|
'Programming Language :: Python :: 3',
|
||||||
],
|
],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'django>=1.11, <2.3',
|
'django>=2.2, <2.3',
|
||||||
'gadjo',
|
'gadjo',
|
||||||
'djangorestframework>=3.4',
|
'djangorestframework>=3.4',
|
||||||
'django-filter',
|
'django-filter',
|
||||||
|
|
Loading…
Reference in New Issue