Skip to content

Commit

Permalink
Add optional flag to get IP by object_identifier_value
Browse files Browse the repository at this point in the history
  • Loading branch information
OskarPersson committed Feb 10, 2018
1 parent 777929c commit 9d29068
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ESSArch_TP/ip/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from django.db import IntegrityError
from django.db.models import Prefetch
from django.http import HttpResponse
from django.shortcuts import get_object_or_404

from django_filters.rest_framework import DjangoFilterBackend

Expand Down Expand Up @@ -157,6 +158,33 @@ def get_permissions(self):

return super(InformationPackageViewSet, self).get_permissions()

def get_object(self):
queryset = self.filter_queryset(self.get_queryset())

# Perform the lookup filtering.
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field

assert lookup_url_kwarg in self.kwargs, (
'Expected view %s to be called with a URL keyword argument '
'named "%s". Fix your URL conf, or set the `.lookup_field` '
'attribute on the view correctly.' %
(self.__class__.__name__, lookup_url_kwarg)
)

lookup_field = self.lookup_field

objid = self.request.query_params.get('objid')
if objid is not None:
lookup_field = 'object_identifier_value'

filter_kwargs = {lookup_field: self.kwargs[lookup_url_kwarg]}
obj = get_object_or_404(queryset, **filter_kwargs)

# May raise a permission denied
self.check_object_permissions(self.request, obj)

return obj

def get_queryset(self):
user = self.request.user
queryset = InformationPackage.objects.visible_to_user(user)
Expand Down

0 comments on commit 9d29068

Please sign in to comment.