diff --git a/CHANGELOG.md b/CHANGELOG.md index 9717435e..a0b1437e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +3.6.0 +===== + +- The user serializer for each `LoginView`is now dynamic + + 3.5.0 ===== diff --git a/docs/changes.md b/docs/changes.md index c9149bb0..3d281e8c 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,5 +1,9 @@ # Changelog +## 3.6.0 + +- The user serializer for each `LoginView`is now dynamic + ## 3.5.0 - The context, token TTL and tokens per user settings in `LoginView` are now dynamic diff --git a/docs/views.md b/docs/views.md index f313cf27..5db2c78f 100644 --- a/docs/views.md +++ b/docs/views.md @@ -18,6 +18,7 @@ helper methods: - `get_context`, to change the context passed to the `UserSerializer` - `get_token_ttl`, to change the token ttl - `get_token_limit_per_user`, to change the number of tokens available for a user +- `get_user_serializer_class`, to change the class used for serializing the user --- When the endpoint authenticates a request, a json object will be returned diff --git a/knox/views.py b/knox/views.py index db464a74..d463e78b 100644 --- a/knox/views.py +++ b/knox/views.py @@ -25,6 +25,9 @@ def get_token_ttl(self): def get_token_limit_per_user(self): return knox_settings.TOKEN_LIMIT_PER_USER + def get_user_serializer_class(self): + return knox_settings.USER_SERIALIZER + def post(self, request, format=None): token_limit_per_user = self.get_token_limit_per_user() if token_limit_per_user is not None: @@ -39,11 +42,11 @@ def post(self, request, format=None): token = AuthToken.objects.create(request.user, token_ttl) user_logged_in.send(sender=request.user.__class__, request=request, user=request.user) - UserSerializer = knox_settings.USER_SERIALIZER + UserSerializer = self.get_user_serializer_class() if UserSerializer is None: - return Response( - {'token': token} - ) + return Response({ + 'token': token + }) context = self.get_context() return Response({ 'user': UserSerializer(request.user, context=context).data, diff --git a/setup.py b/setup.py index 71b7eab0..2c4a77fb 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='3.5.0', + version='3.6.0', description='Authentication for django rest framework', long_description=long_description, long_description_content_type='text/markdown',