Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
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
226d2b8d
authored
Dec 04, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: improve VmCreate view
parent
cdac5b0e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
21 deletions
+20
-21
circle/dashboard/views/vm.py
+20
-21
No files found.
circle/dashboard/views/vm.py
View file @
226d2b8d
...
...
@@ -983,6 +983,17 @@ class VmCreate(LoginRequiredMixin, TemplateView):
else
:
return
[
'dashboard/nojs-wrapper.html'
]
def
get_template
(
self
,
request
,
pk
):
try
:
template
=
InstanceTemplate
.
objects
.
get
(
pk
=
int
(
pk
))
except
(
ValueError
,
InstanceTemplate
.
DoesNotExist
):
raise
Http404
()
if
not
template
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
return
template
def
get
(
self
,
request
,
form
=
None
,
*
args
,
**
kwargs
):
if
not
request
.
user
.
has_perm
(
'vm.create_vm'
):
raise
PermissionDenied
()
...
...
@@ -993,9 +1004,7 @@ class VmCreate(LoginRequiredMixin, TemplateView):
template_pk
=
form
.
template
.
pk
if
template_pk
:
template
=
get_object_or_404
(
InstanceTemplate
,
pk
=
template_pk
)
if
not
template
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
template
=
self
.
get_template
(
request
,
template_pk
)
if
form
is
None
:
form
=
self
.
form_class
(
user
=
request
.
user
,
template
=
template
)
else
:
...
...
@@ -1020,33 +1029,21 @@ class VmCreate(LoginRequiredMixin, TemplateView):
})
return
self
.
render_to_response
(
context
)
def
__create_normal
(
self
,
request
,
*
args
,
**
kwargs
):
user
=
request
.
user
template
=
InstanceTemplate
.
objects
.
get
(
pk
=
request
.
POST
.
get
(
"template"
))
# permission check
if
not
template
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
args
=
{
"template"
:
template
,
"owner"
:
user
}
instances
=
[
Instance
.
create_from_template
(
**
args
)]
def
__create_normal
(
self
,
request
,
template
,
*
args
,
**
kwargs
):
instances
=
[
Instance
.
create_from_template
(
template
=
template
,
owner
=
request
.
user
)]
return
self
.
__deploy
(
request
,
instances
)
def
__create_customized
(
self
,
request
,
*
args
,
**
kwargs
):
def
__create_customized
(
self
,
request
,
template
,
*
args
,
**
kwargs
):
user
=
request
.
user
# no form yet, using POST directly:
template
=
get_object_or_404
(
InstanceTemplate
,
pk
=
request
.
POST
.
get
(
"template"
))
form
=
self
.
form_class
(
request
.
POST
,
user
=
request
.
user
,
template
=
template
)
if
not
form
.
is_valid
():
return
self
.
get
(
request
,
form
,
*
args
,
**
kwargs
)
post
=
form
.
cleaned_data
if
not
template
.
has_level
(
user
,
'user'
):
raise
PermissionDenied
()
ikwargs
=
{
'name'
:
post
[
'name'
],
'template'
:
template
,
...
...
@@ -1099,6 +1096,8 @@ class VmCreate(LoginRequiredMixin, TemplateView):
if
not
request
.
user
.
has_perm
(
'vm.create_vm'
):
raise
PermissionDenied
()
template
=
self
.
get_template
(
request
,
request
.
POST
.
get
(
"template"
))
# limit chekcs
try
:
limit
=
user
.
profile
.
instance_limit
...
...
@@ -1124,7 +1123,7 @@ class VmCreate(LoginRequiredMixin, TemplateView):
request
.
POST
.
get
(
"customized"
)
is
None
else
self
.
__create_customized
)
return
create_func
(
request
,
*
args
,
**
kwargs
)
return
create_func
(
request
,
template
,
*
args
,
**
kwargs
)
@require_GET
...
...
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