Hello guys!
I faced a situation when auth backend needs access to request object inside 
of get_user auth backend function

https://code.djangoproject.com/ticket/29005

I can patch it following way (function to be patched is 
django.contrib.auth.get_user)


def get_user(request):
>
 

......
> code
> .....
>          backend = load_backend(backend_path)
>          backend,request = request
> .....
> code
> .....



But I don't like this solution because I'll need to keep my eyes on this 
monkey patch while django upgrade, etc, and it's very dirty hack.

Instead I propose to extend django behaviour using design pattern Builder 
to simplify integration of another apps into django object internals (it 
sounds hacky, but it's safe and simple to implement)

with change I proposed, the patch would be done on django level, we need to 
add

def get_user(request):
>
> ...
> code
> ...
>
>          backend = load_backend(backend_path)
> DjangoObjectBuilder.do_initialize_object(backend, request)
> ....
> code
> ....


and in another django package we subscribe to this object initialization:


def add_request_to_backend(obj, request):
>     obj.request = request
> DjangoObjectBuilder.add_custom_initializer(lambda obj: isinstance(obj, 
> openstack_auth.Backend), add_request_to_backend)




-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/5dffbda9-7239-489e-9530-564df9ab578e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to