zsoldosp / django-currentuser

Conveniently store reference to request user on thread/db level.
BSD 3-Clause "New" or "Revised" License
139 stars 40 forks source link

add support for new style middleware #6

Closed JavierGonza closed 6 years ago

JavierGonza commented 6 years ago

Now you can use old and style middleware in django >=1.10, use settings.MIDDLEWARE or settings.MIDDLEWARE_CLASSES

belugame commented 6 years ago

Hello @JavierGonza and thank you very much for your contribution.

I understand that you want to extend the compability with the supported django versions, which is always welcome. Though I look at the django documentation and see that the class (inheriting from object) is already the current 1.11 approach.

see: https://docs.djangoproject.com/en/1.11/topics/http/middleware/#writing-your-own-middleware

Could you give more details in what problems you ran and what django version you are using?

JavierGonza commented 6 years ago

If u try to use your middleware in settings.MIDDLEWARE you get an error like this: ... self.load_middleware() mw_instance = middleware(handler) TypeError: object() takes no parameters That happends in django>=1.10 and because your class is like old-style and try to run with new-style settings

Your middleware is written in old-style middleware and we need to adapt it to new-style if we want to use it with settings.MIDDLEWARE( new style) instead of settings.MIDDLEWARE_CLASSES (old style). That happens in django >=1.10, with this patch, we can use your custom middleware in both settings. see:

belugame commented 6 years ago

Ah now I see, you are right, that did not work. Please check out https://github.com/PaesslerAG/django-currentuser/pull/7 where I avoided using MiddlewareMixin.