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
59ba9b54
authored
Feb 11, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one: share quota
parent
00bb4f06
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
23 additions
and
6 deletions
+23
-6
one/migrations/0011_auto__add_field_share_owner.py
+0
-0
one/models.py
+9
-0
one/templates/box-templatelist.html
+3
-2
one/templates/home.html
+1
-1
one/views.py
+9
-3
school/views.py
+1
-0
No files found.
one/migrations/0011_auto__add_field_share_owner.py
0 → 100644
View file @
59ba9b54
This diff is collapsed.
Click to expand it.
one/models.py
View file @
59ba9b54
...
@@ -79,6 +79,14 @@ class UserCloudDetails(models.Model):
...
@@ -79,6 +79,14 @@ class UserCloudDetails(models.Model):
return
c
return
c
def
get_instance_pc
(
self
):
def
get_instance_pc
(
self
):
return
100
*
self
.
get_weighted_instance_count
()
/
self
.
instance_quota
return
100
*
self
.
get_weighted_instance_count
()
/
self
.
instance_quota
def
get_weighted_share_count
(
self
):
c
=
0
for
i
in
Share
.
objects
.
filter
(
owner
=
self
.
user
)
.
all
():
c
=
c
+
i
.
template
.
instance_type
.
credit
*
i
.
instance_limit
return
c
def
get_share_pc
(
self
):
return
100
*
self
.
get_weighted_share_count
()
/
self
.
share_quota
def
set_quota
(
sender
,
instance
,
created
,
**
kwargs
):
def
set_quota
(
sender
,
instance
,
created
,
**
kwargs
):
if
not
StoreApi
.
userexist
(
instance
.
user
.
username
):
if
not
StoreApi
.
userexist
(
instance
.
user
.
username
):
...
@@ -168,6 +176,7 @@ class Share(models.Model):
...
@@ -168,6 +176,7 @@ class Share(models.Model):
help_text
=
_
(
'Maximal count of instances launchable for this share.'
))
help_text
=
_
(
'Maximal count of instances launchable for this share.'
))
per_user_limit
=
models
.
IntegerField
(
verbose_name
=
_
(
'per user limit'
),
per_user_limit
=
models
.
IntegerField
(
verbose_name
=
_
(
'per user limit'
),
help_text
=
_
(
'Maximal count of instances launchable by a single user.'
))
help_text
=
_
(
'Maximal count of instances launchable by a single user.'
))
owner
=
models
.
ForeignKey
(
User
,
null
=
True
,
blank
=
True
)
def
get_running_or_stopped
(
self
):
def
get_running_or_stopped
(
self
):
return
Instance
.
objects
.
all
()
.
exclude
(
state
=
'DONE'
)
.
filter
(
share
=
self
)
.
count
()
return
Instance
.
objects
.
all
()
.
exclude
(
state
=
'DONE'
)
.
filter
(
share
=
self
)
.
count
()
...
...
one/templates/box-templatelist.html
View file @
59ba9b54
{% load i18n %}
{% load i18n %}
{% load l10n %}
{% get_current_language as LANGUAGE_CODE %}
{% get_current_language as LANGUAGE_CODE %}
<div
class=
"contentblock"
id=
"template"
>
<div
class=
"contentblock"
id=
"template"
>
<h2>
{% trans "Templates" %}
</h2>
<h2>
{% trans "Templates" %}
</h2>
...
@@ -131,9 +132,9 @@
...
@@ -131,9 +132,9 @@
<li
class=
"wm small"
>
<li
class=
"wm small"
>
<div
class=
"summary"
>
<div
class=
"summary"
>
<div
class=
"quota"
>
<div
class=
"quota"
>
<div
class=
"used"
style=
"background-color: rgba(0,255,0,0.2); width:
19
%"
></div>
<div
class=
"used"
style=
"background-color: rgba(0,255,0,0.2); width:
{{userdetails.get_share_pc|unlocalize}}
%"
></div>
</div>
</div>
<div
class=
"name"
>
{% blocktrans with used=
19 all=100
%}Share quota: {{used}}/{{all}}{% endblocktrans %}
</div>
<div
class=
"name"
>
{% blocktrans with used=
userdetails.get_weighted_share_count all=userdetails.share_quota
%}Share quota: {{used}}/{{all}}{% endblocktrans %}
</div>
<div
class=
"clear"
></div>
<div
class=
"clear"
></div>
</div>
</div>
</li>
</li>
...
...
one/templates/home.html
View file @
59ba9b54
...
@@ -65,7 +65,7 @@
...
@@ -65,7 +65,7 @@
<li
class=
"wm small"
>
<li
class=
"wm small"
>
<div
class=
"summary"
>
<div
class=
"summary"
>
<div
class=
"quota"
>
<div
class=
"quota"
>
<div
class=
"used"
style=
"background-color: rgba(0,255,0,0.2); width: {{userdetails.get_instance_pc}}%"
></div>
<div
class=
"used"
style=
"background-color: rgba(0,255,0,0.2); width: {{userdetails.get_instance_pc
|unlocalize
}}%"
></div>
</div>
</div>
<div
class=
"name"
>
{% blocktrans with used=userdetails.get_weighted_instance_count all=userdetails.instance_quota %}Personal quota: {{used}}/{{all}}{% endblocktrans %}
</div>
<div
class=
"name"
>
{% blocktrans with used=userdetails.get_weighted_instance_count all=userdetails.instance_quota %}Personal quota: {{used}}/{{all}}{% endblocktrans %}
</div>
<div
class=
"clear"
></div>
<div
class=
"clear"
></div>
...
...
one/views.py
View file @
59ba9b54
...
@@ -137,6 +137,9 @@ ajax_template_wizard = login_required(AjaxTemplateWizard.as_view())
...
@@ -137,6 +137,9 @@ ajax_template_wizard = login_required(AjaxTemplateWizard.as_view())
class
AjaxShareWizard
(
View
):
class
AjaxShareWizard
(
View
):
def
get
(
self
,
request
,
id
,
gid
=
None
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
id
,
gid
=
None
,
*
args
,
**
kwargs
):
det
=
UserCloudDetails
.
objects
.
get
(
user
=
request
.
user
)
if
det
.
get_weighted_share_count
()
>=
det
.
share_quota
:
return
HttpResponse
(
unicode
(
_
(
'You do not have any free share quota.'
)))
types
=
TYPES_L
types
=
TYPES_L
types
[
0
][
'default'
]
=
True
types
[
0
][
'default'
]
=
True
for
i
,
t
in
enumerate
(
types
):
for
i
,
t
in
enumerate
(
types
):
...
@@ -146,13 +149,14 @@ class AjaxShareWizard(View):
...
@@ -146,13 +149,14 @@ class AjaxShareWizard(View):
if
gid
:
if
gid
:
gid
=
get_object_or_404
(
Group
,
id
=
gid
)
gid
=
get_object_or_404
(
Group
,
id
=
gid
)
return
render_to_response
(
'new-share.html'
,
RequestContext
(
request
,{
return
render_to_response
(
'new-share.html'
,
RequestContext
(
request
,
{
'base'
:
get_object_or_404
(
Template
,
id
=
id
),
'base'
:
get_object_or_404
(
Template
,
id
=
id
),
'groups'
:
request
.
user
.
person_set
.
all
()[
0
]
.
owned_groups
.
all
(),
'groups'
:
request
.
user
.
person_set
.
all
()[
0
]
.
owned_groups
.
all
(),
'types'
:
types
,
'types'
:
types
,
'group'
:
gid
,
'group'
:
gid
,
}))
}))
def
post
(
self
,
request
,
id
,
gid
=
None
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
id
,
gid
=
None
,
*
args
,
**
kwargs
):
det
=
UserCloudDetails
.
objects
.
get
(
user
=
request
.
user
)
base
=
get_object_or_404
(
Template
,
id
=
id
)
base
=
get_object_or_404
(
Template
,
id
=
id
)
if
base
.
owner
!=
request
.
user
and
not
base
.
public
and
not
request
.
user
.
is_superuser
:
if
base
.
owner
!=
request
.
user
and
not
base
.
public
and
not
request
.
user
.
is_superuser
:
raise
PermissionDenied
()
raise
PermissionDenied
()
...
@@ -168,10 +172,12 @@ class AjaxShareWizard(View):
...
@@ -168,10 +172,12 @@ class AjaxShareWizard(View):
if
not
stype
in
TYPES
.
keys
():
if
not
stype
in
TYPES
.
keys
():
raise
PermissionDenied
()
raise
PermissionDenied
()
il
=
request
.
POST
[
'instance_limit'
]
il
=
request
.
POST
[
'instance_limit'
]
# TODO check quota
if
det
.
get_weighted_share_count
()
+
int
(
il
)
*
base
.
instance_type
.
credit
>
det
.
share_quota
:
messages
.
error
(
request
,
_
(
'You do not have enough free share quota.'
))
return
redirect
(
'/'
)
s
=
Share
.
objects
.
create
(
name
=
request
.
POST
[
'name'
],
description
=
request
.
POST
[
'description'
],
s
=
Share
.
objects
.
create
(
name
=
request
.
POST
[
'name'
],
description
=
request
.
POST
[
'description'
],
type
=
stype
,
instance_limit
=
il
,
per_user_limit
=
request
.
POST
[
'per_user_limit'
],
type
=
stype
,
instance_limit
=
il
,
per_user_limit
=
request
.
POST
[
'per_user_limit'
],
group
=
group
,
template
=
base
)
group
=
group
,
template
=
base
,
owner
=
request
.
user
)
messages
.
success
(
request
,
_
(
'Successfully shared
%
s.'
)
%
base
)
messages
.
success
(
request
,
_
(
'Successfully shared
%
s.'
)
%
base
)
return
redirect
(
group
)
return
redirect
(
group
)
ajax_share_wizard
=
login_required
(
AjaxShareWizard
.
as_view
())
ajax_share_wizard
=
login_required
(
AjaxShareWizard
.
as_view
())
...
...
school/views.py
View file @
59ba9b54
...
@@ -172,6 +172,7 @@ def group_show(request, gid):
...
@@ -172,6 +172,7 @@ def group_show(request, gid):
'mytemplates'
:
mytemplates
,
'mytemplates'
:
mytemplates
,
'publictemplates'
:
publictemplates
,
'publictemplates'
:
publictemplates
,
'noshare'
:
noshare
,
'noshare'
:
noshare
,
'userdetails'
:
UserCloudDetails
.
objects
.
get
(
user
=
request
.
user
),
}))
}))
@login_required
@login_required
...
...
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