Use functools.wraps on the functions returned by our decorators

This lets Django report the correct view name in errors

(imported from commit b21347e7af39cda439125355f99f4fc63fc3bd2f)
This commit is contained in:
Zev Benjamin
2012-11-01 19:23:26 -04:00
parent 0ca46d5abe
commit 7bbde14d78
3 changed files with 12 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
from functools import wraps
import django.core.cache
def cache_with_key(keyfunc):
@@ -11,6 +13,7 @@ def cache_with_key(keyfunc):
def decorator(func):
djcache = django.core.cache.cache
@wraps(func)
def func_with_caching(*args, **kwargs):
key = keyfunc(*args, **kwargs)
val = djcache.get(key)
@@ -36,6 +39,7 @@ def cache(func):
func_uniqifier = '%s-%s' % (func.func_code.co_filename, func.func_name)
@wraps(func)
def keyfunc(*args, **kwargs):
# Django complains about spaces because memcached rejects them
key = func_uniqifier + repr((args, kwargs))