Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
CSCMETAX-61: [REF] Refactor modifying the Request object in CommonVie…
Browse files Browse the repository at this point in the history
…wSet to be more sensible
  • Loading branch information
Hannu Kamarainen committed May 25, 2018
1 parent 2968d16 commit 779543b
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/metax_api/api/rest/base/views/common_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.http import Http404
from rest_framework import status
from rest_framework.generics import get_object_or_404
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

Expand Down Expand Up @@ -199,22 +198,10 @@ def initialize_request(self, request, *args, **kwargs):
Overrided from rest_framework to preserve the username set during
identifyapicaller middleware.
"""
username = request.user.username

# original ->
parser_context = self.get_parser_context(request)

req = Request(
request,
parsers=self.get_parsers(),
authenticators=self.get_authenticators(),
negotiator=self.get_content_negotiator(),
parser_context=parser_context
)
# ^ original

req.user.username = username
return req
username = request.user.username if hasattr(request.user, 'username') else None
drf_req = super(CommonViewSet, self).initialize_request(request, *args, **kwargs)
drf_req.user.username = username
return drf_req

def set_json_schema(self, view_file):
"""
Expand Down

0 comments on commit 779543b

Please sign in to comment.