# Path: cloudkittydashboard/api/cloudkitty.py
# def cloudkittyclient(request):
# def identify(what, name=False, key=None):
# 
# Path: cloudkittydashboard/dashboards/project/rating/tables.py
# class SummaryTable(tables.DataTable):
#     class Meta(object):
# 
# Path: cloudkittydashboard/utils.py
# class TemplatizableDict(dict):
#     """Class allowing to pass a dict to horizon templates"""
# 
#     def __getattr__(self, key):
#         if key in self.keys():
#             return self[key]
#         raise AttributeError("Object has no {} attribute".format(key))
# 
#     def __setattr__(self, key, val):
#         self[key] = val


import json
from django.conf import settings
from django import http
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tables
from cloudkittydashboard.api import cloudkitty as api
from cloudkittydashboard.dashboards.project.rating \
    import tables as rating_tables
from cloudkittydashboard.utils import TemplatizableDict
# Copyright 2015 Objectif Libre
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.




class IndexView(tables.DataTableView):
    table_class = rating_tables.SummaryTable
    template_name = 'project/rating/index.html'

    def get_data(self):
        summary = api.cloudkittyclient(self.request).report.get_summary(
            tenant_id=self.request.user.tenant_id,
            groupby=['tenant_id', 'res_type'])['summary']

# Path: cloudkittydashboard/api/cloudkitty.py
# def cloudkittyclient(request):
# def identify(what, name=False, key=None):
# 
# Path: cloudkittydashboard/dashboards/project/rating/tables.py
# class SummaryTable(tables.DataTable):
#     class Meta(object):
# 
# Path: cloudkittydashboard/utils.py
# class TemplatizableDict(dict):
#     """Class allowing to pass a dict to horizon templates"""
# 
#     def __getattr__(self, key):
#         if key in self.keys():
#             return self[key]
#         raise AttributeError("Object has no {} attribute".format(key))
# 
#     def __setattr__(self, key, val):
#         self[key] = val


# Path: cloudkittydashboard/dashboards/project/rating/views.py
import json
from django.conf import settings
from django import http
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tables
from cloudkittydashboard.api import cloudkitty as api
from cloudkittydashboard.dashboards.project.rating \
    import tables as rating_tables
from cloudkittydashboard.utils import TemplatizableDict

# Copyright 2015 Objectif Libre
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.




class IndexView(tables.DataTableView):
    table_class = rating_tables.SummaryTable
    template_name = 'project/rating/index.html'

    def get_data(self):
        summary = api.cloudkittyclient(self.request).report.get_summary(
            tenant_id=self.request.user.tenant_id,
            groupby=['tenant_id', 'res_type'])['summary']

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