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
198ec637
authored
Jun 06, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: add Vm{Create,Download}DiskForm
parent
d84501eb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
54 deletions
+17
-54
circle/dashboard/forms.py
+17
-54
No files found.
circle/dashboard/forms.py
View file @
198ec637
...
@@ -846,6 +846,12 @@ class LeaseForm(forms.ModelForm):
...
@@ -846,6 +846,12 @@ class LeaseForm(forms.ModelForm):
model
=
Lease
model
=
Lease
class
VmCreateDiskForm
(
forms
.
Form
):
name
=
forms
.
CharField
(
max_length
=
100
,
label
=
_
(
"Name"
))
size
=
forms
.
CharField
(
widget
=
FileSizeWidget
,
initial
=
10
<<
30
,
label
=
_
(
'Size'
),
help_text
=
_
(
'Size of disk to create in bytes or with units '
'like MB or GB.'
))
def
clean_size
(
self
):
def
clean_size
(
self
):
size_in_bytes
=
self
.
cleaned_data
.
get
(
"size"
)
size_in_bytes
=
self
.
cleaned_data
.
get
(
"size"
)
...
@@ -854,66 +860,23 @@ class LeaseForm(forms.ModelForm):
...
@@ -854,66 +860,23 @@ class LeaseForm(forms.ModelForm):
" GB or MB!"
))
" GB or MB!"
))
return
size_in_bytes
return
size_in_bytes
def
clean
(
self
):
@property
cleaned_data
=
self
.
cleaned_data
def
helper
(
self
):
size
=
cleaned_data
.
get
(
"size"
)
helper
=
FormHelper
(
self
)
url
=
cleaned_data
.
get
(
"url"
)
helper
.
form_tag
=
False
return
helper
if
not
size
and
not
url
:
msg
=
_
(
"You have to either specify size or URL"
)
self
.
_errors
[
_
(
"Global"
)]
=
self
.
error_class
([
msg
])
return
cleaned_data
def
save
(
self
,
commit
=
True
):
data
=
self
.
cleaned_data
if
self
.
is_template
:
inst
=
InstanceTemplate
.
objects
.
get
(
pk
=
self
.
object_pk
)
else
:
inst
=
Instance
.
objects
.
get
(
pk
=
self
.
object_pk
)
if
data
[
'size'
]:
kwargs
=
{
'name'
:
data
[
'name'
],
'type'
:
"qcow2-norm"
,
'datastore'
:
DataStore
.
objects
.
all
()[
0
],
'size'
:
data
[
'size'
],
}
d
=
Disk
.
create_empty
(
instance
=
inst
,
user
=
self
.
user
,
**
kwargs
)
else
:
kwargs
=
{
'name'
:
data
[
'name'
],
'url'
:
data
[
'url'
],
}
Disk
.
create_from_url_async
(
instance
=
inst
,
user
=
self
.
user
,
**
kwargs
)
d
=
None
return
d
class
VmDownloadDiskForm
(
forms
.
Form
):
name
=
forms
.
CharField
(
max_length
=
100
,
label
=
_
(
"Name"
))
url
=
forms
.
CharField
()
@property
@property
def
helper
(
self
):
def
helper
(
self
):
helper
=
FormHelper
()
helper
=
FormHelper
(
self
)
helper
.
form_show_labels
=
False
helper
.
add_input
(
Submit
(
"submit"
,
_
(
"Create"
),
helper
.
layout
=
Layout
(
Field
(
"is_template"
,
type
=
"hidden"
),
Field
(
"object_pk"
,
type
=
"hidden"
),
Field
(
"name"
,
placeholder
=
_
(
"Name"
)),
Field
(
"size"
,
placeholder
=
_
(
"Disk size (for example: 20GB, "
"1500MB)"
)),
Field
(
"url"
,
placeholder
=
_
(
"URL to an ISO image"
)),
AnyTag
(
"div"
,
HTML
(
_
(
"Either specify the size for an empty disk or a URL "
"to an ISO image!"
)
),
css_class
=
"alert alert-info"
,
style
=
"padding: 5px; text-align: justify;"
,
),
)
helper
.
add_input
(
Submit
(
"submit"
,
_
(
"Add"
),
css_class
=
"btn btn-success"
))
css_class
=
"btn btn-success"
))
helper
.
form_tag
=
False
return
helper
return
helper
...
...
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