@@ -33,6 +33,12 @@ class Action(models.Model):
33
33
pass
34
34
35
35
36
+ def decorate (fn ):
37
+ def wrapper (self , request , * args , ** kwargs ):
38
+ return fn (self , request , * args , ** kwargs )
39
+ return wrapper
40
+
41
+
36
42
class ActionViewSet (GenericViewSet ):
37
43
queryset = Action .objects .all ()
38
44
@@ -62,6 +68,16 @@ def custom_detail_action(self, request, *args, **kwargs):
62
68
def unresolvable_detail_action (self , request , * args , ** kwargs ):
63
69
raise NotImplementedError
64
70
71
+ @action (detail = False )
72
+ @decorate
73
+ def wrapped_list_action (self , request , * args , ** kwargs ):
74
+ raise NotImplementedError
75
+
76
+ @action (detail = True )
77
+ @decorate
78
+ def wrapped_detail_action (self , request , * args , ** kwargs ):
79
+ raise NotImplementedError
80
+
65
81
66
82
class ActionNamesViewSet (GenericViewSet ):
67
83
@@ -157,6 +173,8 @@ def test_extra_actions(self):
157
173
'detail_action' ,
158
174
'list_action' ,
159
175
'unresolvable_detail_action' ,
176
+ 'wrapped_list_action' ,
177
+ 'wrapped_detail_action' ,
160
178
]
161
179
162
180
self .assertEqual (actual , expected )
@@ -172,6 +190,7 @@ def test_list_view(self):
172
190
expected = OrderedDict ([
173
191
('Custom list action' , 'http://testserver/api/actions/custom_list_action/' ),
174
192
('List action' , 'http://testserver/api/actions/list_action/' ),
193
+ ('Wrapped list action' , 'http://testserver/api/actions/wrapped_list_action/' ),
175
194
])
176
195
177
196
self .assertEqual (view .get_extra_action_url_map (), expected )
@@ -183,6 +202,7 @@ def test_detail_view(self):
183
202
expected = OrderedDict ([
184
203
('Custom detail action' , 'http://testserver/api/actions/1/custom_detail_action/' ),
185
204
('Detail action' , 'http://testserver/api/actions/1/detail_action/' ),
205
+ ('Wrapped detail action' , 'http://testserver/api/actions/wrapped_detail_action/' ),
186
206
# "Unresolvable detail action" excluded, since it's not resolvable
187
207
])
188
208
0 commit comments