Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
3de47528
authored
Apr 02, 2014
by
Kálmán Viktor
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: clone templates view and form part
parent
b2953fc4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
4 deletions
+127
-4
circle/dashboard/forms.py
+53
-1
circle/dashboard/templates/dashboard/template-clone.html
+39
-0
circle/dashboard/templates/dashboard/template-list/column-template-actions.html
+1
-1
circle/dashboard/urls.py
+3
-1
circle/dashboard/views.py
+31
-1
No files found.
circle/dashboard/forms.py
View file @
3de47528
...
...
@@ -7,9 +7,11 @@ from django.contrib.auth.forms import (
from
crispy_forms.helper
import
FormHelper
from
crispy_forms.layout
import
(
Layout
,
Div
,
BaseInput
,
Field
,
HTML
,
Submit
,
Fieldset
,
TEMPLATE_PACK
Layout
,
Div
,
BaseInput
,
Field
,
HTML
,
Submit
,
Fieldset
,
TEMPLATE_PACK
,
)
from
crispy_forms.bootstrap
import
UneditableField
as
UF
from
django.shortcuts
import
get_object_or_404
from
crispy_forms.utils
import
render_field
from
django
import
forms
...
...
@@ -600,6 +602,56 @@ class TemplateForm(forms.ModelForm):
exclude
=
(
'state'
,
'disks'
,
)
class
TemplateCloneForm
(
forms
.
ModelForm
):
uneditable_fields
=
[
'num_cores'
,
'priority'
,
'ram_size'
,
'max_ram_size'
,
'arch'
,
'access_method'
,
'boot_menu'
,
'raw_data'
,
'description'
,
'system'
,
'lease'
,
'tags'
]
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
clone_from
=
kwargs
.
pop
(
"clone_from"
)
self
.
user
=
kwargs
.
pop
(
"user"
)
super
(
TemplateCloneForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
data
=
self
.
data
.
copy
()
template
=
get_object_or_404
(
InstanceTemplate
,
pk
=
self
.
clone_from
)
for
f
in
self
.
uneditable_fields
:
self
.
initial
[
f
]
=
getattr
(
template
,
f
)
value
=
getattr
(
template
,
f
)
if
hasattr
(
value
,
"pk"
):
value
=
value
.
pk
data
.
update
({
'
%
s'
%
f
:
value
})
data
.
update
({
'owner'
:
self
.
user
.
pk
})
self
.
data
=
data
def
save
(
self
,
*
args
,
**
kwargs
):
pass
@property
def
helper
(
self
):
helper
=
FormHelper
()
ufs
=
[
UF
(
uf
)
for
uf
in
self
.
uneditable_fields
]
helper
.
layout
=
Layout
(
Fieldset
(
_
(
"Modify these"
),
Field
(
"name"
),
),
Fieldset
(
_
(
"You can't modify these ..."
),
*
ufs
)
)
helper
.
add_input
(
Submit
(
'submit'
,
_
(
'Clone template'
)))
return
helper
class
Meta
:
model
=
InstanceTemplate
exclude
=
(
'state'
,
'disks'
,
)
class
LeaseForm
(
forms
.
ModelForm
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
circle/dashboard/templates/dashboard/template-clone.html
0 → 100644
View file @
3de47528
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load sizefieldtags %}
{% load crispy_forms_tags %}
{% block title-page %}{% trans "Clone template" %}{% endblock %}
{% block content %}
<div
class=
"row"
>
<div
class=
"col-md-12"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<a
class=
"pull-right btn btn-default btn-xs"
href=
"{% url "
dashboard
.
views
.
template-list
"
%}"
>
{% trans "Back" %}
</a>
<h3
class=
"no-margin"
><i
class=
"icon-puzzle-piece"
></i>
{% trans "Clone template" %}
</h3>
</div>
<div
class=
"panel-body"
>
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
</div>
</div>
</div>
</div>
<!-- .row -->
<style>
fieldset
{
margin-top
:
40px
;
}
fieldset
legend
{
font-weight
:
bold
;
}
</style>
{% endblock %}
{% block extra_js %}
{% endblock %}
circle/dashboard/templates/dashboard/template-list/column-template-actions.html
View file @
3de47528
{% load i18n %}
<a
href=
"{% url "
dashboard
.
views
.
template-c
reate
"
%}?
parent=
{{
record
.
pk
}
}"
id=
"template-list-clone-button"
class=
"btn btn-default btn-xs"
title=
"{% trans "
Clone
"
%}"
>
<a
href=
"{% url "
dashboard
.
views
.
template-c
lone
"
pk=
record.pk
%
}"
id=
"template-list-clone-button"
class=
"btn btn-default btn-xs"
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=
"{% trans "
Edit
"
%}"
>
...
...
circle/dashboard/urls.py
View file @
3de47528
...
...
@@ -11,7 +11,7 @@ from .views import (
TransferOwnershipConfirmView
,
TransferOwnershipView
,
vm_activity
,
VmCreate
,
VmDelete
,
VmDetailView
,
VmDetailVncTokenView
,
VmGraphView
,
VmList
,
VmMassDelete
,
VmMigrateView
,
VmRenewView
,
DiskRemoveView
,
get_disk_download_status
,
TemplateChoose
,
get_disk_download_status
,
TemplateChoose
,
TemplateClone
)
urlpatterns
=
patterns
(
...
...
@@ -36,6 +36,8 @@ urlpatterns = patterns(
name
=
"dashboard.views.template-list"
),
url
(
r"^template/delete/(?P<pk>\d+)/$"
,
TemplateDelete
.
as_view
(),
name
=
"dashboard.views.template-delete"
),
url
(
r"^template/clone/(?P<pk>\d+)/$"
,
TemplateClone
.
as_view
(),
name
=
"dashboard.views.template-clone"
),
url
(
r'^vm/(?P<pk>\d+)/remove_port/(?P<rule>\d+)/$'
,
PortDelete
.
as_view
(),
name
=
'dashboard.views.remove-port'
),
...
...
circle/dashboard/views.py
View file @
3de47528
...
...
@@ -37,7 +37,7 @@ from braces.views import (
from
.forms
import
(
CircleAuthenticationForm
,
DiskAddForm
,
HostForm
,
LeaseForm
,
MyProfileForm
,
NodeForm
,
TemplateForm
,
TraitForm
,
VmCustomizeForm
,
NodeForm
,
TemplateForm
,
TraitForm
,
VmCustomizeForm
,
TemplateCloneForm
)
from
.tables
import
(
NodeListTable
,
NodeVmListTable
,
TemplateListTable
,
LeaseListTable
,
GroupListTable
,)
...
...
@@ -762,6 +762,36 @@ class TemplateChoose(TemplateView):
return
context
class
TemplateClone
(
CreateView
):
template_name
=
"dashboard/template-clone.html"
form_class
=
TemplateCloneForm
model
=
InstanceTemplate
def
get_form_kwargs
(
self
):
kwargs
=
super
(
TemplateClone
,
self
)
.
get_form_kwargs
()
kwargs
[
'clone_from'
]
=
self
.
kwargs
[
'pk'
]
kwargs
[
'user'
]
=
self
.
request
.
user
return
kwargs
def
get
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
request
.
user
.
has_perm
(
'vm.create_template'
):
raise
PermissionDenied
()
return
super
(
TemplateClone
,
self
)
.
get
(
*
args
,
**
kwargs
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
if
not
self
.
request
.
user
.
has_perm
(
'vm.create_template'
):
raise
PermissionDenied
()
form
=
self
.
form_class
(
request
.
POST
,
clone_from
=
kwargs
[
'pk'
],
user
=
request
.
user
)
if
not
form
.
is_valid
():
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
else
:
# clone template
return
redirect
(
"/"
)
# temp
class
TemplateCreate
(
SuccessMessageMixin
,
CreateView
):
model
=
InstanceTemplate
form_class
=
TemplateForm
...
...
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