@@ -33,49 +33,54 @@ class IndexView(tables.DataTableView):
3333 table_class = sum_tables .SummaryTable
3434
3535 def get_data (self ):
36- summary = api .cloudkittyclient (self .request ).report .get_summary (
37- groupby = ['tenant_id' ], all_tenants = True )['summary' ]
36+ summary = api .cloudkittyclient (
37+ self .request , version = '2' ).summary .get_summary (
38+ groupby = ['project_id' ],
39+ response_format = 'object' )
3840
39- tenants , _ = api_keystone .tenant_list (self .request )
41+ tenants , unused = api_keystone .tenant_list (self .request )
4042 tenants = {tenant .id : tenant .name for tenant in tenants }
41- summary .append ({
42- 'tenant_id' : 'ALL' ,
43- 'rate' : sum ([float (item ['rate' ]) for item in summary ]),
43+ data = summary .get ('results' )
44+
45+ total = sum ([r .get ('rate' ) for r in data ])
46+ data .append ({
47+ 'project_id' : 'ALL' ,
48+ 'rate' : total ,
4449 })
45- summary = api .identify (summary , key = 'tenant_id' )
46- for tenant in summary :
50+ data = api .identify (data , key = 'project_id' )
51+ for tenant in data :
52+ tenant ['tenant_id' ] = tenant .get ('project_id' )
4753 tenant ['name' ] = tenants .get (tenant .id , '-' )
48- summary [- 1 ]['name' ] = 'Cloud Total'
49- for tenant in summary :
5054 tenant ['rate' ] = utils .formatRate (tenant ['rate' ],
5155 rate_prefix , rate_postfix )
52- return summary
56+ data [- 1 ]['name' ] = _ ('Cloud Total' )
57+ return data
5358
5459
5560class TenantDetailsView (tables .DataTableView ):
5661 template_name = 'admin/rating_summary/details.html'
5762 table_class = sum_tables .TenantSummaryTable
5863 page_title = _ ("Script details: {{ table.project_id }}" )
5964
60- def _get_cloud_total_summary (self ):
61- return api .cloudkittyclient (self .request ).report .get_summary (
62- groupby = ['res_type' ], all_tenants = True )['summary' ]
63-
6465 def get_data (self ):
6566 tenant_id = self .kwargs ['project_id' ]
67+
6668 if tenant_id == 'ALL' :
67- summary = self ._get_cloud_total_summary ()
69+ summary = api .cloudkittyclient (
70+ self .request , version = '2' ).summary .get_summary (
71+ groupby = ['type' ], response_format = 'object' )
6872 else :
69- summary = api .cloudkittyclient (self .request ).report .get_summary (
70- groupby = ['res_type' ], tenant_id = tenant_id )['summary' ]
73+ summary = api .cloudkittyclient (
74+ self .request , version = '2' ).summary .get_summary (
75+ filters = {'project_id' : tenant_id },
76+ groupby = ['type' ], response_format = 'object' )
7177
72- summary .append ({
73- 'tenant_id' : tenant_id ,
74- 'res_type' : 'TOTAL' ,
75- 'rate' : sum ([float (item ['rate' ]) for item in summary ]),
76- })
77- summary = api .identify (summary , key = 'res_type' , name = True )
78- for item in summary :
78+ data = summary .get ('results' )
79+ total = sum ([r .get ('rate' ) for r in data ])
80+ data .append ({'type' : 'TOTAL' , 'rate' : total })
81+
82+ for item in data :
7983 item ['rate' ] = utils .formatRate (item ['rate' ],
8084 rate_prefix , rate_postfix )
81- return summary
85+
86+ return data
0 commit comments