def get(self, request): data = dict(request.GET.items()) try: system_obj = ComponentSystem.objects.get(name=data['system']) except Exception: return JsonResponse({'result': False}) result = ESBChannel.objects.filter(component_system=system_obj, component_name=data['component']).exists() return JsonResponse({'result': result})
def post(self, request): form = ComponentSystemForm(request.POST) if form.is_valid(): form.save() data = form.cleaned_data data['id'] = form.instance.id data['display_name'] = form.instance.get_display_name() return JsonResponse({'result': True, 'data': data}) error_message = ';'.join([','.join([_(err) for err in field_error]) for field_error in form.errors.values()]) return JsonResponse({'result': False, 'error_message': error_message})
def post(self, request): form = ESBBuffetMappingForm(request.POST) if form.is_valid(): obj = ESBBuffetMapping(**form.cleaned_data) obj.save() return JsonResponse({ 'error_message': None, 'data': obj.get_info() }) return JsonResponse({ 'error_message': get_error_prompt(form), 'data': None, })
def get(self, request): # 获取接口以及对应的说明 filter_val = request.GET.get('keyword') if filter_val: all_comp_info = ESBChannel.objects.filter(is_hidden=False)\ .filter(Q(component_name__icontains=filter_val) | Q(name__icontains=filter_val))\ .order_by('component_system_id') else: all_comp_info = ESBChannel.objects.filter(is_hidden=False)\ .order_by('component_system_id') all_comp_info = [ { 'id': api.id, 'name': api.component_name, 'label': api.name_display, 'system_id': api.component_system_id, } for api in all_comp_info ] # 通过system_id获取系统信息 system_ids = [api['system_id'] for api in all_comp_info] all_system_info = ComponentSystem.objects.filter(id__in=system_ids).values('id', 'name', 'label') all_system_info = dict([(system['id'], system) for system in list(all_system_info)]) # 组装参数 for comp_info in all_comp_info: system_info = all_system_info.get(comp_info['system_id'], {}) comp_info.update({ 'system_name': system_info.get('name', ''), 'system_label': system_info.get('label', ''), }) all_comp_info = all_comp_info[:30] return JsonResponse(list(all_comp_info))
def post(self, request): channel_ids = request.POST.get('channel_ids') channel_ids = channel_ids.split(',') if channel_ids else [] objs = ESBChannel.objects.filter(id__in=channel_ids) affected_rows = objs.count() objs.delete() return JsonResponse({'affected_rows': affected_rows, 'error_message': None})
def get(self, request): system_name = request.GET.get('system_name') channel_path = request.GET.get('channel_path') # channel_name = request.GET.get('channel_name') channels = ESBChannel.objects.all() if system_name: channels = channels.filter(component_system__name=system_name) # if channel_name: # channels = channels.filter(name__contains=channel_name) if channel_path: channels = channels.filter(path__contains=channel_path) # 获取HOST try: host = settings.PAAS_DOMAIN except Exception: host = DEFAULT_HOST try: schema = settings.HTTP_SCHEMA except Exception: schema = "http" schema_prefix = '%s://' % schema if not host.startswith(schema_prefix): host = '%s://%s' % (schema, host) channels = [{ 'id': channel.id, 'name': channel.name_display, 'label': u'[%s] %s' % (channel.component_system.name, channel.name_display), 'path': channel.path, 'method': channel.method, 'component_codename': channel.component_codename, 'is_active': channel.is_active, 'created_time': channel.created_time.strftime('%Y-%m-%d'), 'last_modified_time': channel.last_modified_time.strftime('%Y-%m-%d'), 'timeout_time': channel.timeout_time, 'host': '%s/api/c/compapi' % host, 'perm_level_label': channel.get_perm_level_display(), 'rate_limit_required': channel.rate_limit_required, 'static_url': settings.STATIC_URL, } for channel in channels.order_by('-is_active', 'component_system__name', 'path')] return JsonResponse({'data': channels})
def post(self, request): data = dict(request.POST.items()) FeedbackForComponentDocs( operator=request.user.username, board='', component_id=data['api_id'], content=data.get('content', _(u"满足需求")), ).save() return JsonResponse({'result': True})
def put(self, request, item_id): from django.http import QueryDict put = QueryDict(request.body) form = EditESBBuffetMappingForm(put) if form.is_valid(): obj = ESBBuffetMapping.objects.get(pk=form.cleaned_data['id']) obj.__dict__.update(form.cleaned_data) obj.save() return JsonResponse({ 'error_message': None, 'data': obj.get_info() }) return JsonResponse({ 'error_message': get_error_prompt(form), 'data': None, })
def post(self, request): system_ids = request.POST.get('system_ids') system_ids = system_ids.split(',') if system_ids else [] objs = ComponentSystem.objects.filter(id__in=system_ids) ESBChannel.objects.filter(component_system__in=objs).delete() ESBBuffetComponent.objects.filter(system__in=objs).delete() affected_rows = objs.count() objs.delete() return JsonResponse({'affected_rows': affected_rows, 'error_message': None})
def get(self, request, system_name, api_id): try: component = ESBChannel.objects.get(id=api_id) api = ComponentAPIDoc.objects.get(component_id=component.id) doc_html = api.doc_html_display except Exception: doc_html = '' return JsonResponse({ 'doc_html': doc_html })
def get(self, request, system_name): """查询指定系统下的apis信息""" # 获取当前系统的信息 try: system_info = ComponentSystem.objects.get(name=system_name) except Exception: raise Http404 api_info_by_system = ESBChannel.objects.filter(component_system_id=system_info.id, is_hidden=False)\ .order_by('component_name') api_info_by_system = [ { 'id': api.id, 'system_id': api.component_system_id, 'name': api.component_name, 'label': api.name_display, 'path': api.path, 'type': api.type, } for api in api_info_by_system ] return JsonResponse({ 'system_summary': system_info.remark_display or _(u'暂无系统简介'), 'api_info_by_system': list(api_info_by_system), })
def get(self, request): return JsonResponse(get_system_category())
def post(self, request): return JsonResponse({'result': True})
def delete(self, request, item_id): obj = ESBBuffetMapping.objects.get(pk=item_id) obj.delete() return JsonResponse({'error_message': None, 'data': None})
def get(self, request, item_id): obj = ESBBuffetMapping.objects.get(pk=item_id) return JsonResponse({'error_message': None, 'data': obj.get_info()})