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

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 import api_method as generic_api_method
from import api_method as user_api_method
from import api_method as service_api_method
from import BadRequest, InternalServerError
from import get_user_quotas
from 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)
def resources(request):
result = get_resources()
return json_response(result)
def commissions(request):
method = request.method
......@@ -36,6 +36,7 @@ from django.conf.urls.defaults import patterns, url
urlpatterns = patterns(
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,
def help_text(self):
return get_presentation(str(self)).get('help_text', '')
......@@ -99,6 +99,22 @@ def set_user_quota(quotas):
def get_resources(resources=None, services=None):
if resources is None:
rs = Resource.objects.all()
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():
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