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
cf8ada05
authored
Apr 12, 2013
by
Bence Dányi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: share quota checked on template editing
parent
1ba601d9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
1 deletions
+32
-1
one/models.py
+21
-0
one/views.py
+11
-1
No files found.
one/models.py
View file @
cf8ada05
...
@@ -387,6 +387,27 @@ class Template(models.Model):
...
@@ -387,6 +387,27 @@ class Template(models.Model):
def
get_credits_per_instance
(
self
):
def
get_credits_per_instance
(
self
):
return
self
.
instance_type
.
credit
return
self
.
instance_type
.
credit
def
get_shares_for
(
self
,
user
=
None
):
shares
=
Share
.
objects
.
all
()
.
filter
(
template
=
self
)
if
user
:
return
shares
.
filter
(
owner
=
user
)
else
:
return
shares
def
get_share_quota_usage_for
(
self
,
user
=
None
):
shares
=
self
.
get_shares_for
(
user
)
usage
=
0
for
share
in
shares
:
usage
+=
share
.
instance_limit
*
self
.
get_credits_per_instance
()
return
usage
def
get_share_quota_usage_for_user_with_type
(
self
,
type
,
user
=
None
):
shares
=
self
.
get_shares_for
(
user
)
usage
=
0
for
share
in
shares
:
usage
+=
share
.
instance_limit
*
type
.
credit
return
usage
class
Instance
(
models
.
Model
):
class
Instance
(
models
.
Model
):
"""Virtual machine instance."""
"""Virtual machine instance."""
name
=
models
.
CharField
(
max_length
=
100
,
name
=
models
.
CharField
(
max_length
=
100
,
...
...
one/views.py
View file @
cf8ada05
...
@@ -147,9 +147,19 @@ class AjaxTemplateEditWizard(View):
...
@@ -147,9 +147,19 @@ class AjaxTemplateEditWizard(View):
}))
}))
def
post
(
self
,
request
,
id
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
id
,
*
args
,
**
kwargs
):
template
=
get_object_or_404
(
Template
,
id
=
id
)
template
=
get_object_or_404
(
Template
,
id
=
id
)
user_details
=
UserCloudDetails
.
objects
.
get
(
user
=
request
.
user
)
if
template
.
owner
!=
request
.
user
and
not
template
.
public
and
not
request
.
user
.
is_superuser
:
if
template
.
owner
!=
request
.
user
and
not
template
.
public
and
not
request
.
user
.
is_superuser
:
raise
PermissionDenied
()
raise
PermissionDenied
()
template
.
instance_type_id
=
request
.
POST
[
'size'
]
instance_type
=
get_object_or_404
(
InstanceType
,
id
=
request
.
POST
[
'size'
])
current_used_share_quota
=
user_details
.
get_weighted_share_count
()
current_used_share_quota_without_template
=
current_used_share_quota
-
template
.
get_share_quota_usage_for
(
request
.
user
)
new_quota_for_current_template
=
template
.
get_share_quota_usage_for_user_with_type
(
instance_type
,
request
.
user
)
new_used_share_quota
=
current_used_share_quota_without_template
+
new_quota_for_current_template
allow_type_modify
=
True
if
new_used_share_quota
<=
user_details
.
share_quota
else
False
if
not
allow_type_modify
:
messages
.
error
(
request
,
_
(
'You do not have enough free share quota.'
))
return
redirect
(
home
)
template
.
instance_type
=
instance_type
template
.
description
=
request
.
POST
[
'description'
]
template
.
description
=
request
.
POST
[
'description'
]
template
.
name
=
request
.
POST
[
'name'
]
template
.
name
=
request
.
POST
[
'name'
]
template
.
save
()
template
.
save
()
...
...
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