# Path: cloudkittydashboard/api/cloudkitty.py
# def cloudkittyclient(request):
# def identify(what, name=False, key=None):
# 
# Path: cloudkittydashboard/dashboards/admin/summary/tables.py
# def get_details_link(datum):
# class SummaryTable(tables.DataTable):
#     class Meta(object):
# class TenantSummaryTable(tables.DataTable):
#     class Meta(object):


from django.utils.translation import ugettext_lazy as _
from horizon import tables
from openstack_dashboard.api import keystone as api_keystone
from cloudkittydashboard.api import cloudkitty as api
from cloudkittydashboard.dashboards.admin.summary import tables as sum_tables
        })
        summary = api.identify(summary, key='tenant_id')
        for tenant in summary:
            tenant['name'] = tenants.get(tenant.id, '-')
        summary[-1]['name'] = 'Cloud Total'
        return summary


class TenantDetailsView(tables.DataTableView):
    template_name = 'admin/rating_summary/details.html'
    table_class = sum_tables.TenantSummaryTable
    page_title = _("Script Details : {{ table.project_id }}")

    def _get_cloud_total_summary(self):
        return api.cloudkittyclient(self.request).report.get_summary(
            groupby=['res_type'], all_tenants=True)['summary']

    def get_data(self):
        tenant_id = self.kwargs['project_id']
        if tenant_id == 'ALL':
            summary = self._get_cloud_total_summary()
        else:
            summary = api.cloudkittyclient(self.request).report.get_summary(
                groupby=['res_type'], tenant_id=tenant_id)['summary']

        summary.append({
            'tenant_id': tenant_id,
            'res_type': 'TOTAL',
            'rate': sum([float(item['rate']) for item in summary]),
        })

# Path: cloudkittydashboard/api/cloudkitty.py
# def cloudkittyclient(request):
# def identify(what, name=False, key=None):
# 
# Path: cloudkittydashboard/dashboards/admin/summary/tables.py
# def get_details_link(datum):
# class SummaryTable(tables.DataTable):
#     class Meta(object):
# class TenantSummaryTable(tables.DataTable):
#     class Meta(object):


# Path: cloudkittydashboard/dashboards/admin/summary/views.py
from django.utils.translation import ugettext_lazy as _
from horizon import tables
from openstack_dashboard.api import keystone as api_keystone
from cloudkittydashboard.api import cloudkitty as api
from cloudkittydashboard.dashboards.admin.summary import tables as sum_tables

        })
        summary = api.identify(summary, key='tenant_id')
        for tenant in summary:
            tenant['name'] = tenants.get(tenant.id, '-')
        summary[-1]['name'] = 'Cloud Total'
        return summary


class TenantDetailsView(tables.DataTableView):
    template_name = 'admin/rating_summary/details.html'
    table_class = sum_tables.TenantSummaryTable
    page_title = _("Script Details : {{ table.project_id }}")

    def _get_cloud_total_summary(self):
        return api.cloudkittyclient(self.request).report.get_summary(
            groupby=['res_type'], all_tenants=True)['summary']

    def get_data(self):
        tenant_id = self.kwargs['project_id']
        if tenant_id == 'ALL':
            summary = self._get_cloud_total_summary()
        else:
            summary = api.cloudkittyclient(self.request).report.get_summary(
                groupby=['res_type'], tenant_id=tenant_id)['summary']

        summary.append({
            'tenant_id': tenant_id,
            'res_type': 'TOTAL',
            'rate': sum([float(item['rate']) for item in summary]),
        })

        summary = api.identify(summary, key='res_type', name=True)