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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
07b66c82
authored
Jan 02, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: create template
parent
3b4b53ee
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
14 deletions
+73
-14
circle/dashboard/forms.py
+20
-13
circle/dashboard/templates/dashboard/template-create.html
+37
-0
circle/dashboard/templates/dashboard/template-list.html
+4
-1
circle/dashboard/urls.py
+2
-0
circle/dashboard/views.py
+10
-0
No files found.
circle/dashboard/forms.py
View file @
07b66c82
...
...
@@ -301,15 +301,24 @@ class TemplateForm(forms.ModelForm):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
TemplateForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'disks'
]
=
forms
.
ModelMultipleChoiceField
(
queryset
=
DISKS
)
mn
=
self
.
instance
.
interface_set
.
filter
(
managed
=
True
)
.
values_list
(
"vlan"
,
flat
=
True
)
un
=
self
.
instance
.
interface_set
.
filter
(
managed
=
False
)
.
values_list
(
"vlan"
,
flat
=
True
)
self
.
initial
[
'managed_networks'
]
=
mn
self
.
initial
[
'unmanaged_networks'
]
=
un
if
self
.
instance
.
pk
:
mn
=
self
.
instance
.
interface_set
.
filter
(
managed
=
True
)
.
values_list
(
"vlan"
,
flat
=
True
)
un
=
self
.
instance
.
interface_set
.
filter
(
managed
=
False
)
.
values_list
(
"vlan"
,
flat
=
True
)
self
.
initial
[
'managed_networks'
]
=
mn
self
.
initial
[
'unmanaged_networks'
]
=
un
def
save
(
self
,
commit
=
True
):
data
=
self
.
cleaned_data
self
.
instance
.
max_ram_size
=
data
.
get
(
'ram_size'
)
instance
=
super
(
TemplateForm
,
self
)
.
save
(
commit
=
False
)
if
commit
:
instance
.
save
()
self
.
instance
.
disks
=
data
[
'disks'
]
# TODO why do I need this
# create and/or delete InterfaceTemplates
managed
=
InterfaceTemplate
.
objects
.
filter
(
managed
=
True
,
template
=
self
.
instance
)
.
values_list
(
"vlan"
,
...
...
@@ -332,17 +341,15 @@ class TemplateForm(forms.ModelForm):
InterfaceTemplate
.
objects
.
filter
(
managed
=
False
,
template
=
self
.
instance
)
.
exclude
(
vlan__in
=
data
[
'unmanaged_networks'
])
.
delete
()
self
.
instance
.
disks
=
data
[
'disks'
]
# TODO why do I need this
self
.
instance
.
max_ram_size
=
data
.
get
(
'ram_size'
)
instance
=
super
(
TemplateForm
,
self
)
.
save
(
commit
=
False
)
if
commit
:
instance
.
save
()
return
instance
@property
def
helper
(
self
):
helper
=
FormHelper
()
if
not
self
.
instance
.
pk
:
self
.
instance
.
priority
=
20
self
.
instance
.
ram_size
=
512
self
.
instance
.
num_cores
=
2
helper
.
layout
=
Layout
(
Field
(
"name"
),
Fieldset
(
...
...
@@ -386,7 +393,7 @@ class TemplateForm(forms.ModelForm):
),
css_class
=
"row"
,
),
Field
(
'max_ram_size'
,
type
=
"hidden"
),
Field
(
'max_ram_size'
,
type
=
"hidden"
,
value
=
"0"
),
Field
(
'arch'
),
),
Fieldset
(
...
...
circle/dashboard/templates/dashboard/template-create.html
0 → 100644
View file @
07b66c82
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% 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 template" %}
</h3>
</div>
<div
class=
"panel-body"
>
{% with form=form %}
{% include "display-form-errors.html" %}
{% endwith %}
{% crispy form %}
</div>
</div>
</div>
</div>
<style>
fieldset
{
margin-top
:
40px
;
}
fieldset
legend
{
font-weight
:
bold
;
}
</style>
<script>
$
(
function
()
{
$
(
"#hint_id_num_cores, #hint_id_priority, #hint_id_ram_size"
).
hide
();
});
</script>
{% endblock %}
circle/dashboard/templates/dashboard/template-list.html
View file @
07b66c82
...
...
@@ -7,9 +7,12 @@
<div
class=
"col-md-12"
>
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<a
href=
"
#
"
class=
"pull-right btn btn-success btn-xs"
>
<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"
>
...
...
circle/dashboard/urls.py
View file @
07b66c82
...
...
@@ -15,6 +15,8 @@ urlpatterns = patterns(
name
=
"dashboard.views.lease-detail"
),
url
(
r'^lease/create/$'
,
LeaseCreate
.
as_view
(),
name
=
"dashboard.views.lease-create"
),
url
(
r'^template/create/$'
,
TemplateCreate
.
as_view
(),
name
=
"dashboard.views.template-create"
),
url
(
r'^template/(?P<pk>\d+)/$'
,
TemplateDetail
.
as_view
(),
name
=
'dashboard.views.template-detail'
),
url
(
r"^template/list/$"
,
TemplateList
.
as_view
(),
...
...
circle/dashboard/views.py
View file @
07b66c82
...
...
@@ -351,6 +351,16 @@ class AclUpdateView(View, SingleObjectMixin):
value
,
unicode
(
request
.
user
))
class
TemplateCreate
(
SuccessMessageMixin
,
CreateView
):
model
=
InstanceTemplate
form_class
=
TemplateForm
template_name
=
"dashboard/template-create.html"
success_message
=
_
(
"Successfully created a new template!"
)
def
get_success_url
(
self
):
return
reverse_lazy
(
"dashboard.views.template-list"
)
class
TemplateDetail
(
SuccessMessageMixin
,
UpdateView
):
model
=
InstanceTemplate
template_name
=
"dashboard/template-edit.html"
...
...
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