Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
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
3d052db9
authored
Mar 26, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: template wizard draft
parent
381c61f1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
120 additions
and
31 deletions
+120
-31
circle/dashboard/forms.py
+9
-2
circle/dashboard/static/dashboard/dashboard.css
+22
-0
circle/dashboard/templates/dashboard/_template-create-1.html
+36
-0
circle/dashboard/templates/dashboard/_template-create-2.html
+4
-22
circle/dashboard/templates/dashboard/index-templates.html
+6
-5
circle/dashboard/urls.py
+3
-1
circle/dashboard/views.py
+40
-1
No files found.
circle/dashboard/forms.py
View file @
3d052db9
...
...
@@ -9,6 +9,8 @@ from crispy_forms.helper import FormHelper
from
crispy_forms.layout
import
(
Layout
,
Div
,
BaseInput
,
Field
,
HTML
,
Submit
,
Fieldset
,
TEMPLATE_PACK
)
from
django.shortcuts
import
get_object_or_404
from
crispy_forms.utils
import
render_field
from
django
import
forms
from
django.forms.widgets
import
TextInput
...
...
@@ -456,8 +458,8 @@ class TemplateForm(forms.ModelForm):
data
[
'owner'
]
=
self
.
user
.
pk
self
.
data
=
data
if
parent
is
not
None
:
template
=
InstanceTemplate
.
objects
.
get
(
pk
=
parent
)
if
parent
is
not
None
and
parent
.
isdigit
()
:
template
=
get_object_or_404
(
InstanceTemplate
,
pk
=
parent
)
parent
=
template
.
__dict__
fields
=
[
"system"
,
"name"
,
"num_cores"
,
"boot_menu"
,
"ram_size"
,
"priority"
,
"access_method"
,
"raw_data"
,
...
...
@@ -497,11 +499,16 @@ class TemplateForm(forms.ModelForm):
def
save
(
self
,
commit
=
True
):
data
=
self
.
cleaned_data
self
.
instance
.
max_ram_size
=
data
.
get
(
'ram_size'
)
is_new
=
self
.
instance
.
pk
is
None
instance
=
super
(
TemplateForm
,
self
)
.
save
(
commit
=
False
)
if
commit
:
instance
.
save
()
if
is_new
:
self
.
instance
.
disks
=
InstanceTemplate
.
objects
.
get
(
pk
=
self
.
instance
.
parent
.
pk
)
.
disks
.
all
()
# create and/or delete InterfaceTemplates
networks
=
InterfaceTemplate
.
objects
.
filter
(
template
=
self
.
instance
)
.
values_list
(
"vlan"
,
flat
=
True
)
...
...
circle/dashboard/static/dashboard/dashboard.css
View file @
3d052db9
...
...
@@ -423,3 +423,25 @@ footer a, footer a:hover, footer a:visited {
#node-info-pane
{
margin-bottom
:
20px
;
}
.template-choose-list
{
max-width
:
600px
;
}
.template-choose-list-element
{
cursor
:
pointer
;
}
.template-choose-list-element
small
{
display
:
none
;
float
:
right
;
padding-right
:
50px
;
}
.template-choose-list-element
{
padding
:
15px
;
}
.template-choose-list
input
[
type
=
"radio"
]
{
float
:
right
;
}
circle/dashboard/templates/dashboard/_template-create-1.html
0 → 100644
View file @
3d052db9
{% load i18n %}
<form
action=
"{% url "
dashboard
.
views
.
template-create
"
%}"
>
<div
class=
"template-choose-list"
>
{% for t in templates %}
<div
class=
"panel panel-default template-choose-list-element"
>
<input
type=
"radio"
name=
"parent"
value=
"{{ t.pk }}"
/>
{{ t.name }} - {{ t.system }}
<small>
Cores: {{ t.num_cores }} RAM: {{ t.ram_size }}
</small>
<div
class=
"clearfix"
></div>
</div>
{% endfor %}
<div
class=
"panel panel-default template-choose-list-element"
>
<input
type=
"radio"
name=
"parent"
value=
"base_vm"
/>
{% trans "Create a new base VM without disk" %}
</div>
<button
type=
"submit"
class=
"btn btn-success pull-right"
>
{% trans "Next" %}
</button>
<div
class=
"clearfix"
></div>
</div>
</form>
<script>
$
(
function
()
{
$
(
".template-choose-list-element"
).
click
(
function
()
{
$
(
"input"
,
$
(
this
)).
prop
(
"checked"
,
true
);
});
$
(
".template-choose-list-element"
).
hover
(
function
()
{
$
(
"small"
,
$
(
this
)).
stop
().
fadeIn
(
200
);
},
function
()
{
$
(
"small"
,
$
(
this
)).
stop
().
fadeOut
(
200
);
}
);
});
</script>
circle/dashboard/templates/dashboard/
template-create
.html
→
circle/dashboard/templates/dashboard/
_template-create-2
.html
View file @
3d052db9
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block title-page %}{% trans "Create base VM" %}{% 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-desktop"
></i>
{% trans "Create base VM" %}
</h3>
</div>
<div
class=
"panel-body"
>
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
</div>
</div>
</div>
</div>
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
<style>
fieldset
{
...
...
@@ -35,5 +19,3 @@
$
(
"#hint_id_num_cores, #hint_id_priority, #hint_id_ram_size"
).
hide
();
});
</script>
{% endblock %}
circle/dashboard/templates/dashboard/index-templates.html
View file @
3d052db9
...
...
@@ -18,15 +18,16 @@
<p>
{% trans "You don't have any templates, however you can still start virtual machines and even save them as new templates!" %}
</p>
<p>
{% trans "The new button below creates a new base vm, please use only if necessary!" %}
</p>
</div>
{% endfor %}
<div
href=
"#"
class=
"list-group-item list-group-footer text-right"
>
<p>
<a
href=
"{% url "
dashboard
.
views
.
template-list
"
%}"
class=
"btn btn-primary btn-xs"
><i
class=
"icon-chevron-sign-right"
></i>
{% trans "show all" %}
</a>
<a
href=
"{% url "
dashboard
.
views
.
template-create
"
%}"
class=
"btn btn-success btn-xs"
><i
class=
"icon-plus-sign"
></i>
{% trans "new" %}
</a>
<a
href=
"{% url "
dashboard
.
views
.
template-list
"
%}"
class=
"btn btn-primary btn-xs"
>
<i
class=
"icon-chevron-sign-right"
></i>
{% trans "show all" %}
</a>
<a
href=
"{% url "
dashboard
.
views
.
template-choose
"
%}"
class=
"btn btn-success btn-xs"
>
<i
class=
"icon-plus-sign"
></i>
{% trans "new" %}
</a>
</p>
</div>
</div>
...
...
circle/dashboard/urls.py
View file @
3d052db9
...
...
@@ -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
,
get_disk_download_status
,
TemplateChoose
,
)
urlpatterns
=
patterns
(
...
...
@@ -26,6 +26,8 @@ urlpatterns = patterns(
url
(
r'^template/create/$'
,
TemplateCreate
.
as_view
(),
name
=
"dashboard.views.template-create"
),
url
(
r'^template/choose/$'
,
TemplateChoose
.
as_view
(),
name
=
"dashboard.views.template-choose"
),
url
(
r'template/(?P<pk>\d+)/acl/$'
,
TemplateAclUpdateView
.
as_view
(),
name
=
'dashboard.views.template-acl'
),
url
(
r'^template/(?P<pk>\d+)/$'
,
TemplateDetail
.
as_view
(),
...
...
circle/dashboard/views.py
View file @
3d052db9
...
...
@@ -741,12 +741,51 @@ class GroupAclUpdateView(AclUpdateView):
kwargs
=
self
.
kwargs
))
class
TemplateChoose
(
TemplateView
):
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/modal-wrapper.html'
]
else
:
return
[
'dashboard/nojs-wrapper.html'
]
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
TemplateChoose
,
self
)
.
get_context_data
(
*
args
,
**
kwargs
)
templates
=
InstanceTemplate
.
get_objects_with_level
(
"user"
,
self
.
request
.
user
)
context
.
update
({
'box_title'
:
_
(
'Choose template'
),
'ajax_title'
:
False
,
'template'
:
"dashboard/_template-create-1.html"
,
'templates'
:
templates
.
all
(),
})
return
context
class
TemplateCreate
(
SuccessMessageMixin
,
CreateView
):
model
=
InstanceTemplate
form_class
=
TemplateForm
template_name
=
"dashboard/template-create.html"
success_message
=
_
(
"Successfully created a new template!"
)
def
get_template_names
(
self
):
if
self
.
request
.
is_ajax
():
return
[
'dashboard/modal-wrapper.html'
]
else
:
return
[
'dashboard/nojs-wrapper.html'
]
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
TemplateCreate
,
self
)
.
get_context_data
(
*
args
,
**
kwargs
)
context
.
update
({
'box_title'
:
(
_
(
'Clone a template'
)
if
self
.
request
.
GET
.
get
(
"parent"
)
.
isdigit
()
else
_
(
"Create a new base VM"
)),
'ajax_title'
:
False
,
'template'
:
"dashboard/_template-create-2.html"
,
})
return
context
def
get
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
request
.
user
.
has_perm
(
'vm.create_template'
):
raise
PermissionDenied
()
...
...
@@ -767,7 +806,7 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
form
=
self
.
form_class
(
request
.
POST
,
user
=
request
.
user
)
if
not
form
.
is_valid
():
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
el
s
e
:
el
if
form
.
cleaned_data
.
get
(
"parent"
)
is
Non
e
:
post
=
form
.
cleaned_data
networks
=
self
.
__create_networks
(
post
.
pop
(
"networks"
))
...
...
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