7
7
methods on viewsets that should be included by routers.
8
8
"""
9
9
import types
10
- from functools import update_wrapper
11
10
12
11
from django .forms .utils import pretty_name
13
12
@@ -23,8 +22,18 @@ def api_view(http_method_names=None):
23
22
24
23
def decorator (func ):
25
24
26
- class WrappedAPIView (APIView ):
27
- pass
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
28
37
29
38
# api_view applied without (method_names)
30
39
assert not (isinstance (http_method_names , types .FunctionType )), \
@@ -43,6 +52,9 @@ def handler(self, *args, **kwargs):
43
52
for method in http_method_names :
44
53
setattr (WrappedAPIView , method .lower (), handler )
45
54
55
+ WrappedAPIView .__name__ = func .__name__
56
+ WrappedAPIView .__module__ = func .__module__
57
+
46
58
WrappedAPIView .renderer_classes = getattr (func , 'renderer_classes' ,
47
59
APIView .renderer_classes )
48
60
@@ -61,7 +73,7 @@ def handler(self, *args, **kwargs):
61
73
WrappedAPIView .schema = getattr (func , 'schema' ,
62
74
APIView .schema )
63
75
64
- return update_wrapper ( WrappedAPIView .as_view (), func )
76
+ return WrappedAPIView .as_view ()
65
77
66
78
return decorator
67
79
0 commit comments