Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c529f9c6
authored
Jan 09, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: clone templates from parents
parent
020ee0a8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
16 deletions
+39
-16
circle/dashboard/forms.py
+27
-8
circle/dashboard/templates/dashboard/template-list.html
+0
-8
circle/dashboard/templates/dashboard/template-list/column-template-actions.html
+3
-0
circle/dashboard/views.py
+9
-0
No files found.
circle/dashboard/forms.py
View file @
c529f9c6
...
...
@@ -299,16 +299,39 @@ class TemplateForm(forms.ModelForm):
queryset
=
VLANS
,
required
=
False
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
parent
=
kwargs
.
pop
(
"parent"
,
None
)
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'disks'
]
=
forms
.
ModelMultipleChoiceField
(
queryset
=
DISKS
)
if
self
.
instance
.
pk
:
mn
=
self
.
instance
.
interface_set
.
filter
(
if
parent
is
not
None
:
template
=
InstanceTemplate
.
objects
.
get
(
pk
=
parent
)
parent
=
template
.
__dict__
fields
=
[
"system"
,
"name"
,
"num_cores"
,
"boot_menu"
,
"ram_size"
,
"priority"
,
"state"
,
"access_method"
,
"raw_data"
,
"arch"
,
"description"
]
for
f
in
fields
:
self
.
initial
[
f
]
=
parent
[
f
]
self
.
initial
[
'lease'
]
=
parent
[
'lease_id'
]
self
.
initial
[
'disks'
]
=
template
.
disks
.
all
()
self
.
initial
[
'parent'
]
=
template
self
.
initial
[
'name'
]
=
"Clone of
%
s"
%
self
.
initial
[
'name'
]
self
.
for_networks
=
template
else
:
self
.
for_networks
=
self
.
instance
if
self
.
instance
.
pk
or
parent
is
not
None
:
mn
=
self
.
for_networks
.
interface_set
.
filter
(
managed
=
True
)
.
values_list
(
"vlan"
,
flat
=
True
)
un
=
self
.
instance
.
interface_set
.
filter
(
un
=
self
.
for_networks
.
interface_set
.
filter
(
managed
=
False
)
.
values_list
(
"vlan"
,
flat
=
True
)
self
.
initial
[
'managed_networks'
]
=
mn
self
.
initial
[
'unmanaged_networks'
]
=
un
if
not
self
.
instance
.
pk
and
len
(
self
.
errors
)
<
1
:
self
.
instance
.
priority
=
20
self
.
instance
.
ram_size
=
512
self
.
instance
.
num_cores
=
2
def
save
(
self
,
commit
=
True
):
data
=
self
.
cleaned_data
self
.
instance
.
max_ram_size
=
data
.
get
(
'ram_size'
)
...
...
@@ -346,10 +369,6 @@ class TemplateForm(forms.ModelForm):
@property
def
helper
(
self
):
helper
=
FormHelper
()
if
not
self
.
instance
.
pk
and
len
(
self
.
errors
)
<
1
:
self
.
instance
.
priority
=
20
self
.
instance
.
ram_size
=
512
self
.
instance
.
num_cores
=
2
helper
.
layout
=
Layout
(
Field
(
"name"
),
Fieldset
(
...
...
@@ -403,7 +422,7 @@ class TemplateForm(forms.ModelForm):
Field
(
'raw_data'
),
Field
(
'req_traits'
),
Field
(
'description'
),
Field
(
"parent"
),
Field
(
"parent"
,
type
=
"hidden"
),
Field
(
"system"
),
Field
(
"state"
),
),
...
...
circle/dashboard/templates/dashboard/template-list.html
View file @
c529f9c6
...
...
@@ -10,9 +10,6 @@
<a
href=
"{% url "
dashboard
.
views
.
template-create
"
%}"
class=
"pull-right btn btn-success btn-xs"
>
<i
class=
"icon-plus"
></i>
new template
</a>
<a
href=
"{% url "
dashboard
.
views
.
lease-create
"
%}"
class=
"pull-right btn btn-success btn-xs"
style=
"margin-right: 10px;"
>
<i
class=
"icon-plus"
></i>
new lease
</a>
<h3
class=
"no-margin"
><i
class=
"icon-desktop"
></i>
{% trans "Templates" %}
</h3>
</div>
<div
class=
"panel-body"
>
...
...
@@ -22,15 +19,10 @@
</div>
</div>
<div
class=
"row"
>
<div
class=
"col-md-6"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<a
href=
"{% url "
dashboard
.
views
.
template-create
"
%}"
class=
"pull-right btn btn-success btn-xs"
>
<i
class=
"icon-plus"
></i>
new template
</a>
<a
href=
"{% url "
dashboard
.
views
.
lease-create
"
%}"
class=
"pull-right btn btn-success btn-xs"
style=
"margin-right: 10px;"
>
<i
class=
"icon-plus"
></i>
new lease
</a>
...
...
circle/dashboard/templates/dashboard/template-list/column-template-actions.html
View file @
c529f9c6
{% load i18n %}
<a
href=
"{% url "
dashboard
.
views
.
template-create
"
%}?
parent=
{{
record
.
pk
}}"
id=
"template-list-clone-button"
class=
"btn btn-default btn-xs"
title
data-original-title=
"{% trans "
Clone
"
%}"
>
<i
class=
"icon-copy"
></i>
</a>
<a
href=
"{% url "
dashboard
.
views
.
template-detail
"
pk=
record.pk%}"
id=
"template-list-edit-button"
class=
"btn btn-default btn-xs"
title
data-original-title=
"{% trans "
Edit
"
%}"
>
<i
class=
"icon-edit"
></i>
</a>
...
...
circle/dashboard/views.py
View file @
c529f9c6
...
...
@@ -361,6 +361,15 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
template_name
=
"dashboard/template-create.html"
success_message
=
_
(
"Successfully created a new template!"
)
def
get
(
self
,
*
args
,
**
kwargs
):
self
.
parent
=
self
.
request
.
GET
.
get
(
"parent"
)
return
super
(
TemplateCreate
,
self
)
.
get
(
*
args
,
**
kwargs
)
def
get_form_kwargs
(
self
):
kwargs
=
super
(
TemplateCreate
,
self
)
.
get_form_kwargs
()
kwargs
[
'parent'
]
=
getattr
(
self
,
"parent"
,
None
)
return
kwargs
def
get_success_url
(
self
):
return
reverse_lazy
(
"dashboard.views.template-list"
)
...
...
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