1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

Example code for capturing current user from rest framework.

This commit is contained in:
Chris Church 2013-11-20 00:25:09 -05:00
parent e4851c6e18
commit b73e792b23
2 changed files with 12 additions and 0 deletions

View File

@ -70,6 +70,15 @@ def get_view_description(cls, html=False):
class APIView(views.APIView):
def initialize_request(self, request, *args, **kwargs):
'''
Store the Django REST Framework Request object as an attribute on the
normal Django request.
'''
drf_request = super(APIView, self).initialize_request(request, *args, **kwargs)
request.drf_request = drf_request
return drf_request
def get_authenticate_header(self, request):
"""
Determine the WWW-Authenticate header to use for 401 responses. Try to

View File

@ -24,6 +24,9 @@ class ActivityStreamMiddleware(object):
post_save.connect(set_actor, sender=ActivityStream, dispatch_uid=self.disp_uid, weak=False)
def process_response(self, request, response):
drf_request = getattr(request, 'drf_request', None)
drf_user = getattr(drf_request, 'user', None)
# FIXME: Associate the user above from Django REST framework with instances.
post_save.disconnect(dispatch_uid=self.disp_uid)
self.finished = True
if self.isActivityStreamEvent: