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
e8679f39
authored
Aug 06, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Plain Diff
Resolve marge conflict
parents
15d24c7f
be12f47f
Pipeline
#805
failed with stage
in 1 minute 22 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
90 additions
and
21 deletions
+90
-21
.gitignore
+2
-1
Pipfile
+1
-1
recircle/image/models.py
+24
-2
recircle/image/serializers.py
+10
-2
recircle/image/views.py
+38
-14
recircle/instance/migrations/0010_merge_20190723_0841.py
+14
-0
recircle/interface_openstack
+1
-1
No files found.
.gitignore
View file @
e8679f39
.vscode/
recircle/db
.sqlite3
*
.sqlite3
recircle/clouds.yaml
environment.sh
.idea/
__pycache__
Pipfile
View file @
e8679f39
...
...
@@ -13,11 +13,11 @@ django-nose = "*"
[packages]
django = "*"
djangorestframework = "*"
djoser = "*"
django-cors-headers = "*"
openstacksdk = "*"
python-novaclient = "*"
keystoneauth1 = "*"
djoser = "*"
[requires]
python_version = "3.6"
recircle/image/models.py
View file @
e8679f39
...
...
@@ -82,7 +82,9 @@ class Image(models.Model):
uploaded_by_user
=
False
,
description
=
description
)
return
new_image
for
attr
,
value
in
new_image
.
__dict__
.
items
():
setattr
(
remote_image
,
attr
,
value
)
return
remote_image
@classmethod
def
create_from_user
(
cls
,
description
,
file_format
,
image_file
,
name
,
user
):
...
...
@@ -96,4 +98,24 @@ class Image(models.Model):
uploaded_by_user
=
True
,
description
=
description
)
return
new_image
for
attr
,
value
in
new_image
.
__dict__
.
items
():
setattr
(
remote_image
,
attr
,
value
)
return
remote_image
def
delete
(
self
):
interface
=
OpenstackImageManager
(
settings
.
CONNECTION
)
if
interface
.
delete
(
self
.
remote_id
):
super
()
.
delete
()
def
get
(
self
):
interface
=
OpenstackImageManager
(
settings
.
CONNECTION
)
image
=
interface
.
get
(
self
.
remote_id
)
for
attr
,
value
in
self
.
__dict__
.
items
():
setattr
(
image
,
attr
,
value
)
return
image
def
update
(
self
,
data
):
for
(
key
,
value
)
in
data
.
items
():
setattr
(
self
,
key
,
value
)
self
.
save
()
return
self
.
get
()
recircle/image/serializers.py
View file @
e8679f39
...
...
@@ -3,9 +3,15 @@ from rest_framework import serializers
from
.models
import
Image
class
ImageUpdateSerializer
(
serializers
.
Serializer
):
name
=
serializers
.
CharField
(
required
=
False
)
description
=
serializers
.
CharField
(
required
=
False
)
class
ImageSerializer
(
serializers
.
ModelSerializer
):
image_file
=
serializers
.
FileField
(
write_only
=
True
)
file_format
=
serializers
.
CharField
(
max_length
=
10
,
write_only
=
True
)
file_format
=
serializers
.
CharField
(
max_length
=
10
)
size
=
serializers
.
IntegerField
()
class
Meta
:
model
=
Image
...
...
@@ -18,5 +24,7 @@ class ImageSerializer(serializers.ModelSerializer):
"created_at"
,
"uploaded_by_user"
,
"created_by"
,
"id"
,
"size"
,
)
read_only_fields
=
(
"created_at"
,
"uploaded_by_user"
,
"created_by"
,
"remote_id"
,
)
read_only_fields
=
(
"created_at"
,
"uploaded_by_user"
,
"created_by"
,
"remote_id"
,
"size"
,
)
recircle/image/views.py
View file @
e8679f39
# from django.shortcuts import render
from
rest_framework.viewsets
import
Model
ViewSet
from
rest_framework.viewsets
import
ViewSet
from
rest_framework.response
import
Response
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
(
ModelViewSet
):
serializer_class
=
ImageSerializer
queryset
=
Image
.
objects
.
all
()
# def list(self, request):
# return HttpResponse("list")
class
ImageViewSet
(
ViewSet
):
def
list
(
self
,
request
):
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
)
...
...
@@ -26,14 +34,30 @@ class ImageViewSet(ModelViewSet):
serializer
=
ImageSerializer
(
instance
=
new_image
)
return
Response
(
serializer
.
data
)
# def retrieve(self, request, pk=None):
# return HttpResponse("retrive")
def
retrieve
(
self
,
request
,
pk
=
None
):
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")
def
update
(
self
,
request
,
pk
=
None
):
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"
)
def
partial_update
(
self
,
request
,
pk
=
None
):
return
self
.
update
(
request
,
pk
)
# def destroy(self, request, pk=None):
# return HttpResponse("delete")
def
destroy
(
self
,
request
,
pk
=
None
):
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
)
recircle/instance/migrations/0010_merge_20190723_0841.py
0 → 100644
View file @
e8679f39
# Generated by Django 2.2.3 on 2019-07-23 08:41
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'instance'
,
'0009_auto_20190715_0929'
),
(
'instance'
,
'0009_auto_20190715_1354'
),
]
operations
=
[
]
interface_openstack
@
f1525f93
Subproject commit
e01d873c78ac17fed0438936f979de3cbaca6a5e
Subproject commit
f1525f9340d02647953b3996bc33e5828dedf544
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