Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
권주희
2020-06-12 00:15:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d58dedd2ae0d49dc1346c020eb78015d92b73ce0
d58dedd2
1 parent
5f09800c
add get api
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
5 deletions
backend/api/serializers.py
backend/api/views.py
backend/khudrive/urls.py
backend/api/serializers.py
View file @
d58dedd
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.auth.models
import
Group
from
rest_framework
import
serializers
from
api.models
import
Item
,
SharedItem
from
.models
import
Item
,
SharedItem
,
User
class
UserSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
User
fields
=
[
'url'
,
'username'
,
'email'
,
'groups'
]
fields
=
'__all__'
class
GroupSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
...
...
backend/api/views.py
View file @
d58dedd
...
...
@@ -27,8 +27,11 @@ class UserViewSet(viewsets.ModelViewSet):
"""
queryset
=
User
.
objects
.
all
()
.
order_by
(
'-date_joined'
)
serializer_class
=
UserSerializer
permission_classes
=
[
permissions
.
IsAuthenticated
]
permission_classes
=
[
permissions
.
IsAuthenticatedOrReadOnly
,
permissions
.
AllowAny
,
# IsOwnerOrReadOnly
]
permission_classes_by_action
=
{
'get'
:
[
permissions
.
AllowAny
],
'destroy'
:
[
permissions
.
AllowAny
]}
@csrf_exempt
@action
(
detail
=
False
,
methods
=
[
'POST'
],
permission_classes
=
[
permissions
.
AllowAny
],
url_path
=
'signup'
,
url_name
=
'singup'
)
def
signup
(
self
,
request
):
...
...
@@ -93,6 +96,22 @@ class UserViewSet(viewsets.ModelViewSet):
)
return
JsonResponse
(
status
=
status
.
HTTP_405_METHOD_NOT_ALLOWED
)
def
get
(
self
,
request
,
pk
):
user
=
User
.
objects
.
filter
(
int_id
=
pk
)
data
=
serializers
.
serialize
(
"json"
,
user
)
json_data
=
json
.
loads
(
data
)
res
=
json_data
[
0
][
'fields'
]
res
[
'id'
]
=
json_data
[
0
][
'pk'
]
return
Response
({
'data'
:
res
},
status
=
status
.
HTTP_200_OK
)
def
get_permissions
(
self
):
try
:
# return permission_classes depending on `action`
return
[
permission
()
for
permission
in
self
.
permission_classes_by_action
[
self
.
action
]]
except
KeyError
:
# action is not set return default permission_classes
return
[
permission
()
for
permission
in
self
.
permission_classes
]
class
ItemViewSet
(
viewsets
.
ViewSet
):
...
...
backend/khudrive/urls.py
View file @
d58dedd
...
...
@@ -35,5 +35,6 @@ urlpatterns = [
url
(
r'^<int:pk>/copy/$'
,
views
.
ItemViewSet
.
copy
,
name
=
'copy'
),
url
(
r'^<int:pk>/children/$'
,
views
.
ItemViewSet
.
children
,
name
=
'copy'
),
url
(
r'^signup/$'
,
views
.
UserViewSet
.
signup
,
name
=
'signup'
),
url
(
r'^login/$'
,
views
.
UserViewSet
.
login
,
name
=
'login'
),
]
...
...
Please
register
or
login
to post a comment