Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
portal
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
11
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d7a58537
authored
Jul 23, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement vieset functions
parent
71726083
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
10 deletions
+29
-10
recircle/image/views.py
+29
-10
No files found.
recircle/image/views.py
View file @
d7a58537
...
...
@@ -3,17 +3,23 @@ from rest_framework.viewsets import ViewSet
from
rest_framework.response
import
Response
from
django.http
import
HttpResponse
from
django.shortcuts
import
get_object_or_404
from
rest_framework
import
status
from
django.core.exceptions
import
ObjectDoesNotExist
from
image.models
import
Image
from
image.serializers
import
ImageSerializer
from
image.serializers
import
ImageUpdateSerializer
class
ImageViewSet
(
ViewSet
):
def
list
(
self
,
request
):
images
=
Image
.
object
.
all
()
serializer
=
ImageSerializer
(
images
,
many
=
True
)
return
HttpResponse
(
serializer
.
data
)
image_list
=
[]
images
=
Image
.
objects
.
all
()
for
image
in
images
:
image_list
.
append
(
image
.
get
())
serializer
=
ImageSerializer
(
image_list
,
many
=
True
)
return
Response
(
serializer
.
data
)
def
create
(
self
,
request
):
serializer
=
ImageSerializer
(
data
=
request
.
data
)
...
...
@@ -30,17 +36,30 @@ class ImageViewSet(ViewSet):
return
Response
(
serializer
.
data
)
def
retrieve
(
self
,
request
,
pk
=
None
):
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
queryset
=
Image
.
objects
.
all
()
image
=
get_object_or_404
(
queryset
,
pk
=
pk
)
serializer
=
ImageSerializer
(
instance
=
image
)
image
=
image
.
get
()
serializer
=
ImageSerializer
(
instance
=
image
)
return
Response
(
serializer
.
data
)
def
update
(
self
,
request
,
pk
=
None
):
return
HttpResponse
(
"update"
)
serializer
=
ImageUpdateSerializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
queryset
=
Image
.
objects
.
all
()
image
=
get_object_or_404
(
queryset
,
pk
=
pk
)
image
=
image
.
update
(
serializer
.
validated_data
)
serializer
=
ImageSerializer
(
instance
=
image
)
return
Response
(
serializer
.
data
)
def
partial_update
(
self
,
request
,
pk
=
None
):
return
HttpResponse
(
"patch"
)
return
self
.
update
(
request
,
pk
)
def
destroy
(
self
,
request
,
pk
=
None
):
queryset
=
Image
.
objects
.
all
()
image
=
get_object_or_404
(
queryset
,
pk
=
pk
)
image
.
delete
()
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
try
:
image
=
Image
.
objects
.
get
(
id
=
pk
)
image
.
delete
()
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
except
ObjectDoesNotExist
:
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
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