Commit 8772b304 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

API call for resources

parent 46b2a781
......@@ -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
......
......@@ -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'),
......
......@@ -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', '')
......
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment