Example #1
0
def rest(request,object_):
    path = request.get_full_path()
    object_ = object_.strip()
    if request.method == 'GET':
        try:
            c_ = conf.objects.get(key=object_)    
            value = json.loads(c_.value)
        except:
            value = {}
        if request.GET.get('type') == "json":
            #兼容以前的配置
            try:
                value['DB']['table_split_idx'] = value['DB']['mysql']['table_split_idx'] 
                value['DB']['tableprefix'] = value['DB']['mysql']['tableprefix'] 
            except:
                value['DB']['mysql']['table_split_idx'] = value['DB']['table_split_idx'] 
                value['DB']['mysql']['tableprefix'] = value['DB']['tableprefix'] 
            if type(value['METADB'][0])==list:
                value['METADB'] = map(lambda x:{'name':x[0],"lambda":x[1],'alias':(len(x)>2 and x[2] or x[0])},value['METADB'])
            if type(value['FIELDS_ALIAS'])==dict:
                value['FIELDS_ALIAS'] = [{'name':i[0],'lambda':i[1][0],'alias':i[1][1]} for i in value['FIELDS_ALIAS'].items()]
            value['KEY']=object_ 
            return HttpResponse(json.dumps(value))
        else:
            return render_to_response("index.html")
    if request.method == "POST":
        object_ = object_ or request.POST.get('key') 
        value = json.loads(request.POST.get('data'))
        check_ = DataModel(config=value)
        print 'value',value
        try:
            check_.check_new_config()
        except Exception as e:
            msg = {'code':"200","success":False,'msg':str(e)}
            return HttpResponse(json.dumps(msg))
        try:
            c_ = conf.objects.get(key=object_) 
            value_ = json.loads(c_.value)
            value_.update(value)
            #print value_
            c_.value = json.dumps(value_)
            c_.save()
        except Exception as e:
            #print 'create a conf object'
            #print e
            c_ = conf(key=object_,value=json.dumps(value))
            c_.save()
        msg = {'code':"200","success":True}
        return HttpResponse(json.dumps(msg))
Example #2
0
def rest(request, object_):
    path = request.get_full_path()
    object_ = object_.strip()
    if request.method == 'GET':
        try:
            c_ = conf.objects.get(key=object_)
            value = json.loads(c_.value)
        except:
            value = {}
        if request.GET.get('type') == "json":
            #兼容以前的配置
            try:
                value['DB']['table_split_idx'] = value['DB']['mysql'][
                    'table_split_idx']
                value['DB']['tableprefix'] = value['DB']['mysql'][
                    'tableprefix']
            except:
                value['DB']['mysql']['table_split_idx'] = value['DB'][
                    'table_split_idx']
                value['DB']['mysql']['tableprefix'] = value['DB'][
                    'tableprefix']
            if type(value['METADB'][0]) == list:
                value['METADB'] = map(
                    lambda x: {
                        'name': x[0],
                        "lambda": x[1],
                        'alias': (len(x) > 2 and x[2] or x[0])
                    }, value['METADB'])
            if type(value['FIELDS_ALIAS']) == dict:
                value['FIELDS_ALIAS'] = [{
                    'name': i[0],
                    'lambda': i[1][0],
                    'alias': i[1][1]
                } for i in value['FIELDS_ALIAS'].items()]
            value['KEY'] = object_
            return HttpResponse(json.dumps(value))
        else:
            return render_to_response("index.html")
    if request.method == "POST":
        object_ = object_ or request.POST.get('key')
        value = json.loads(request.POST.get('data'))
        check_ = DataModel(config=value)
        print 'value', value
        try:
            check_.check_new_config()
        except Exception as e:
            msg = {'code': "200", "success": False, 'msg': str(e)}
            return HttpResponse(json.dumps(msg))
        try:
            c_ = conf.objects.get(key=object_)
            value_ = json.loads(c_.value)
            value_.update(value)
            #print value_
            c_.value = json.dumps(value_)
            c_.save()
        except Exception as e:
            #print 'create a conf object'
            #print e
            c_ = conf(key=object_, value=json.dumps(value))
            c_.save()
        msg = {'code': "200", "success": True}
        return HttpResponse(json.dumps(msg))
Example #3
0
 def document_to_model(self, document):
     data = self.parse_model(document['__data__'])
     rules = document['__rules__']
     return DataModel.load(rules, data)
Example #4
0
 def document_to_model(self, document):
     data = self.parse_model(document['__data__'])
     rules = document['__rules__']
     return DataModel.load(rules, data)