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
1a9a8829
authored
Apr 06, 2020
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Template list now uses new serializer
parent
a63c5cd1
Pipeline
#1045
failed with stage
in 2 minutes 23 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
3 deletions
+20
-3
recircle/template/serializers.py
+11
-0
recircle/template/urls.py
+1
-1
recircle/template/views.py
+8
-2
No files found.
recircle/template/serializers.py
View file @
1a9a8829
from
rest_framework
import
serializers
from
template.models
import
ImageTemplate
from
instance.serializers
import
FlavorSerializer
,
LeaseSerializer
class
ImageTemplateListItemSerializer
(
serializers
.
ModelSerializer
):
flavor
=
FlavorSerializer
(
read_only
=
True
)
lease
=
LeaseSerializer
(
read_only
=
True
)
class
Meta
:
model
=
ImageTemplate
fields
=
[
"id"
,
"name"
,
"distro"
,
"flavor"
,
"lease"
,
"system_type"
]
read_only_fields
=
(
"id"
,
"name"
,
"distro"
,
"flavor"
,
"lease"
,
"system_type"
)
class
InstanceFromTemplateSerializer
(
serializers
.
Serializer
):
...
...
recircle/template/urls.py
View file @
1a9a8829
...
...
@@ -3,6 +3,6 @@ from rest_framework import routers
from
template
import
views
router
=
routers
.
DefaultRouter
()
router
.
register
(
r"templates
/image-templates
"
,
views
.
ImageTemplateViewSet
,
basename
=
"image-template"
)
router
.
register
(
r"templates"
,
views
.
ImageTemplateViewSet
,
basename
=
"image-template"
)
urlpatterns
=
router
.
urls
recircle/template/views.py
View file @
1a9a8829
from
rest_framework.response
import
Response
from
rest_framework.viewsets
import
ModelViewSet
from
template.serializers
import
ImageTemplateModelSerializer
from
template.serializers
import
ImageTemplateModelSerializer
,
ImageTemplateListItemSerializer
from
template.models
import
ImageTemplate
...
...
@@ -31,7 +31,7 @@ class ImageTemplateViewSet(ModelViewSet):
def
update
(
self
,
request
,
*
args
,
**
kwargs
):
# only the name, description, lease, flavor can be updated
allowed_keys
=
[
"name"
,
"description"
,
"lease"
,
"flavor"
]
allowed_keys
=
[
"name"
,
"description"
,
"
access_prtotocol"
,
"distro"
,
"
lease"
,
"flavor"
]
# delete not allowed key
for
key
in
request
.
data
.
keys
():
...
...
@@ -39,3 +39,9 @@ class ImageTemplateViewSet(ModelViewSet):
request
.
data
.
pop
(
key
,
None
)
return
super
(
ImageTemplateViewSet
,
self
)
.
update
(
request
,
partial
=
True
)
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
# TODO: Filter for owned and shared tempaltes
query
=
ImageTemplate
.
objects
.
all
()
serializer
=
ImageTemplateListItemSerializer
(
query
,
many
=
True
)
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