示例#1
0
def search_serve(request, servename=""):
    if servename == "" or servename == None:
        servename = request.POST.get('servename', "")
    if servename == "" or servename == None or servename.strip() == "":
        return HttpResponseRedirect("/index/")
    try:
        respObj, contentObj = RestUtils.rest_get("/base", {
            "serve_name__contains": servename,
            "recursion": 1
        })  #@UnusedVariable
    except:
        return HttpResponseRedirect("/index/")
    searchlist = []
    if contentObj.count > 0:
        searchlist = contentObj.results
        try:
            searchword = Search_Words.objects.get(
                word=servename)  #@UndefinedVariable
            searchword.visits = searchword.visits + 1
            searchword.save()
        except ObjectDoesNotExist:
            Search_Words.objects.create(word=servename)  #@UndefinedVariable
    return render_to_response('api_search.html', {
        'searchlist': searchlist,
    },
                              context_instance=RequestContext(request))
def ip_bind(request):
    userdatas = User_data_service.objects.filter(user = request.user)
    serve_list = []
    id_list = []
    for userdata in userdatas :
        id_list.append(str(userdata.service_id))
    try:
        respObj,contentObj = RestUtils.rest_get("/base.json",{"id__in":",".join(id_list),"recursion":1}) #@UnusedVariable
        serve_list = contentObj.results
    except :
        return HttpResponseRedirect("/person/index/")
    return render_to_response('ipbind.html',{'current_app' : current_app, 'current_tab' : request.path ,
                                             'userdatas' : userdatas, 'serve_list' : serve_list,
                                              },context_instance=RequestContext(request))
def search_serve(request,servename=""):
    if servename == "" or servename == None:
        servename = request.POST.get('servename', "")
    if servename == "" or servename == None or servename.strip() == "":
        return HttpResponseRedirect("/index/")
    try:
        respObj,contentObj = RestUtils.rest_get("/base",{"serve_name__contains":servename,"recursion":1}) #@UnusedVariable
    except :
        return HttpResponseRedirect("/index/")
    searchlist = [];
    if contentObj.count > 0 :
        searchlist = contentObj.results
        try:
            searchword = Search_Words.objects.get(word=servename) #@UndefinedVariable
            searchword.visits = searchword.visits + 1
            searchword.save()
        except ObjectDoesNotExist:
            Search_Words.objects.create(word=servename) #@UndefinedVariable
    return render_to_response('api_search.html',{'searchlist':searchlist,},context_instance=RequestContext(request))
def ip_bind(request):
    userdatas = User_data_service.objects.filter(user=request.user)
    serve_list = []
    id_list = []
    for userdata in userdatas:
        id_list.append(str(userdata.service_id))
    try:
        respObj, contentObj = RestUtils.rest_get("/base.json", {
            "id__in": ",".join(id_list),
            "recursion": 1
        })  #@UnusedVariable
        serve_list = contentObj.results
    except:
        return HttpResponseRedirect("/person/index/")
    return render_to_response('ipbind.html', {
        'current_app': current_app,
        'current_tab': request.path,
        'userdatas': userdatas,
        'serve_list': serve_list,
    },
                              context_instance=RequestContext(request))
def get_service_by_request(args, kwargs):
    try:
        serve_cache = caches['default']
        cate_abb = kwargs.pop('cate_abb', None)
        type_abb = kwargs.pop('type_abb', None)
        serve_abb = kwargs.pop('serve_abb', None)
        serve_cache_key = "%s-%s-%s" % (cate_abb, type_abb, serve_abb)

        if None == serve_cache.get(serve_cache_key):
            paramsObj = {
                'service__serve_type__category__cate_abbreviation': cate_abb,
                'service__serve_type__type_abbreviation': type_abb,
                'service__serve_abbreviation': serve_abb,
                'recursion': 1,
                'page_no': 1,
                'page_size': 10
            }
            respObj, contentObj = RestUtils.rest_auth_get(
                "/api_secret/", paramsObj)
            service = contentObj.results[0]
            serve_cache.set(serve_cache_key, service)
        else:
            service = serve_cache.get(serve_cache_key)

        regexId = "https?://.*/base/(\d)\.json"
        matchId = re.search(regexId, service.service.url)
        if matchId:
            service.service.id = matchId.group(1)

        regexStatus = "https?://.*/status/(\d)\.json"
        matchStatus = re.search(regexStatus, service.service.status)
        if matchStatus:
            service.service.status = matchStatus.group(1)

        return service
    except Exception, e:
        logger.info(e)
        return None
def get_service_by_request(args, kwargs):
    try:
        serve_cache = caches["default"]
        cate_abb = kwargs.pop("cate_abb", None)
        type_abb = kwargs.pop("type_abb", None)
        serve_abb = kwargs.pop("serve_abb", None)
        serve_cache_key = "%s-%s-%s" % (cate_abb, type_abb, serve_abb)

        if None == serve_cache.get(serve_cache_key):
            paramsObj = {
                "service__serve_type__category__cate_abbreviation": cate_abb,
                "service__serve_type__type_abbreviation": type_abb,
                "service__serve_abbreviation": serve_abb,
                "recursion": 1,
                "page_no": 1,
                "page_size": 10,
            }
            respObj, contentObj = RestUtils.rest_auth_get("/api_secret/", paramsObj)
            service = contentObj.results[0]
            serve_cache.set(serve_cache_key, service)
        else:
            service = serve_cache.get(serve_cache_key)

        regexId = "https?://.*/base/(\d)\.json"
        matchId = re.search(regexId, service.service.url)
        if matchId:
            service.service.id = matchId.group(1)

        regexStatus = "https?://.*/status/(\d)\.json"
        matchStatus = re.search(regexStatus, service.service.status)
        if matchStatus:
            service.service.status = matchStatus.group(1)

        return service
    except Exception, e:
        logger.info(e)
        return None