Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
8772b304
Commit
8772b304
authored
Apr 05, 2013
by
Giorgos Korfiatis
Browse files
API call for resources
parent
46b2a781
Changes
4
Hide whitespace changes
Inline
Side-by-side
snf-astakos-app/astakos/api/quotas.py
View file @
8772b304
...
...
@@ -37,10 +37,11 @@ from django.http import HttpResponse
from
synnefo.lib.db.transaction
import
commit_on_success_strict
from
astakos.api.util
import
json_response
from
astakos.im.api
import
api_method
as
generic_api_method
from
astakos.im.api.user
import
api_method
as
user_api_method
from
astakos.im.api.service
import
api_method
as
service_api_method
from
astakos.im.api.faults
import
BadRequest
,
InternalServerError
from
astakos.im.quotas
import
get_user_quotas
from
astakos.im.quotas
import
get_user_quotas
,
get_resources
import
astakos.quotaholder.exception
as
qh_exception
from
astakos.quotaholder.callpoint
import
QuotaholderDjangoDBCallpoint
...
...
@@ -53,6 +54,12 @@ def quotas(request, user=None):
return
json_response
(
result
)
@
generic_api_method
(
http_method
=
'GET'
)
def
resources
(
request
):
result
=
get_resources
()
return
json_response
(
result
)
@
csrf_exempt
def
commissions
(
request
):
method
=
request
.
method
...
...
snf-astakos-app/astakos/api/urls.py
View file @
8772b304
...
...
@@ -36,6 +36,7 @@ from django.conf.urls.defaults import patterns, url
urlpatterns
=
patterns
(
'astakos.api.quotas'
,
url
(
r
'^quotas/?$'
,
'quotas'
),
url
(
r
'^resources/?$'
,
'resources'
),
url
(
r
'^commissions/?$'
,
'commissions'
),
url
(
r
'^commissions/action/?$'
,
'resolve_pending_commissions'
),
url
(
r
'^commissions/(?P<serial>\d+)/?$'
,
'get_commission'
),
...
...
snf-astakos-app/astakos/im/models.py
View file @
8772b304
...
...
@@ -177,6 +177,12 @@ class Resource(models.Model):
def
full_name
(
self
):
return
str
(
self
)
def
get_info
(
self
):
return
{
'service'
:
str
(
self
.
service
),
'description'
:
self
.
desc
,
'unit'
:
self
.
unit
,
}
@
property
def
help_text
(
self
):
return
get_presentation
(
str
(
self
)).
get
(
'help_text'
,
''
)
...
...
snf-astakos-app/astakos/im/quotas.py
View file @
8772b304
...
...
@@ -99,6 +99,22 @@ def set_user_quota(quotas):
qh
.
set_holder_quota
(
quotas
)
def
get_resources
(
resources
=
None
,
services
=
None
):
if
resources
is
None
:
rs
=
Resource
.
objects
.
all
()
else
:
rs
=
Resource
.
objects
.
filter
(
name__in
=
resources
)
if
services
is
not
None
:
rs
=
rs
.
filter
(
service__in
=
services
)
resource_dict
=
{}
for
r
in
rs
:
resource_dict
[
r
.
full_name
()]
=
r
.
get_info
()
return
resource_dict
def
get_default_quota
():
_DEFAULT_QUOTA
=
{}
resources
=
Resource
.
objects
.
select_related
(
'service'
).
all
()
...
...
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