7
7
methods on viewsets that should be included by routers.
8
8
"""
9
9
import types
10
+ from functools import update_wrapper
10
11
11
12
from django .forms .utils import pretty_name
12
13
@@ -22,18 +23,8 @@ def api_view(http_method_names=None):
22
23
23
24
def decorator (func ):
24
25
25
- WrappedAPIView = type (
26
- 'WrappedAPIView' ,
27
- (APIView ,),
28
- {'__doc__' : func .__doc__ }
29
- )
30
-
31
- # Note, the above allows us to set the docstring.
32
- # It is the equivalent of:
33
- #
34
- # class WrappedAPIView(APIView):
35
- # pass
36
- # WrappedAPIView.__doc__ = func.doc <--- Not possible to do this
26
+ class WrappedAPIView (APIView ):
27
+ pass
37
28
38
29
# api_view applied without (method_names)
39
30
assert not (isinstance (http_method_names , types .FunctionType )), \
@@ -52,9 +43,6 @@ def handler(self, *args, **kwargs):
52
43
for method in http_method_names :
53
44
setattr (WrappedAPIView , method .lower (), handler )
54
45
55
- WrappedAPIView .__name__ = func .__name__
56
- WrappedAPIView .__module__ = func .__module__
57
-
58
46
WrappedAPIView .renderer_classes = getattr (func , 'renderer_classes' ,
59
47
APIView .renderer_classes )
60
48
@@ -73,7 +61,7 @@ def handler(self, *args, **kwargs):
73
61
WrappedAPIView .schema = getattr (func , 'schema' ,
74
62
APIView .schema )
75
63
76
- return WrappedAPIView .as_view ()
64
+ return update_wrapper ( WrappedAPIView .as_view (), func )
77
65
78
66
return decorator
79
67
0 commit comments