2013-05-04 17:53:12 +08:00
|
|
|
from functools import wraps
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
|
2013-06-04 14:13:36 +08:00
|
|
|
from django.db.models.loading import get_apps, get_app_paths, get_app, get_models, get_model, register_models, UnavailableApp
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.db.models.query import Q
|
2009-01-29 18:46:36 +08:00
|
|
|
from django.db.models.expressions import F
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.db.models.manager import Manager
|
2008-07-19 07:54:34 +08:00
|
|
|
from django.db.models.base import Model
|
2009-01-15 19:06:34 +08:00
|
|
|
from django.db.models.aggregates import *
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.db.models.fields import *
|
2007-11-05 21:59:42 +08:00
|
|
|
from django.db.models.fields.subclassing import SubfieldBase
|
2008-08-09 04:59:02 +08:00
|
|
|
from django.db.models.fields.files import FileField, ImageField
|
2013-03-25 00:40:40 +08:00
|
|
|
from django.db.models.fields.related import ForeignKey, ForeignObject, OneToOneField, ManyToManyField, ManyToOneRel, ManyToManyRel, OneToOneRel
|
2011-01-20 08:33:32 +08:00
|
|
|
from django.db.models.deletion import CASCADE, PROTECT, SET, SET_NULL, SET_DEFAULT, DO_NOTHING, ProtectedError
|
2006-05-02 09:31:56 +08:00
|
|
|
from django.db.models import signals
|
|
|
|
|
|
|
|
|
2006-07-28 10:09:38 +08:00
|
|
|
def permalink(func):
|
2007-07-16 21:47:43 +08:00
|
|
|
"""
|
|
|
|
Decorator that calls urlresolvers.reverse() to return a URL using
|
|
|
|
parameters returned by the decorated function "func".
|
|
|
|
|
|
|
|
"func" should be a function that returns a tuple in one of the
|
|
|
|
following formats:
|
|
|
|
(viewname, viewargs)
|
|
|
|
(viewname, viewargs, viewkwargs)
|
|
|
|
"""
|
2006-07-28 10:09:38 +08:00
|
|
|
from django.core.urlresolvers import reverse
|
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
|