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
256a2690
authored
Oct 02, 2019
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create returns the whole object, the merging in retrieve extracted to a function
parent
a824aa69
Pipeline
#904
passed with stage
in 1 minute 21 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
7 deletions
+16
-7
recircle/instance/views.py
+16
-7
No files found.
recircle/instance/views.py
View file @
256a2690
...
...
@@ -56,6 +56,18 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
except
Instance
.
DoesNotExist
:
raise
Http404
def
get_merged_object
(
self
,
pk
):
instance
=
self
.
get_object
(
pk
)
instanceDict
=
InstanceSerializer
(
instance
)
.
data
remoteInstance
=
instance
.
get_remote_instance
()
remoteInstanceDict
=
{
"remote_id"
:
remoteInstance
.
id
,
"status"
:
remoteInstance
.
status
,
"disks"
:
remoteInstance
.
disks
,
"addresses"
:
remoteInstance
.
addresses
,
}
return
({
**
instanceDict
,
**
remoteInstanceDict
})
def
list
(
self
,
request
):
instances
=
self
.
get_objects_with_perms
(
request
.
user
,
"list"
,
Instance
)
return
Response
(
InstanceSerializer
(
instances
,
many
=
True
)
.
data
)
...
...
@@ -87,7 +99,8 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
owner
=
request
.
user
,
disks
=
None
)
return
Response
(
newInstance
.
pk
)
return
Response
(
InstanceSerializer
(
newInstance
)
.
data
)
def
retrieve
(
self
,
request
,
pk
):
instance
=
self
.
get_object
(
pk
)
...
...
@@ -95,13 +108,9 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
return
Response
({
"error"
:
"No permission to access the Virtual Machine."
},
status
=
status
.
HTTP_401_UNAUTHORIZED
)
instanceDict
=
InstanceSerializer
(
instance
)
.
data
remoteInstance
=
instance
.
get_remote_instance
()
remoteInstanceDict
=
remoteInstance
.
__dict__
mergedInstance
=
self
.
get_merged_object
(
pk
)
merged_dict
=
{
**
instanceDict
,
**
remoteInstanceDict
}
return
Response
(
merged_dict
)
return
Response
(
mergedInstance
)
def
update
(
self
,
request
,
pk
,
format
=
None
):
if
request
.
data
[
"action"
]
in
update_actions
:
...
...
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