Example #1
0
def wiki_doc_edit(request, now_version):
    data = {}
    data['channelName'] = 'maintenance'
    data['now_version'] = now_version
    params = request.REQUEST
    print params
    side_info = get_side_info(now_version)
    data.update(side_info)

    if params.has_key('inter'):
        id = params['inter']
        data['inter_id'] = int(id)

        q_info = mobile_info.objects.get(pk=id)
        data['q_info'] = q_info

        q_input = mobile_input.objects.filter(inter_id=id)
        data['q_input'] = q_input

        q_output = mobile_output.objects.filter(inter_id=id)
        data['q_output'] = q_output
    else:
        redirect_url = "/api/%s/" % now_version
        return HttpResponseRedirect(redirect_url)

    import time
    todayString = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    print todayString

    if params.has_key('doc_hide') and params['doc_hide'] == "edit" :
        #------------------------------line-------------------------------#
        error_url = "/api/%s/add/" % now_version
        #接口基本信息start
        if params.has_key('inter_name') :
            inter_name = params['inter_name']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('desc') :
            desc = params['desc']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('url') :
            url = params['url']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('islogin') :
            islogin = params['islogin']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('req_method') :
            req_method = params['req_method']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('category') :
            category = params['category']
        else :
            return HttpResponseRedirect(error_url)
        if params.has_key('version') :
            version = params['version']
        else :
            return HttpResponseRedirect(error_url)

        q_info.name = inter_name
        q_info.desc = desc
        q_info.url = url
        q_info.islogin = islogin
        q_info.req = req_method
        q_info.category = category
        q_info.version = version
        q_info.user_id = auth.get_user(request).id
        q_info.lastUpdated = todayString
        q_info.save()
        #接口基本信息end

        #------------------------------line-------------------------------#
        #接口输入参数start
        #表中原有的输入参数
        input_origin = []
        for k, v in enumerate(q_input) :
            tmp = {}
            tmp['name'] = v.name
            tmp['type'] = v.type
            tmp['require'] = v.require
            tmp['example'] = v.example
            tmp['desc'] = v.desc
            input_origin.append(tmp)
        print input_origin

        #接口输入参数
        error_url = "/api/%s/add/" % now_version
        if params.has_key('tr_cnt') and params['tr_cnt'] == 0 :
            return HttpResponseRedirect(error_url)

        if not params.has_key('inter_id') :
            return HttpResponseRedirect(error_url)
        else :
            inter_id = params['inter_id']
            inter = mobile_info.objects.get(pk=inter_id)

        #表单提交的输入参数
        input_form = []
        num = 0
        isend_num = 0
        while True :
            if isend_num == int(params['tr_cnt']) :
                break
            num = num + 1
            num_forstr = str(num)
            tmp = {}
            if not params.has_key('name_'+num_forstr) :
                continue
            else :
                tmp['name'] = params['name_'+num_forstr]
            if not params.has_key('type_'+num_forstr) :
                continue
            else :
                tmp['type'] = params['type_'+num_forstr]
            if not params.has_key('require_'+num_forstr) :
                continue
            else :
                tmp['require'] = int(params['require_'+num_forstr])
            if not params.has_key('example_'+num_forstr) :
                continue
            else :
                tmp['example'] = params['example_'+num_forstr]
            if not params.has_key('desc_'+num_forstr) :
                continue
            else :
                tmp['desc'] = params['desc_'+num_forstr]
            isend_num = isend_num + 1
            input_form.append(tmp)
        print input_form

        print 'chaji'
        needadd = [val for val in input_form if val not in input_origin]
        print needadd
        needdel = [val for val in input_origin if val not in input_form]
        print needdel
        print 'chaji'

        for k, v in enumerate(needdel) :
            p = mobile_input.objects.get(name=v['name'], inter_id = inter)
            p.delete()

        for k, v in enumerate(needadd) :
            db_input = mobile_input(name = v['name'],
                        type = v['type'],
                        require = v['require'],
                        example = v['example'],
                        desc = v['desc'],
                        user = request.user,
                        lastUpdated = todayString,
                        inter_id = inter
                        )
            db_input.save()
        #接口输入参数end

        #------------------------------line-------------------------------#
        #接口输出结果start
        #表中原有的输出结果
        output_origin = []
        for k, v in enumerate(q_output) :
            tmp = {}
            tmp['name'] = v.name
            tmp['desc'] = v.desc
            tmp['type'] = v.type
            tmp['example'] = v.example
            output_origin.append(tmp)
        print output_origin

        if params.has_key('out_cnt') and params['out_cnt'] == 0 :
            error_url = "/api/%s/add/" % now_version
            return HttpResponseRedirect(error_url)

        #表单提交的输出结果
        output_form = []
        num = 0
        isend_num = 0
        while True :
            if isend_num == int(params['out_cnt']) :
                break
            num = num + 1
            num_forstr = str(num)
            tmp = {}
            if not params.has_key('rname_'+num_forstr) :
                continue
            else :
                tmp['name'] = params['rname_'+num_forstr]

            if not params.has_key('rdesc_'+num_forstr) :
                continue
            else :
                tmp['desc'] = params['rdesc_'+num_forstr]

            if not params.has_key('rtype_'+num_forstr) :
                continue
            else :
                tmp['type'] = params['rtype_'+num_forstr]

            if not params.has_key('rexample_'+num_forstr) :
                continue
            else :
                tmp['example'] = params['rexample_'+num_forstr]

            isend_num = isend_num + 1
            output_form.append(tmp)
        print output_form

        print 'chaji'
        needadd = [val for val in output_form if val not in output_origin]
        print needadd
        needdel = [val for val in output_origin if val not in output_form]
        print needdel
        print 'chaji'

        for k, v in enumerate(needdel) :
            p = mobile_output.objects.get(name=v['name'], inter_id = inter)
            p.delete()

        for k, v in enumerate(needadd) :
            db_output = mobile_output(name = v['name'],
                        desc = v['desc'],
                        type = v['type'],
                        example = v['example'],
                        user = request.user,
                        lastUpdated = todayString,
                        inter_id = inter
                        )
            db_output.save()
        #接口输出结果end
        redirect_url = "/api/%s/" % now_version
        return HttpResponseRedirect(redirect_url)

    return render(request,'tools/mobile_doc_edit.html',{'data':data})
