drf-tracking icon indicating copy to clipboard operation
drf-tracking copied to clipboard

Middleware support

Open inforian opened this issue 8 years ago • 3 comments

  • Instead of importing Mixin in every View, Do this job using middleware is more durable.

inforian avatar Sep 04 '17 10:09 inforian

  • Sorry I was crating the pull request on my fork but instead created on Parent repo. So you can ignore This pull request.

  • However if you liked the idea , I can explain what I did and why ? and can write test cases too

inforian avatar Sep 04 '17 10:09 inforian

@inforian Thanks for making a PR. If you can briefly explain how this betters the library I am all for it. Write somes tests would be great. Lastly, add some quick documentation on how it should be installed. Would this be a breaking change for current users? Or would does it compliment the mixin?

avelis avatar Sep 08 '17 04:09 avelis

  • The main idea is to avoid redundancy of using Mixin in every viewset. Instead their must be a way where you have to mention just once and that will be applicable everywhere (Some configurable settings can be provided).

  • So I decided to write a Django middleware for the same which will use this mixin functions like :

    • In process_request -> initial
    • process_exception -> handle_exception
    • process_response -> finalize_response
  • But during Implementation I faced some issues like : - Your Mixin use DRF Request Object but Middleware will pass HttpRequest object , So some things may not be accessible in Mixin like request.data .

    • In finalize_response some response do not have rendered_content
    • calling super_class super(BaseLoggingMixin, self).any_function(request, *args, **kwargs)
  • However I fixed above issues but then I realize This repo aims at DRF not Django , So a Middlware won't be a good option. But I still think there must be a single way of enabling this logging functionality instead of use Mixin in every Viewset.

  • So I wanted to contribute and enable above functionality (keeping the old one too) but first I wanted to know your views and Any thoughts on what will be the best way to do so ?

inforian avatar Sep 08 '17 07:09 inforian