Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
3743cec7
authored
Feb 27, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: better way to handle disk add origin
parent
df4f36a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
circle/dashboard/forms.py
+5
-5
circle/dashboard/views.py
+16
-7
No files found.
circle/dashboard/forms.py
View file @
3743cec7
...
...
@@ -729,14 +729,14 @@ class DiskAddForm(forms.Form):
name
=
forms
.
CharField
()
size
=
forms
.
CharField
(
widget
=
FileSizeWidget
,
required
=
False
)
url
=
forms
.
CharField
(
required
=
False
)
add_to
=
forms
.
CharField
()
is_template
=
forms
.
CharField
()
object_pk
=
forms
.
CharField
()
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
add_to
=
kwargs
.
pop
(
"add_to
"
)
self
.
is_template
=
kwargs
.
pop
(
"is_template
"
)
self
.
object_pk
=
kwargs
.
pop
(
"object_pk"
)
super
(
DiskAddForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
initial
[
'
add_to'
]
=
self
.
add_to
self
.
initial
[
'
is_template'
]
=
1
if
self
.
is_template
is
True
else
0
self
.
initial
[
'object_pk'
]
=
self
.
object_pk
def
clean_size
(
self
):
...
...
@@ -773,7 +773,7 @@ class DiskAddForm(forms.Form):
# TODO
d
=
None
if
self
.
add_to
==
"template"
:
if
self
.
is_template
:
vm_or_temp
=
InstanceTemplate
.
objects
.
get
(
pk
=
self
.
object_pk
)
else
:
vm_or_temp
=
Instance
.
objects
.
get
(
pk
=
self
.
object_pk
)
...
...
@@ -787,7 +787,7 @@ class DiskAddForm(forms.Form):
helper
=
FormHelper
()
helper
.
form_show_labels
=
False
helper
.
layout
=
Layout
(
Field
(
"
add_to
"
,
type
=
"hidden"
),
Field
(
"
is_template
"
,
type
=
"hidden"
),
Field
(
"object_pk"
,
type
=
"hidden"
),
Field
(
"name"
,
placeholder
=
_
(
"Name"
)),
Field
(
"size"
,
placeholder
=
_
(
"Disk size (for example: 20GB, "
...
...
circle/dashboard/views.py
View file @
3743cec7
...
...
@@ -181,7 +181,7 @@ class VmDetailView(CheckedDetailView):
context
[
'acl'
]
=
get_vm_acl_data
(
instance
)
context
[
'forms'
]
=
{
'disk_add_form'
:
DiskAddForm
(
add_to
=
"instance"
,
object_pk
=
self
.
get_object
()
.
pk
,
is_template
=
False
,
object_pk
=
self
.
get_object
()
.
pk
,
prefix
=
"disk"
),
}
context
[
'os_type_icon'
]
=
instance
.
os_type
.
replace
(
"unknown"
,
...
...
@@ -733,7 +733,7 @@ class TemplateDetail(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
context
=
super
(
TemplateDetail
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'acl'
]
=
get_vm_acl_data
(
self
.
get_object
())
context
[
'disk_add_form'
]
=
DiskAddForm
(
add_to
=
"template"
,
is_template
=
True
,
object_pk
=
self
.
get_object
()
.
pk
,
prefix
=
"disk"
,
)
...
...
@@ -1711,11 +1711,20 @@ class VmMigrateView(SuperuserRequiredMixin, TemplateView):
class
DiskAddView
(
SuperuserRequiredMixin
,
TemplateView
):
def
post
(
self
,
*
args
,
**
kwargs
):
add_to
=
self
.
request
.
POST
.
get
(
"disk-add_to
"
)
is_template
=
self
.
request
.
POST
.
get
(
"disk-is_template
"
)
object_pk
=
self
.
request
.
POST
.
get
(
"disk-object_pk"
)
is_template
=
int
(
is_template
)
==
1
if
is_template
:
obj
=
InstanceTemplate
.
objects
.
get
(
pk
=
object_pk
)
else
:
obj
=
Instance
.
objects
.
get
(
pk
=
object_pk
)
if
not
obj
.
has_level
(
self
.
request
.
user
,
'owner'
):
raise
PermissionDenied
()
form
=
DiskAddForm
(
self
.
request
.
POST
,
add_to
=
add_to
,
object_pk
=
object_pk
,
is_template
=
is_template
,
object_pk
=
object_pk
,
prefix
=
"disk"
)
...
...
@@ -1728,9 +1737,9 @@ class DiskAddView(SuperuserRequiredMixin, TemplateView):
for
i
in
form
.
errors
.
items
()])
messages
.
error
(
self
.
request
,
error
)
if
add_to
==
"template"
:
r
=
InstanceTemplate
.
objects
.
get
(
pk
=
object_pk
)
.
get_absolute_url
()
if
is_template
:
r
=
obj
.
get_absolute_url
()
else
:
r
=
Instance
.
objects
.
get
(
pk
=
object_pk
)
.
get_absolute_url
()
r
=
obj
.
get_absolute_url
()
r
=
"
%
s#resources"
%
r
return
redirect
(
r
)
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