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
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
Show 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):
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
):
size_in_bytes
=
self
.
cleaned_data
.
get
(
"size"
)
...
...
@@ -854,66 +860,23 @@ class LeaseForm(forms.ModelForm):
" GB or MB!"
))
return
size_in_bytes
def
clean
(
self
):
cleaned_data
=
self
.
cleaned_data
size
=
cleaned_data
.
get
(
"size"
)
url
=
cleaned_data
.
get
(
"url"
)
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
@property
def
helper
(
self
):
helper
=
FormHelper
(
self
)
helper
.
form_tag
=
False
return
helper
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
def
helper
(
self
):
helper
=
FormHelper
()
helper
.
form_show_labels
=
False
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"
),
helper
=
FormHelper
(
self
)
helper
.
add_input
(
Submit
(
"submit"
,
_
(
"Create"
),
css_class
=
"btn btn-success"
))
helper
.
form_tag
=
False
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