Example #2
0
def wiki_doc_add(request, now_version):
    data = {}
    data['channelName'] = 'maintenance'
    data['now_version'] = now_version

    params = request.REQUEST
    print params

    side_info = get_side_info(now_version)
    data.update(side_info)

    import time
    todayString = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    print todayString

    #接口接本信息
    if params.has_key('doc_hide') and params['doc_hide'] == "basic" :
        error_url = "/api/%s/add/" % now_version
        if params.has_key('inter_name') :
            inter_name = params['inter_name']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('desc') :
            desc = params['desc']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('url') :
            url = params['url']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('islogin') :
            islogin = params['islogin']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('req_method') :
            req_method = params['req_method']
        else :
            return HttpResponseRedirect(error_url)

        if params.has_key('category') :
            category = params['category']
        else :
            return HttpResponseRedirect(error_url)
        if params.has_key('version') :
            version = params['version']
        else :
            return HttpResponseRedirect(error_url)

        db_info = mobile_info(name = inter_name,
                    desc = desc,
                    url = url,
                    islogin = islogin,
                    req = req_method,
                    category = category,
                    user = request.user,
                    version = version,
                    lastUpdated = todayString
                    )
        db_info.save()
        inter_id = db_info.id
        print inter_id
        data['inter_id'] = inter_id
        redirect_url = '/api/%s/add/step2?inter=%s'%(version,inter_id)
        return HttpResponseRedirect(redirect_url)
        #return render(request,'tools/mobile_doc_add_step2.html',{'data':data})

    #------------------------------line-------------------------------#
    #接口输入参数
    error_url = "/api/%s/add/" % now_version
    if params.has_key('doc_hide') and params['doc_hide'] == "input" :
        if params.has_key('tr_cnt') and params['tr_cnt'] == 0 :
            return HttpResponseRedirect(error_url)

        if not params.has_key('inter_id') :
            return HttpResponseRedirect(error_url)
        else:
            inter_id = params['inter_id']
            inter = mobile_info.objects.get(pk=inter_id)

        num = 0
        isend_num = 0
        print 'input'
        print params['tr_cnt']
        while True:
            if isend_num == int(params['tr_cnt']) :
                break
            print 'in_end'

            num = num + 1
            num_forstr = str(num)
            if not params.has_key('name_'+num_forstr) :
                continue

            if not params.has_key('type_'+num_forstr) :
                continue

            if not params.has_key('require_'+num_forstr) :
                continue

            if not params.has_key('example_'+num_forstr) :
                continue

            if not params.has_key('desc_'+num_forstr) :
                continue

            isend_num = isend_num + 1
            db_input = mobile_input(name = params['name_'+num_forstr],
                        type = params['type_'+num_forstr],
                        require = params['require_'+num_forstr],
                        example = params['example_'+num_forstr],
                        desc = params['desc_'+num_forstr],
                        user = request.user,
                        lastUpdated = todayString,
                        inter_id = inter
                        )
            db_input.save()

        #------------------------------line-------------------------------#
        print 'output'
        print params['out_cnt'];
        #接口结果输出
        if params.has_key('out_cnt') and params['out_cnt'] == 0 :
            error_url = "/api/%s/add/" % now_version
            return HttpResponseRedirect(error_url)

        num = 0
        isend_num = 0
        while True :
            if isend_num == int(params['out_cnt']) :
                break
            print 'out_end'

            num = num + 1
            num_forstr = str(num)
            if not params.has_key('rname_'+num_forstr) :
                continue

            if not params.has_key('rtype_'+num_forstr) :
                continue

            if not params.has_key('rexample_'+num_forstr) :
                continue

            if not params.has_key('rdesc_'+num_forstr) :
                continue

            isend_num = isend_num + 1
            db_output = mobile_output(name = params['rname_'+num_forstr],
                        desc = params['rdesc_'+num_forstr],
                        type = params['rtype_'+num_forstr],
                        example = params['rexample_'+num_forstr],
                        user = request.user,
                        lastUpdated = todayString,
                        inter_id = inter
                        )
            db_output.save()
        redirect_url = "/api/%s/" % now_version
        return HttpResponseRedirect(redirect_url)

    return render(request,'tools/mobile_doc_add.html',{'data':data})