File: mixins.py

package info (click to toggle)
python-django 3%3A6.0~alpha1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 62,204 kB
  • sloc: python: 370,694; javascript: 19,376; xml: 211; makefile: 187; sh: 28
file content (36 lines) | stat: -rw-r--r-- 1,246 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# RemovedInDjango70Warning: When the deprecation ends, remove completely.
import warnings

from django.utils.deprecation import RemovedInDjango61Warning, RemovedInDjango70Warning


# RemovedInDjango61Warning.
class _DeprecatedOrdering:
    def __init__(self, *expressions, ordering=(), order_by=(), **extra):
        if ordering:
            warnings.warn(
                "The ordering argument is deprecated. Use order_by instead.",
                category=RemovedInDjango61Warning,
                stacklevel=2,
            )
            if order_by:
                raise TypeError("Cannot specify both order_by and ordering.")
            order_by = ordering

        super().__init__(*expressions, order_by=order_by, **extra)


# RemovedInDjango70Warning.
# RemovedInDjango61Warning: When the deprecation ends, replace with:
# class OrderableAggMixin:
class OrderableAggMixin(_DeprecatedOrdering):
    allow_order_by = True

    def __init_subclass__(cls, /, *args, **kwargs):
        warnings.warn(
            "OrderableAggMixin is deprecated. Use Aggregate and allow_order_by "
            "instead.",
            category=RemovedInDjango70Warning,
            stacklevel=1,
        )
        super().__init_subclass__(*args, **kwargs)