コード例 #1
0
ファイル: views.py プロジェクト: blik/blik-resource-inventory
    def get_connection_params(self, request):
        """ Implement GET method """
        if request.GET.get('spec_id', None):
            connection = ConnectionOperationalAPI()
            conn_info = connection.getConnectionInfo(request.GET['spec_id']).to_dict()
            conn_spec = self._search_spec(ELEM_TYPES['IS_CONN'], conn_info['specification_name'])[0]

            connected_type = conn_spec['connected_type']
            connecting_type = conn_spec['connecting_type']
            resource = ResourceOperationalAPI()

            res_filter = {'specification_name': str(connecting_type)}
            raw_connecting_res_list = self._search_elem(res_filter, resource)

            connecting_res_list = []
            if raw_connecting_res_list:
                for res in raw_connecting_res_list:
                    connecting_res_dict = dict()
                    connecting_res_dict['connecting_res_id'] = res['id']
                    connecting_res_dict['res_name'] = res['resource_name']
                    connecting_res_list.append(connecting_res_dict)

            res_filter = {'specification_name': str(connected_type)}
            raw_connected_res_list = self._search_elem(res_filter, resource)
            connected_res_list = []
            if raw_connected_res_list:
                for res in raw_connected_res_list:
                    connected_res_dict = dict()
                    connected_res_dict['connected_res_id'] = res['id']
                    connected_res_dict['res_name'] = res['resource_name']
                    connected_res_list.append(connected_res_dict)

            # for TreeMenu
            spec_params_json = json.dumps(conn_spec['params_spec'])
            to_text = spec_params_json.replace('param_name','text')
            items = to_text.replace('children_spec','items')

            json_data = {'conn_spec': conn_spec['params_spec'],
                         'conn_info': conn_info,
                         'items': json.loads(items),
                         'connected_type': conn_spec.get('connected_type', None),
                         'connecting_type': conn_spec.get('connecting_type', None),
                         'connected_res_list': connected_res_list,
                         'connecting_res_list': connecting_res_list}
            return HttpResponse(json.dumps(json_data), mimetype="application/json")

        return HttpResponse()