def test_document2json(self): pessoa1 = { 'nome': 'Antony', 'dependente': [ { 'nome_dep': 'Neymar', 'idade_dep': 12, 'gmulti': [{ 'teste': 'False' }, { 'teste': 'False' }] }, ], 'carros': ['x', 'y', 'z'], } pessoa1 = lbutils.object2json(pessoa1) pessoa2 = json2document(self.base, pessoa1) #Gmulti = self.base.metaclass('gmulti') #Gmulti.teste= True #pessoa2.dependente.gmulti[1] = Gmulti() #pessoa2.dependente.gmulti.append(55) j = document2json(self.base, pessoa2, indent=4) fd = open('/tmp/document.json', 'w+') fd.write(j) fd.close()
def test_document2json(self): pessoa1 = { 'nome' : 'Antony', 'dependente' : { 'nome_dep' : 'Neymar', 'idade_dep': 12, 'gmulti' : [ { 'teste' : 'False' }, { 'teste' : 'True' } ] }, 'carros' : ['x', 'y', 'z'], } pessoa1 = lbutils.object2json(pessoa1) pessoa2 = json2document(self.base, pessoa1) #Gmulti = self.base.metaclass('gmulti') #Gmulti.teste= True #pessoa2.dependente.gmulti[1] = Gmulti() #pessoa2.dependente.gmulti.append(55) j = document2json(self.base, pessoa2, indent=4) fd = open('/tmp/document.json', 'w+') fd.write(j) fd.close()
def _asjson(self, **kw): dict_search = {} for key in dir(self): if not key[0] == "_": if isinstance(getattr(self, key), OrderBy): value = getattr(self, key)._asdict() else: value = getattr(self, key) dict_search[key] = value return lbutils.object2json(dict_search)
def txt_mapping_json(self): """ @property txt_mapping_json: JSON format of txt_mapping. """ ''' NOTE: Se usarmos "object2json()" será retornado p/ o campo outro valor que não vazio (string vazia) nos casos onde txt_mapping não for enviado! By Questor ''' if self.asdict["metadata"]["txt_mapping"] is not '': return lbutils.object2json(self.asdict["metadata"]["txt_mapping"]) else: return self.asdict["metadata"]["txt_mapping"]
def version(self): import pkg_resources lbg = pkg_resources.get_distribution('lbgenerator') versions = { } for requirement in lbg.requires(): try: req_name = requirement.project_name req_version = pkg_resources.get_distribution(req_name).version versions[req_name] = req_version except: pass versions['lbgenerator'] = lbg.version return Response(object2json(versions), content_type='application/json')
def version(self): import pkg_resources lbg = pkg_resources.get_distribution('lbgenerator') versions = {} for requirement in lbg.requires(): try: req_name = requirement.project_name req_version = pkg_resources.get_distribution(req_name).version versions[req_name] = req_version except: pass versions['lbgenerator'] = lbg.version return Response(object2json(versions), content_type='application/json')
def update_collection(self, search_obj=None, path_list=[]): """ Updates collection of documents according to search object. @param search_obj: JSON which represents a search object. """ if search_obj is not None: msg = 'search_obj must be a Search object.' assert isinstance(search_obj, Search), msg else: search_obj = Search() response = self.send_request(self.httpput, url_path=[self.basename, self.doc_prefix], params={self.search_param: search_obj._asjson(), self.path_param: lbutils.object2json(path_list)}) return response
def update_collection(self, search_obj=None, path_list=[]): """ Updates collection of documents according to search object. @param search_obj: JSON which represents a search object. """ if search_obj is not None: msg = 'search_obj must be a Search object.' assert isinstance(search_obj, Search), msg else: search_obj = Search() response = self.send_request(self.httpput, url_path=[self.basename, self.doc_prefix], params={ self.search_param: search_obj._asjson(), self.path_param: lbutils.object2json(path_list) }) return response
def json(self): return lbutils.object2json(self, default=lambda o: o.__dict__)
def json(self): """ @property json: JSON format of base model. """ return lbutils.object2json(self.asdict)
def document2json(base, document, **kw): """ Convert a BaseMetaClass object to JSON string. @param document: BaseMetaClass object """ return lbutils.object2json(document2dict(base, document), **kw)
def _asjson(self, **kw): dict_orderby = {} for key in dir(self): if not key[0] == "_": dict_orderby[key] = getattr(self, key) return lbutils.object2json(dict_orderby)
def json(self): """ @property json: JSON format of base metadata model. """ return lbutils.object2json(self.asdict)
def validate(self, value): lbutils.object2json(value) self.__obj__ = value return value
def json(self): """ @property json: JSON format of group model. """ return lbutils.object2json(self.asdict)
def json(self): """ @property json: JSON format of group metadata model. """ return lbutils.object2json(self.asdict)