Fix code formatting

This commit is contained in:
Bruno Alla 2020-01-23 15:04:30 +00:00
parent 2833600aec
commit fa9a8cfe7b
5 changed files with 16 additions and 17 deletions

View File

@ -7,8 +7,8 @@ if settings.DEBUG:
else:
router = SimpleRouter()
router.register('users', UserViewSet)
router.register("users", UserViewSet)
app_name = 'api'
app_name = "api"
urlpatterns = router.urls

View File

@ -308,13 +308,11 @@ STATICFILES_FINDERS += ["compressor.finders.CompressorFinder"]
# -------------------------------------------------------------------------------
# django-rest-framework - https://www.django-rest-framework.org/api-guide/settings/
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
"DEFAULT_AUTHENTICATION_CLASSES": (
"rest_framework.authentication.SessionAuthentication",
"rest_framework.authentication.TokenAuthentication",
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
)
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
}
{%- endif %}
# Your stuff...

View File

@ -24,9 +24,10 @@ urlpatterns = [
# API URLS
urlpatterns += [
# API base url
path("api/", include('config.api_router')),
path("api/", include("config.api_router")),
# DRF auth token
path("auth-token/", obtain_auth_token)]
path("auth-token/", obtain_auth_token),
]
{%- endif %}
if settings.DEBUG:

View File

@ -1,12 +1,12 @@
from rest_framework import serializers
from {{ cookiecutter.project_slug }}.users.models import User
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['username', 'email', 'name', 'url']
fields = ["username", "email", "name", "url"]
extra_kwargs = {
'url': {'view_name': 'api:user-detail', 'lookup_field': 'username'}
"url": {"view_name": "api:user-detail", "lookup_field": "username"}
}

View File

@ -5,20 +5,20 @@ from rest_framework.mixins import RetrieveModelMixin, ListModelMixin, UpdateMode
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from .serializers import UserSerializer
User = get_user_model()
class UserViewSet(RetrieveModelMixin, ListModelMixin, UpdateModelMixin, GenericViewSet):
serializer_class = UserSerializer
queryset = User.objects.all()
lookup_field = 'username'
lookup_field = "username"
def get_queryset(self, *args, **kwargs):
return self.queryset.filter(id=self.request.user.id)
@action(detail=False, methods=['GET'])
@action(detail=False, methods=["GET"])
def me(self, request):
serializer = UserSerializer(request.user, context={'request': request})
serializer = UserSerializer(request.user, context={"request": request})
return Response(status=status.HTTP_200_OK, data=serializer.data)