Skip to content

Commit

Permalink
feat(access): add back and return_url urls to team user metadata
Browse files Browse the repository at this point in the history
ref: #410 #411
  • Loading branch information
jon-nfc committed Nov 30, 2024
1 parent c8b6a31 commit 7c9320a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/access/viewsets/team_user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiParameter, OpenApiResponse

from access.models import Team

from access.serializers.team_user import (
TeamUsers,
TeamUserModelSerializer,
Expand Down Expand Up @@ -147,6 +149,24 @@ class ViewSet( ModelViewSet ):

view_description = 'Users belonging to a single team'


def get_back_url(self) -> str:

if(
getattr(self, '_back_url', None) is None
):

return_model =Team.objects.get(
pk = self.kwargs['team_id']
)

self._back_url = str(
return_model.get_url( self.request )
)

return self._back_url


def get_queryset(self):

queryset = super().get_queryset()
Expand All @@ -172,3 +192,21 @@ def get_serializer_class(self):

return globals()[str( self.model._meta.verbose_name).replace(' ', '') + 'ModelSerializer']


def get_return_url(self):

if getattr(self, '_get_return_url', None):

return self._get_return_url

if self.kwargs.get('pk', None) is None:

return_model = Team.objects.get(
pk = self.kwargs['team_id']
)

self._get_return_url = return_model.get_url( self.request )

return self._get_return_url

return None

0 comments on commit 7c9320a

Please sign in to comment.