mirror of https://github.com/zulip/zulip.git
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:
parent
0ca46d5abe
commit
7bbde14d78
|
@ -1,3 +1,5 @@
|
|||
from functools import wraps
|
||||
|
||||
import types
|
||||
|
||||
class TornadoAsyncException(Exception): pass
|
||||
|
@ -10,6 +12,7 @@ def returnResponse(value):
|
|||
raise _DefGen_Return(value)
|
||||
|
||||
def asynchronous(method):
|
||||
@wraps(method)
|
||||
def wrapper(request, *args, **kwargs):
|
||||
try:
|
||||
v = method(request, request._tornado_handler, *args, **kwargs)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -25,6 +25,8 @@ from zephyr.lib.avatar import gravatar_hash
|
|||
|
||||
from confirmation.models import Confirmation
|
||||
|
||||
from functools import wraps
|
||||
|
||||
import datetime
|
||||
import simplejson
|
||||
import socket
|
||||
|
@ -38,6 +40,7 @@ import base64
|
|||
SERVER_GENERATION = int(time.time())
|
||||
|
||||
def require_post(view_func):
|
||||
@wraps(view_func)
|
||||
def _wrapped_view_func(request, *args, **kwargs):
|
||||
if request.method != "POST":
|
||||
return json_error('This form can only be submitted by POST.')
|
||||
|
@ -50,6 +53,7 @@ def require_post(view_func):
|
|||
def authenticated_api_view(view_func):
|
||||
@csrf_exempt
|
||||
@require_post
|
||||
@wraps(view_func)
|
||||
def _wrapped_view_func(request, *args, **kwargs):
|
||||
try:
|
||||
user_profile = UserProfile.objects.get(user__email=request.POST.get("email"))
|
||||
|
@ -65,6 +69,7 @@ def authenticated_api_view(view_func):
|
|||
# redirecting to a login page doesn't make sense for json views)
|
||||
def authenticated_json_view(view_func):
|
||||
@require_post
|
||||
@wraps(view_func)
|
||||
def _wrapped_view_func(request, *args, **kwargs):
|
||||
if not request.user.is_authenticated():
|
||||
return json_error("Not logged in")
|
||||
|
|
Loading…
Reference in New Issue