Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
JoinTheCity
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafal
JoinTheCity
Commits
b9bf2a9e
Commit
b9bf2a9e
authored
Jan 16, 2016
by
Rafal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now u can add api to user
parent
66d77566
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
views.py
JoinTheCityREST/app/API/views.py
+13
-2
No files found.
JoinTheCityREST/app/API/views.py
View file @
b9bf2a9e
...
@@ -2,11 +2,12 @@
...
@@ -2,11 +2,12 @@
from
django.http
import
HttpResponse
,
Http404
from
django.http
import
HttpResponse
,
Http404
from
rest_framework
import
viewsets
,
permissions
from
rest_framework
import
viewsets
,
permissions
import
rest_framework
import
rest_framework
from
rest_framework.decorators
import
detail_route
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
app.API.models
import
API
,
APIType
from
app.API.models
import
API
,
APIType
from
app.API.serializers
import
APISerializer
,
APITypeSerializer
from
app.API.serializers
import
APISerializer
,
APITypeSerializer
from
app.User.models
import
UserAPI
from
app.User.models
import
UserAPI
from
django.shortcuts
import
get_object_or_404
class
APIViewSet
(
viewsets
.
ModelViewSet
):
class
APIViewSet
(
viewsets
.
ModelViewSet
):
"""
"""
...
@@ -16,8 +17,19 @@ class APIViewSet(viewsets.ModelViewSet):
...
@@ -16,8 +17,19 @@ class APIViewSet(viewsets.ModelViewSet):
serializer_class
=
APISerializer
serializer_class
=
APISerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
@
staticmethod
def
add
(
request
,
pk
=
None
):
api
=
get_object_or_404
(
APIViewSet
.
queryset
,
pk
=
pk
)
user
=
request
.
user
user_api
=
UserAPI
(
user
=
user
,
api
=
api
)
user_api
.
save
()
return
Response
(
status
=
rest_framework
.
status
.
HTTP_200_OK
)
@
staticmethod
@
staticmethod
def
test
(
request
,
id
,
function
,
slash
):
def
test
(
request
,
id
,
function
,
slash
):
if
function
==
'add'
:
APIViewSet
.
add
(
request
,
id
)
try
:
try
:
object
=
API
.
objects
.
get
(
pk
=
id
)
object
=
API
.
objects
.
get
(
pk
=
id
)
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -29,7 +41,6 @@ class APIViewSet(viewsets.ModelViewSet):
...
@@ -29,7 +41,6 @@ class APIViewSet(viewsets.ModelViewSet):
return
HttpResponse
(
api
.
execute
(
function
),
content_type
=
"application/json"
)
return
HttpResponse
(
api
.
execute
(
function
),
content_type
=
"application/json"
)
def
get_queryset
(
self
):
def
get_queryset
(
self
):
queryset
=
API
.
objects
.
all
()
queryset
=
API
.
objects
.
all
()
username
=
self
.
request
.
query_params
.
get
(
'only_new'
,
None
)
username
=
self
.
request
.
query_params
.
get
(
'only_new'
,
None
)
if
username
is
not
None
:
if
username
is
not
None
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment