2013-05-04 17:53:12 +08:00
|
|
|
from functools import wraps
|
|
|
|
|
2015-06-16 02:07:31 +08:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist # NOQA
|
|
|
|
from django.db.models import signals # NOQA
|
|
|
|
from django.db.models.aggregates import * # NOQA
|
|
|
|
from django.db.models.deletion import ( # NOQA
|
|
|
|
CASCADE, DO_NOTHING, PROTECT, SET, SET_DEFAULT, SET_NULL, ProtectedError,
|
|
|
|
)
|
2015-03-19 11:07:53 +08:00
|
|
|
from django.db.models.expressions import ( # NOQA
|
2016-03-28 23:19:25 +08:00
|
|
|
Case, Expression, ExpressionWrapper, F, Func, Value, When,
|
2015-03-19 11:07:53 +08:00
|
|
|
)
|
2013-10-18 19:25:30 +08:00
|
|
|
from django.db.models.fields import * # NOQA
|
2013-11-03 05:02:56 +08:00
|
|
|
from django.db.models.fields.files import FileField, ImageField # NOQA
|
2013-12-07 03:22:53 +08:00
|
|
|
from django.db.models.fields.proxy import OrderWrt # NOQA
|
2016-06-26 00:32:56 +08:00
|
|
|
from django.db.models.indexes import * # NOQA
|
2014-01-18 17:09:43 +08:00
|
|
|
from django.db.models.lookups import Lookup, Transform # NOQA
|
2015-06-16 02:07:31 +08:00
|
|
|
from django.db.models.manager import Manager # NOQA
|
2015-08-15 20:41:57 +08:00
|
|
|
from django.db.models.query import ( # NOQA
|
2016-03-28 23:19:25 +08:00
|
|
|
Prefetch, Q, QuerySet, prefetch_related_objects,
|
2015-08-15 20:41:57 +08:00
|
|
|
)
|
2015-06-16 02:07:31 +08:00
|
|
|
|
|
|
|
# Imports that would create circular imports if sorted
|
2016-02-02 17:33:09 +08:00
|
|
|
from django.db.models.base import DEFERRED, Model # NOQA isort:skip
|
2015-06-16 02:07:31 +08:00
|
|
|
from django.db.models.fields.related import ( # NOQA isort:skip
|
|
|
|
ForeignKey, ForeignObject, OneToOneField, ManyToManyField,
|
|
|
|
ManyToOneRel, ManyToManyRel, OneToOneRel,
|
|
|
|
)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
|
|
|
|
2006-07-28 10:09:38 +08:00
|
|
|
def permalink(func):
|
2007-07-16 21:47:43 +08:00
|
|
|
"""
|
2015-12-30 23:51:16 +08:00
|
|
|
Decorator that calls urls.reverse() to return a URL using parameters
|
|
|
|
returned by the decorated function "func".
|
2007-07-16 21:47:43 +08:00
|
|
|
|
|
|
|
"func" should be a function that returns a tuple in one of the
|
|
|
|
following formats:
|
|
|
|
(viewname, viewargs)
|
|
|
|
(viewname, viewargs, viewkwargs)
|
|
|
|
"""
|
2015-12-30 23:51:16 +08:00
|
|
|
from django.urls import reverse
|
2013-07-08 08:39:54 +08:00
|
|
|
|
2011-03-14 13:22:39 +08:00
|
|
|
@wraps(func)
|
2006-07-28 10:09:38 +08:00
|
|
|
def inner(*args, **kwargs):
|
|
|
|
bits = func(*args, **kwargs)
|
2006-08-09 22:40:29 +08:00
|
|
|
return reverse(bits[0], None, *bits[1:3])
|
2006-07-28 10:09:38 +08:00
|
|
|
return inner
|