Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
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
ce8fd522
authored
Jul 31, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: new sliders for template edit/create
parent
acb311c7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
109 additions
and
82 deletions
+109
-82
circle/dashboard/forms.py
+35
-69
circle/dashboard/templates/dashboard/_template-create.html
+38
-11
circle/dashboard/templates/dashboard/template-edit.html
+32
-1
circle/dashboard/views.py
+4
-1
No files found.
circle/dashboard/forms.py
View file @
ce8fd522
...
@@ -30,7 +30,7 @@ from django.core.exceptions import PermissionDenied, ValidationError
...
@@ -30,7 +30,7 @@ from django.core.exceptions import PermissionDenied, ValidationError
import
autocomplete_light
import
autocomplete_light
from
crispy_forms.helper
import
FormHelper
from
crispy_forms.helper
import
FormHelper
from
crispy_forms.layout
import
(
from
crispy_forms.layout
import
(
Layout
,
Div
,
BaseInput
,
Field
,
HTML
,
Submit
,
Fieldset
,
TEMPLATE_PACK
,
Layout
,
Div
,
BaseInput
,
Field
,
HTML
,
Submit
,
TEMPLATE_PACK
,
)
)
from
crispy_forms.utils
import
render_field
from
crispy_forms.utils
import
render_field
...
@@ -407,6 +407,29 @@ class TemplateForm(forms.ModelForm):
...
@@ -407,6 +407,29 @@ class TemplateForm(forms.ModelForm):
networks
=
forms
.
ModelMultipleChoiceField
(
networks
=
forms
.
ModelMultipleChoiceField
(
queryset
=
None
,
required
=
False
,
label
=
_
(
"Networks"
))
queryset
=
None
,
required
=
False
,
label
=
_
(
"Networks"
))
num_cores
=
forms
.
IntegerField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
'class'
:
"form-control input-tags cpu-count-input"
,
'min'
:
1
,
'max'
:
10
,
'required'
:
""
,
}),
min_value
=
1
,
max_value
=
10
,
)
ram_size
=
forms
.
IntegerField
(
widget
=
forms
.
NumberInput
(
attrs
=
{
'class'
:
"form-control input-tags ram-input"
,
'min'
:
128
,
'max'
:
MAX_NODE_RAM
,
'step'
:
128
,
'required'
:
""
,
}),
min_value
=
128
,
max_value
=
MAX_NODE_RAM
,
)
priority
=
forms
.
ChoiceField
(
priority_choices
,
widget
=
forms
.
Select
(
attrs
=
{
'class'
:
"form-control input-tags cpu-priority-input"
,
}))
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
user
=
kwargs
.
pop
(
"user"
,
None
)
self
.
user
=
kwargs
.
pop
(
"user"
,
None
)
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
...
@@ -438,18 +461,24 @@ class TemplateForm(forms.ModelForm):
...
@@ -438,18 +461,24 @@ class TemplateForm(forms.ModelForm):
field
.
widget
.
attrs
[
'disabled'
]
=
'disabled'
field
.
widget
.
attrs
[
'disabled'
]
=
'disabled'
if
not
self
.
instance
.
pk
and
len
(
self
.
errors
)
<
1
:
if
not
self
.
instance
.
pk
and
len
(
self
.
errors
)
<
1
:
self
.
instance
.
priority
=
20
self
.
initial
[
'num_cores'
]
=
1
self
.
instance
.
ram_size
=
512
self
.
initial
[
'priority'
]
=
10
self
.
instance
.
num_cores
=
2
self
.
initial
[
'ram_size'
]
=
512
self
.
initial
[
'max_ram_size'
]
=
512
self
.
fields
[
"lease"
]
.
queryset
=
Lease
.
get_objects_with_level
(
self
.
fields
[
"lease"
]
.
queryset
=
Lease
.
get_objects_with_level
(
"operator"
,
self
.
user
)
"operator"
,
self
.
user
)
self
.
fields
[
'raw_data'
]
.
validators
.
append
(
domain_validator
)
def
clean_owner
(
self
):
def
clean_owner
(
self
):
if
self
.
instance
.
pk
is
not
None
:
if
self
.
instance
.
pk
is
not
None
:
return
User
.
objects
.
get
(
pk
=
self
.
instance
.
owner
.
pk
)
return
User
.
objects
.
get
(
pk
=
self
.
instance
.
owner
.
pk
)
return
self
.
user
return
self
.
user
def
clean_max_ram_size
(
self
):
return
self
.
cleaned_data
.
get
(
"ram_size"
,
0
)
def
_clean_fields
(
self
):
def
_clean_fields
(
self
):
try
:
try
:
old
=
InstanceTemplate
.
objects
.
get
(
pk
=
self
.
instance
.
pk
)
old
=
InstanceTemplate
.
objects
.
get
(
pk
=
self
.
instance
.
pk
)
...
@@ -511,77 +540,14 @@ class TemplateForm(forms.ModelForm):
...
@@ -511,77 +540,14 @@ class TemplateForm(forms.ModelForm):
submit_kwargs
[
'disabled'
]
=
None
submit_kwargs
[
'disabled'
]
=
None
helper
=
FormHelper
()
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
Field
(
"name"
),
Fieldset
(
_
(
"Resource configuration"
),
Div
(
# cpu count
Div
(
Field
(
'num_cores'
,
id
=
"vm-cpu-count-slider"
,
css_class
=
"vm-slider"
,
data_slider_min
=
"1"
,
data_slider_max
=
"8"
,
data_slider_step
=
"1"
,
data_slider_value
=
self
.
instance
.
num_cores
,
data_slider_handle
=
"square"
,
data_slider_tooltip
=
"hide"
),
css_class
=
"col-sm-9"
),
css_class
=
"row"
),
Div
(
# cpu priority
Div
(
Field
(
'priority'
,
id
=
"vm-cpu-priority-slider"
,
css_class
=
"vm-slider"
,
data_slider_min
=
"0"
,
data_slider_max
=
"100"
,
data_slider_step
=
"1"
,
data_slider_value
=
self
.
instance
.
priority
,
data_slider_handle
=
"square"
,
data_slider_tooltip
=
"hide"
),
css_class
=
"col-sm-9"
),
css_class
=
"row"
),
Div
(
Div
(
Field
(
'ram_size'
,
id
=
"vm-ram-size-slider"
,
css_class
=
"vm-slider"
,
data_slider_min
=
"128"
,
data_slider_max
=
"4096"
,
data_slider_step
=
"128"
,
data_slider_value
=
self
.
instance
.
ram_size
,
data_slider_handle
=
"square"
,
data_slider_tooltip
=
"hide"
),
css_class
=
"col-sm-9"
),
css_class
=
"row"
,
),
Field
(
'max_ram_size'
,
type
=
"hidden"
,
value
=
"0"
),
Field
(
'arch'
),
),
Fieldset
(
_
(
"Virtual machine settings"
),
Field
(
'access_method'
),
Field
(
'boot_menu'
),
Field
(
'raw_data'
),
Field
(
'req_traits'
),
Field
(
'description'
),
Field
(
"parent"
,
type
=
"hidden"
),
Field
(
"system"
),
),
Fieldset
(
_
(
"External resources"
),
Field
(
"networks"
),
Field
(
"lease"
),
Field
(
"tags"
),
),
)
helper
.
add_input
(
Submit
(
'submit'
,
'Save changes'
,
**
submit_kwargs
))
return
helper
return
helper
class
Meta
:
class
Meta
:
model
=
InstanceTemplate
model
=
InstanceTemplate
exclude
=
(
'state'
,
'disks'
,
)
exclude
=
(
'state'
,
'disks'
,
)
widgets
=
{
widgets
=
{
'system'
:
forms
.
TextInput
'system'
:
forms
.
TextInput
,
'max_ram_size'
:
forms
.
HiddenInput
}
}
...
...
circle/dashboard/templates/dashboard/_template-create.html
View file @
ce8fd522
{% load i18n %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load crispy_forms_tags %}
{% if leases
<
1
%}
<form
action=
""
method=
"POST"
>
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% csrf_token %}
{{ form.name|as_crispy_field }}
<fieldset
class=
"resources-sliders"
>
<legend>
{% trans "Resource configuration" %}
</legend>
{% include "dashboard/_resources-sliders.html" with field_priority=form.priority field_num_cores=form.num_cores field_ram_size=form.ram_size %}
{{ form.max_ram_size|as_crispy_field }}
</fieldset>
<fieldset>
<legend>
{% trans "Virtual machine settings" %}
</legend>
{{ form.arch|as_crispy_field }}
{{ form.access_method|as_crispy_field }}
{{ form.boot_menu|as_crispy_field }}
{{ form.raw_data|as_crispy_field }}
{{ form.req_traits|as_crispy_field }}
{{ form.description|as_crispy_field }}
{{ form.system|as_crispy_field }}
</fieldset>
<fieldset>
<legend>
{% trans "External resources" %}
</legend>
{{ form.networks|as_crispy_field }}
{{ form.lease|as_crispy_field }}
{% if show_lease_create %}
<div
class=
"alert alert-warning"
>
<div
class=
"alert alert-warning"
>
{% trans "You haven't created any leases yet, but you need one to create a template
!
" %}
{% trans "You haven't created any leases yet, but you need one to create a template
.
" %}
<a
href=
"{% url "
dashboard
.
views
.
lease-create
"
%}"
>
{% trans "Create a new lease now." %}
</a>
<a
href=
"{% url "
dashboard
.
views
.
lease-create
"
%}"
>
{% trans "Create a new lease now." %}
</a>
</div>
</div>
{% endif %}
{% endif %}
{{ form.tags|as_crispy_field }}
</fieldset>
<input
type=
"submit"
value=
"{% trans "
Create
new
template
"
%}"
class=
"btn btn-success"
>
</form>
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
<style>
<style>
fieldset
{
fieldset
{
...
@@ -21,8 +53,3 @@
...
@@ -21,8 +53,3 @@
font-weight
:
bold
;
font-weight
:
bold
;
}
}
</style>
</style>
<script>
$
(
function
()
{
$
(
"#hint_id_num_cores, #hint_id_priority, #hint_id_ram_size"
).
hide
();
});
</script>
circle/dashboard/templates/dashboard/template-edit.html
View file @
ce8fd522
...
@@ -15,10 +15,41 @@
...
@@ -15,10 +15,41 @@
<h3
class=
"no-margin"
><i
class=
"fa fa-puzzle-piece"
></i>
{% trans "Edit template" %}
</h3>
<h3
class=
"no-margin"
><i
class=
"fa fa-puzzle-piece"
></i>
{% trans "Edit template" %}
</h3>
</div>
</div>
<div
class=
"panel-body"
>
<div
class=
"panel-body"
>
<form
action=
""
method=
"POST"
>
{% with form=form %}
{% with form=form %}
{% include "display-form-errors.html" %}
{% include "display-form-errors.html" %}
{% endwith %}
{% endwith %}
{% crispy form %}
{% csrf_token %}
{{ form.name|as_crispy_field }}
<fieldset
class=
"resources-sliders"
>
<legend>
{% trans "Resource configuration" %}
</legend>
{% include "dashboard/_resources-sliders.html" with field_priority=form.priority field_num_cores=form.num_cores field_ram_size=form.ram_size %}
{{ form.max_ram_size|as_crispy_field }}
</fieldset>
<fieldset>
<legend>
{% trans "Virtual machine settings" %}
</legend>
{{ form.arch|as_crispy_field }}
{{ form.access_method|as_crispy_field }}
{{ form.boot_menu|as_crispy_field }}
{{ form.raw_data|as_crispy_field }}
{{ form.req_traits|as_crispy_field }}
{{ form.description|as_crispy_field }}
{{ form.system|as_crispy_field }}
</fieldset>
<fieldset>
<legend>
{% trans "External resources" %}
</legend>
{{ form.networks|as_crispy_field }}
{{ form.lease|as_crispy_field }}
{{ form.tags|as_crispy_field }}
</fieldset>
<input
type=
"submit"
value=
"{% trans "
Save
changes
"
%}"
class=
"btn btn-primary"
>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
...
...
circle/dashboard/views.py
View file @
ce8fd522
...
@@ -1348,10 +1348,13 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
...
@@ -1348,10 +1348,13 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
def
get_context_data
(
self
,
*
args
,
**
kwargs
):
context
=
super
(
TemplateCreate
,
self
)
.
get_context_data
(
*
args
,
**
kwargs
)
context
=
super
(
TemplateCreate
,
self
)
.
get_context_data
(
*
args
,
**
kwargs
)
num_leases
=
Lease
.
get_objects_with_level
(
"user"
,
self
.
request
.
user
)
.
count
()
can_create_leases
=
self
.
request
.
user
.
has_perm
(
"create_leases"
)
context
.
update
({
context
.
update
({
'box_title'
:
_
(
"Create a new base VM"
),
'box_title'
:
_
(
"Create a new base VM"
),
'template'
:
"dashboard/_template-create.html"
,
'template'
:
"dashboard/_template-create.html"
,
'
leases'
:
Lease
.
objects
.
count
()
'
show_lease_create'
:
num_leases
<
1
and
can_create_leases
})
})
return
context
return
context
...
...
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