# 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
        LOG.info('Creating group with name %s' % (name))
        try:
            group = api.cloudkittyclient(request).rating.hashmap.create_group(
                name=name)
            messages.success(
                request,
                _('Group was successfully created'))
            return group
        except Exception:
            horizon_exceptions.handle(
                request,
                _("Unable to create group."))


class BaseForm(forms.SelfHandlingForm):
    type = forms.ChoiceField(label=_("Type"),
                             choices=(("flat", _("Flat")),
                                      ("rate", _("Rate"))))
    cost = forms.DecimalField(label=_("Cost"))
    url = "horizon:admin:hashmap:group_create"
    group_id = forms.DynamicChoiceField(label=_("Group"),
                                        required=False,
                                        add_item_link=url)
    tenant_id = forms.ChoiceField(label=_("Project"),
                                  required=False)
    fields_order = ['type', 'cost', 'group_id']

    def __init__(self, request, *args, **kwargs):
        super(BaseForm, self).__init__(request, *args, **kwargs)
        # self.order_fields(self.fields_order)

# 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

        LOG.info('Creating group with name %s' % (name))
        try:
            group = api.cloudkittyclient(request).rating.hashmap.create_group(
                name=name)
            messages.success(
                request,
                _('Group was successfully created'))
            return group
        except Exception:
            horizon_exceptions.handle(
                request,
                _("Unable to create group."))


class BaseForm(forms.SelfHandlingForm):
    type = forms.ChoiceField(label=_("Type"),
                             choices=(("flat", _("Flat")),
                                      ("rate", _("Rate"))))
    cost = forms.DecimalField(label=_("Cost"))
    url = "horizon:admin:hashmap:group_create"
    group_id = forms.DynamicChoiceField(label=_("Group"),
                                        required=False,
                                        add_item_link=url)
    tenant_id = forms.ChoiceField(label=_("Project"),
                                  required=False)
    fields_order = ['type', 'cost', 'group_id']

    def __init__(self, request, *args, **kwargs):
        super(BaseForm, self).__init__(request, *args, **kwargs)
        # self.order_fields(self.fields_order)

        groups = api.cloudkittyclient(