Exemplo n.º 1
0
 def get(self, request, *args, **kwargs):
     api_id = int(kwargs['id'])
     body_res = {'is_deleted': False, 'paging': False}
     service_list = get_service_list(self, body_res)
     api = get_api_detail(self, api_id)
     context = {"service_list": service_list, "form": api}
     return render(request, self.template_name, context)
Exemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        api_id = int(kwargs['id'])
        url = api_settings.EDIT_CHANNEL_API.format(api_id=api_id)
        form = request.POST
        params = {}

        if form.get('name'):
            params['name'] = form['name']

        if form.get('http_method'):
            params['http_method'] = form['http_method']

        if form.get('pattern'):
            params['pattern'] = form['pattern']

        if form.get('service_id'):
            params['service_id'] = int(form['service_id'])

        if form.get('require_access_token'):
            params['is_required_access_token'] = True if form[
                'require_access_token'] == '1' else False

        success, status_code, status_message, data = RestfulHelper.send(
            "PUT", url, params, self.request, "Update API")

        if success:
            messages.add_message(request, messages.SUCCESS,
                                 'API has been edited')
            return redirect('channel_gateway_api:list')
        else:
            body_res = {'is_deleted': False, 'paging': False}
            service_list = get_service_list(self, body_res)
            messages.add_message(request, messages.ERROR, status_message)
            return render(request,
                          self.template_name,
                          context={
                              'form': form,
                              'service_list': service_list
                          })
Exemplo n.º 3
0
    def post(self, request):
        form = request.POST
        params = {}

        if form.get('name'):
            params['name'] = form['name']

        if form.get('http_method'):
            params['http_method'] = form['http_method']

        if form.get('pattern'):
            params['pattern'] = form['pattern']

        if form.get('service_id'):
            params['service_id'] = int(form['service_id'])

        if form.get('require_access_token'):
            params['is_required_access_token'] = True if form[
                'require_access_token'] == '1' else False

        success, status_code, message, data = self.add_api_service(params)

        if success:
            messages.add_message(request, messages.SUCCESS,
                                 'New API has been created')
            return redirect('channel_gateway_api:list')
        else:
            body_res = {'is_deleted': False, 'paging': False}
            service_list = get_service_list(self, body_res)
            messages.add_message(request, messages.ERROR, message)
            return render(request,
                          self.template_name,
                          context={
                              'form': form,
                              'service_list': service_list
                          })
Exemplo n.º 4
0
    def get(self, request, *args, **kwargs):
        context = super(ListView, self).get_context_data(**kwargs)
        # get undeleted services
        body_res = {'is_deleted': False, 'paging': False}
        service_list = get_service_list(self, body_res)

        is_deleted_status_list = [{
            "value": "0",
            "name": "No"
        }, {
            "value": "1",
            "name": "Yes"
        }, {
            "value": "",
            "name": "All"
        }]

        http_method_list = [{
            "value": "",
            "name": "All"
        }, {
            "value": "GET",
            "name": "GET"
        }, {
            "value": "POST",
            "name": "POST"
        }, {
            "value": "PUT",
            "name": "PUT"
        }, {
            "value": "DELETE",
            "name": "DELETE"
        }]
        context.update({
            'is_deleted_status_list': is_deleted_status_list,
            'http_method_list': http_method_list,
            'service_list': service_list
        })
        opening_page_index = request.GET.get('current_page_index', 1)
        api_id = request.GET.get('api_id', "")
        api_name = request.GET.get('api_name', "")
        service_id = request.GET.get('service_id', "")
        is_deleted = request.GET.get('is_deleted', "0")
        http_method = request.GET.get('http_method', "")

        params = {}
        params['paging'] = True
        params['page_index'] = int(opening_page_index)
        if api_id:
            params['id'] = api_id
        if api_name:
            params['name'] = api_name
        if service_id:
            params['service_id'] = int(service_id)
        if is_deleted:
            params['is_deleted'] = True if is_deleted == '1' else False
        if http_method:
            params['http_method'] = http_method

        channel_api_list = get_api_list(self, params)
        page = channel_api_list.get('page', {})
        context.update({
            'channel_api_list': channel_api_list.get('apis', []),
            'paginator': page,
            'page_range': calculate_page_range_from_page_info(page),
            'total_result': page.get('total_elements', 0),
            "api_id": api_id,
            "api_name": api_name,
            "selected_deleted_status": is_deleted,
            "selected_http_method": http_method,
            "service_id": int(service_id) if service_id else ""
        })
        return render(request, self.template_name, context)
Exemplo n.º 5
0
 def get(self, request, *args, **kwargs):
     context = super(CreateView, self).get_context_data(**kwargs)
     body_res = {'is_deleted': False, 'paging': False}
     service_list = get_service_list(self, body_res)
     context.update({'service_list': service_list})
     return render(request, self.template_name, context)