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
08457367
authored
Aug 15, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor models, seializer, urls, admin and views
parent
3a808815
Pipeline
#831
passed with stage
in 1 minute 21 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
32 deletions
+16
-32
recircle/image/admin.py
+1
-2
recircle/image/models.py
+12
-25
recircle/image/serializers.py
+1
-1
recircle/image/urls.py
+1
-0
recircle/image/views.py
+1
-4
No files found.
recircle/image/admin.py
View file @
08457367
from
django.contrib
import
admin
from
image.models
import
Image
from
image.models
import
Disk
from
image.models
import
Image
,
Disk
admin
.
site
.
register
(
Image
)
admin
.
site
.
register
(
Disk
)
recircle/image/models.py
View file @
08457367
...
...
@@ -7,12 +7,14 @@ from interface_openstack.implementation.image.openstack_image_manager import Ope
class
Disk
(
models
.
Model
):
"""A virtual disk.
"""
name
=
models
.
CharField
(
blank
=
True
,
max_length
=
100
,
verbose_name
=
"name"
,
help_text
=
"Name of the disk"
blank
=
True
,
max_length
=
100
,
verbose_name
=
"name"
,
help_text
=
"Name of the disk"
)
remote_id
=
models
.
CharField
(
max_length
=
40
,
...
...
@@ -23,7 +25,6 @@ class Disk(models.Model):
class
Image
(
models
.
Model
):
"""A virtual image.
"""
...
...
@@ -61,48 +62,34 @@ class Image(models.Model):
)
@classmethod
def
create
(
cls
,
name
,
description
,
remote_id
,
uploaded_by_user
,
created_by
):
inst
=
cls
(
name
=
name
,
description
=
description
,
uploaded_by_user
=
uploaded_by_user
,
remote_id
=
remote_id
,
created_by
=
created_by
)
inst
.
full_clean
()
inst
.
save
()
return
inst
@classmethod
def
create_from_instance
(
cls
,
user
,
instance
,
description
):
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
remote_image
=
interface
.
create_image
(
instance
.
remote_id
)
remote_id
=
remote_image
.
id
name
=
remote_image
.
name
new_image
=
cls
.
create
(
name
=
name
,
new_image
=
Image
.
objects
.
create
(
name
=
name
,
remote_id
=
remote_id
,
created_by
=
user
,
uploaded_by_user
=
False
,
description
=
description
)
for
attr
,
value
in
new_image
.
__dict__
.
items
():
setattr
(
remote_image
,
attr
,
value
)
return
remote_image
description
=
description
)
return
new_image
@classmethod
def
create_from_user
(
cls
,
description
,
file_format
,
image_file
,
name
,
user
):
interface
=
OpenstackImageManager
(
settings
.
CONNECTION
)
remote_image
=
interface
.
upload_file
(
name
=
name
,
path
=
image_file
.
temporary_file_path
(),
remote_image
=
interface
.
upload_file
(
name
=
name
,
path
=
image_file
.
temporary_file_path
(),
format
=
file_format
)
new_image
=
cls
.
create
(
name
=
name
,
new_image
=
Image
.
objects
.
create
(
name
=
name
,
remote_id
=
remote_image
.
id
,
created_by
=
user
,
uploaded_by_user
=
True
,
description
=
description
)
description
=
description
)
for
attr
,
value
in
new_image
.
__dict__
.
items
():
setattr
(
remote_image
,
attr
,
value
)
return
remote_image
def
delete
(
self
):
def
delete
(
self
,
**
kwargs
):
interface
=
OpenstackImageManager
(
settings
.
CONNECTION
)
if
interface
.
delete
(
self
.
remote_id
):
super
()
.
delete
()
...
...
recircle/image/serializers.py
View file @
08457367
...
...
@@ -11,7 +11,7 @@ class ImageUpdateSerializer(serializers.Serializer):
class
ImageSerializer
(
serializers
.
ModelSerializer
):
image_file
=
serializers
.
FileField
(
write_only
=
True
)
file_format
=
serializers
.
CharField
(
max_length
=
10
)
size
=
serializers
.
IntegerField
()
size
=
serializers
.
IntegerField
(
read_only
=
True
)
class
Meta
:
model
=
Image
...
...
recircle/image/urls.py
View file @
08457367
from
rest_framework
import
routers
from
image
import
views
router
=
routers
.
DefaultRouter
()
...
...
recircle/image/views.py
View file @
08457367
# from django.shortcuts import render
from
rest_framework.viewsets
import
ViewSet
from
rest_framework.response
import
Response
from
django.shortcuts
import
get_object_or_404
...
...
@@ -6,8 +5,7 @@ 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
from
image.serializers
import
ImageSerializer
,
ImageUpdateSerializer
class
ImageViewSet
(
ViewSet
):
...
...
@@ -37,7 +35,6 @@ class ImageViewSet(ViewSet):
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
)
...
...
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