From f25170a0a98f982f01ca5d93425ce85477bd930e Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Mon, 18 Jun 2018 10:41:28 +0200 Subject: [PATCH] api for username --- src/api/handlers.py | 10 ++++++---- src/api/urls.py | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api/handlers.py b/src/api/handlers.py index 3e4e0931a..ab1a44a52 100644 --- a/src/api/handlers.py +++ b/src/api/handlers.py @@ -656,16 +656,18 @@ class PictureHandler(BaseHandler): class UserDataHandler(BaseHandler): model = BookUserData - fields = ('state',) + fields = ('state', 'username') allowed_methods = ('GET', 'POST') - def read(self, request, slug): + def read(self, request, slug=None): + if not request.user.is_authenticated(): + return rc.FORBIDDEN + if slug is None: + return {'username': request.user.username} try: book = Book.objects.get(slug=slug) except Book.DoesNotExist: return rc.NOT_FOUND - if not request.user.is_authenticated(): - return rc.FORBIDDEN try: data = BookUserData.objects.get(book=book, user=request.user) except BookUserData.DoesNotExist: diff --git a/src/api/urls.py b/src/api/urls.py index 006abed60..f90ec3e7d 100644 --- a/src/api/urls.py +++ b/src/api/urls.py @@ -80,6 +80,7 @@ urlpatterns = [ url(r'^reading/(?P[a-z0-9-]+)/$', reading_resource, name='api_reading'), url(r'^reading/(?P[a-z0-9-]+)/(?P[a-z]+)/$', reading_resource, name='api_reading'), url(r'^shelf/(?P[a-z]+)/$', shelf_resource, name='api_shelf'), + url(r'^username/$', reading_resource, name='api_username'), # objects details url(r'^books/(?P[a-z0-9-]+)/$', book_resource, name="api_book"), -- 2.20.1