Commit 92303734 authored by Michael Fladischer's avatar Michael Fladischer

Import djoser_0.5.2.orig.tar.gz

parent cf00f564
This diff is collapsed.
...@@ -92,7 +92,7 @@ REST_FRAMEWORK = { ...@@ -92,7 +92,7 @@ REST_FRAMEWORK = {
} }
``` ```
Run migrations this step will create tables for `auth` app: Run migrations - this step will create tables for `auth` app:
$ ./manage.py migrate $ ./manage.py migrate
...@@ -132,10 +132,29 @@ REST_FRAMEWORK = { ...@@ -132,10 +132,29 @@ REST_FRAMEWORK = {
} }
``` ```
Run migrations this step will create tables for `auth` and `authtoken` apps: Run migrations - this step will create tables for `auth` and `authtoken` apps:
$ ./manage.py migrate $ ./manage.py migrate
### JSON Web Token Authentication
`djoser` does not provide support for JSON web token authentication out of the box but
can be enabled by using a library like [djangorestframework-jwt](https://github.com/GetBlimp/django-rest-framework-jwt).
You simply need to route correctly in your `settings.ROOT_URLCONF`. An example would be:
```
import rest_framework_jwt.views
import djoser.views
urlpatterns = [
url(r'^auth/login', rest_framework_jwt.views.obtain_jwt_token), # using JSON web token
url(r'^auth/register', djoser.views.RegistrationView.as_view()),
url(r'^auth/password/reset', djoser.views.PasswordResetView.as_view()),
url(r'^auth/password/reset/confirm', djoser.views.PasswordResetConfirmView.as_view()),
...
]
```
## Settings ## Settings
Optionally add `DJOSER` settings: Optionally add `DJOSER` settings:
...@@ -484,7 +503,7 @@ These validators are run on `/register/` and `/password/reset/confirm/`. ...@@ -484,7 +503,7 @@ These validators are run on `/register/` and `/password/reset/confirm/`.
### SERIALIZERS ### SERIALIZERS
This dictionary is used to update the defaults, so by providing, This dictionary is used to update the defaults, so by providing,
let's say, one key, all the others will still be used. let's say, one key, all the others will still be used.
**Examples** **Examples**
...@@ -494,7 +513,7 @@ let's say, one key, all the others will still be used. ...@@ -494,7 +513,7 @@ let's say, one key, all the others will still be used.
} }
``` ```
**Default**: **Default**:
``` ```
{ {
'activation': 'djoser.serializers.ActivationSerializer', 'activation': 'djoser.serializers.ActivationSerializer',
...@@ -605,9 +624,9 @@ In this extremely short tutorial we are going to mimic the simplest flow: regist ...@@ -605,9 +624,9 @@ In this extremely short tutorial we are going to mimic the simplest flow: regist
## Customization ## Customization
If you need to customize any serializer behavior you can use If you need to customize any serializer behaviour you can use
the DJOSER['SERIALIZERS'] setting to use your own serializer classes in the built-in views. the DJOSER['SERIALIZERS'] setting to use your own serializer classes in the built-in views.
Or if you need to completely change the default djoser behaviour, Or if you need to completely change the default djoser behaviour,
you can always override djoser views with your own custom ones. you can always override djoser views with your own custom ones.
Define custom `urls` instead of reusing `djoser.urls`: Define custom `urls` instead of reusing `djoser.urls`:
...@@ -624,7 +643,7 @@ Define custom view/serializer (inherit from one of `djoser` class) and override ...@@ -624,7 +643,7 @@ Define custom view/serializer (inherit from one of `djoser` class) and override
```python ```python
class CustomRegistrationView(djoser.views.RegistrationView): class CustomRegistrationView(djoser.views.RegistrationView):
def send_email(self, *args, **kwargs): def send_activation_email(self, *args, **kwargs):
your_custom_email_sender(*args, **kwargs) your_custom_email_sender(*args, **kwargs)
``` ```
......
This diff is collapsed.
Django>=1.5 Django>=1.7
djangorestframework>=3.0.0 djangorestframework>=3.0.0
...@@ -35,13 +35,8 @@ class ActionViewMixin(object): ...@@ -35,13 +35,8 @@ class ActionViewMixin(object):
def post(self, request): def post(self, request):
serializer = self.get_serializer(data=request.data) serializer = self.get_serializer(data=request.data)
if serializer.is_valid(): serializer.is_valid(raise_exception=True)
return self.action(serializer) return self._action(serializer)
else:
return response.Response(
data=serializer.errors,
status=status.HTTP_400_BAD_REQUEST,
)
class UserEmailFactoryBase(object): class UserEmailFactoryBase(object):
......
...@@ -86,7 +86,7 @@ class LoginView(utils.ActionViewMixin, generics.GenericAPIView): ...@@ -86,7 +86,7 @@ class LoginView(utils.ActionViewMixin, generics.GenericAPIView):
permissions.AllowAny, permissions.AllowAny,
) )
def action(self, serializer): def _action(self, serializer):
token = utils.login_user(self.request, serializer.user) token = utils.login_user(self.request, serializer.user)
token_serializer_class = serializers.serializers_manager.get('token') token_serializer_class = serializers.serializers_manager.get('token')
return Response( return Response(
...@@ -119,7 +119,7 @@ class PasswordResetView(utils.ActionViewMixin, generics.GenericAPIView): ...@@ -119,7 +119,7 @@ class PasswordResetView(utils.ActionViewMixin, generics.GenericAPIView):
_users = None _users = None
def action(self, serializer): def _action(self, serializer):
for user in self.get_users(serializer.data['email']): for user in self.get_users(serializer.data['email']):
self.send_password_reset_email(user) self.send_password_reset_email(user)
return response.Response(status=status.HTTP_204_NO_CONTENT) return response.Response(status=status.HTTP_204_NO_CONTENT)
...@@ -152,7 +152,7 @@ class SetPasswordView(utils.ActionViewMixin, generics.GenericAPIView): ...@@ -152,7 +152,7 @@ class SetPasswordView(utils.ActionViewMixin, generics.GenericAPIView):
return serializers.serializers_manager.get('set_password_retype') return serializers.serializers_manager.get('set_password_retype')
return serializers.serializers_manager.get('set_password') return serializers.serializers_manager.get('set_password')
def action(self, serializer): def _action(self, serializer):
self.request.user.set_password(serializer.data['new_password']) self.request.user.set_password(serializer.data['new_password'])
self.request.user.save() self.request.user.save()
...@@ -176,7 +176,7 @@ class PasswordResetConfirmView(utils.ActionViewMixin, generics.GenericAPIView): ...@@ -176,7 +176,7 @@ class PasswordResetConfirmView(utils.ActionViewMixin, generics.GenericAPIView):
return serializers.serializers_manager.get('password_reset_confirm_retype') return serializers.serializers_manager.get('password_reset_confirm_retype')
return serializers.serializers_manager.get('password_reset_confirm') return serializers.serializers_manager.get('password_reset_confirm')
def action(self, serializer): def _action(self, serializer):
serializer.user.set_password(serializer.data['new_password']) serializer.user.set_password(serializer.data['new_password'])
serializer.user.save() serializer.user.save()
return response.Response(status=status.HTTP_204_NO_CONTENT) return response.Response(status=status.HTTP_204_NO_CONTENT)
...@@ -192,7 +192,7 @@ class ActivationView(utils.ActionViewMixin, generics.GenericAPIView): ...@@ -192,7 +192,7 @@ class ActivationView(utils.ActionViewMixin, generics.GenericAPIView):
) )
token_generator = default_token_generator token_generator = default_token_generator
def action(self, serializer): def _action(self, serializer):
serializer.user.is_active = True serializer.user.is_active = True
serializer.user.save() serializer.user.save()
signals.user_activated.send( signals.user_activated.send(
...@@ -218,7 +218,7 @@ class SetUsernameView(utils.ActionViewMixin, generics.GenericAPIView): ...@@ -218,7 +218,7 @@ class SetUsernameView(utils.ActionViewMixin, generics.GenericAPIView):
return serializers.serializers_manager.get('set_username_retype') return serializers.serializers_manager.get('set_username_retype')
return serializers.serializers_manager.get('set_username') return serializers.serializers_manager.get('set_username')
def action(self, serializer): def _action(self, serializer):
setattr(self.request.user, User.USERNAME_FIELD, serializer.data['new_' + User.USERNAME_FIELD]) setattr(self.request.user, User.USERNAME_FIELD, serializer.data['new_' + User.USERNAME_FIELD])
self.request.user.save() self.request.user.save()
return response.Response(status=status.HTTP_204_NO_CONTENT) return response.Response(status=status.HTTP_204_NO_CONTENT)
......
#!/usr/bin/env python #!/usr/bin/env python
import io
import os import os
from setuptools import setup from setuptools import setup
try: try:
import pypandoc import pypandoc
description = pypandoc.convert('README.md', 'rst') description = pypandoc.convert('README.md', 'rst')
except (IOError, ImportError): except (IOError, ImportError):
description = open('README.md').read() description = io.open('README.md', encoding='utf-8').read()
def get_packages(package): def get_packages(package):
...@@ -22,7 +24,7 @@ def get_requirements(file_name): ...@@ -22,7 +24,7 @@ def get_requirements(file_name):
setup( setup(
name='djoser', name='djoser',
version='0.5.1', version='0.5.2',
packages=get_packages('djoser'), packages=get_packages('djoser'),
license='MIT', license='MIT',
author='SUNSCRAPERS', author='SUNSCRAPERS',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment