Skip to content

Commit

Permalink
general changes:
Browse files Browse the repository at this point in the history
* updating docs
  • Loading branch information
Ori-Roza committed May 12, 2024
1 parent bae5dcc commit 321a7b7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions drf_api_action/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

def run_function(self, func):
def api_item(*args, **kwargs):
# here we retrieve serializer_class from @action decorator in order to inject it to the ViewSet
serializer_class = func.kwargs['serializer_class']
return run_as_api(self, func, serializer_class, *args, **kwargs)

Expand Down
7 changes: 4 additions & 3 deletions drf_api_action/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ def build_absolute_uri(self, _=None):

def run_as_api(self, func, serializer_class, *args, **kw):
# adding to the view the request & kwargs including the serializer class
kw.update({"serializer_class": serializer_class})
kw.update({"serializer_class": serializer_class}) # adding serializer class from @action
# decorator into our instance
request = CustomRequest(kw, kw)
self.kwargs = kw
self.request = request
self.kwargs = kw # adding our enhanced kwargs into instance kwargs
self.request = request # mocking request with our arguments as data in the instance

try:
ret = func(request, **kw)
Expand Down
1 change: 1 addition & 0 deletions tests/test_server/test_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def api_dummy(self, request, **kwargs):

@action(detail=False, methods=["post"], serializer_class=GetDummyByIntSerializer)
def by_dummy_int(self, request, **kwargs):
breakpoint()
self.get_serializer(data=request.data).is_valid(raise_exception=True)
queryset = DummyModel.objects.filter(dummy_int=request.data["dummy_int"]).order_by("id")
page = self.paginate_queryset(queryset)
Expand Down

0 comments on commit 321a7b7

Please sign in to comment.