# Path: cloudkittydashboard/api/cloudkitty.py
# def cloudkittyclient(request):
# def identify(what, name=False, key=None):


from decimal import Decimal
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions as horizon_exceptions
from horizon import forms
from horizon import messages
from keystoneauth1 import exceptions
from cloudkittydashboard.api import cloudkitty as api
from openstack_dashboard import api as api_keystone
import logging
                                     attrs={'readonly': 'readonly'}))
    tenant_id = forms.ChoiceField(label=_("Project"),
                                  required=False)

    def handle(self, request, data):
        mapping_mgr = api.cloudkittyclient(request).rating.hashmap
        mapping = {}
        for k, v in data.items():
            if v:
                mapping[k] = float(v) if isinstance(v, Decimal) else v
        mapping['mapping_id'] = self.initial['mapping_id']
        return mapping_mgr.update_mapping(**mapping)


class EditServiceMappingForm(BaseEditMappingForm, CreateServiceMappingForm):
    fields_order = ['service_id', 'mapping_id', 'type', 'cost', 'group_id',
                    'tenant_id']


class EditFieldMappingForm(BaseEditMappingForm, CreateFieldMappingForm):
    fields_order = [
        'field_id',
        'mapping_id',
        'value',
        'type',
        'cost',
        'group_id',
        'tenant_id']



# Path: cloudkittydashboard/api/cloudkitty.py
# def cloudkittyclient(request):
# def identify(what, name=False, key=None):


# Path: cloudkittydashboard/dashboards/admin/hashmap/forms.py
from decimal import Decimal
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions as horizon_exceptions
from horizon import forms
from horizon import messages
from keystoneauth1 import exceptions
from cloudkittydashboard.api import cloudkitty as api
from openstack_dashboard import api as api_keystone
import logging

                                     attrs={'readonly': 'readonly'}))
    tenant_id = forms.ChoiceField(label=_("Project"),
                                  required=False)

    def handle(self, request, data):
        mapping_mgr = api.cloudkittyclient(request).rating.hashmap
        mapping = {}
        for k, v in data.items():
            if v:
                mapping[k] = float(v) if isinstance(v, Decimal) else v
        mapping['mapping_id'] = self.initial['mapping_id']
        return mapping_mgr.update_mapping(**mapping)


class EditServiceMappingForm(BaseEditMappingForm, CreateServiceMappingForm):
    fields_order = ['service_id', 'mapping_id', 'type', 'cost', 'group_id',
                    'tenant_id']


class EditFieldMappingForm(BaseEditMappingForm, CreateFieldMappingForm):
    fields_order = [
        'field_id',
        'mapping_id',
        'value',
        'type',
        'cost',
        'group_id',
        'tenant_id']



class BaseEditThresholdForm(BaseThresholdForm):