コード例 #1
0
    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()
コード例 #2
0
ファイル: metaclass.py プロジェクト: antonygc/liblightbase
    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()
コード例 #3
0
ファイル: search.py プロジェクト: antonygc/liblightbase
 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)
コード例 #4
0
 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)
コード例 #5
0
 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"]
コード例 #6
0
ファイル: command.py プロジェクト: VictorMedeiros/LBGenerator
 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')
コード例 #7
0
 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')
コード例 #8
0
 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
コード例 #9
0
ファイル: document.py プロジェクト: benonisilva/liblightbase
 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
コード例 #10
0
ファイル: conv.py プロジェクト: lightbase/liblightbase
 def json(self):
     return lbutils.object2json(self, default=lambda o: o.__dict__)
コード例 #11
0
 def json(self):
     """ @property json: JSON format of base model.
     """
     return lbutils.object2json(self.asdict)
コード例 #12
0
ファイル: conv.py プロジェクト: benonisilva/liblightbase
def document2json(base, document, **kw):
    """
    Convert a BaseMetaClass object to JSON string.
    @param document: BaseMetaClass object
    """
    return lbutils.object2json(document2dict(base, document), **kw)
コード例 #13
0
 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)
コード例 #14
0
ファイル: search.py プロジェクト: antonygc/liblightbase
 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)
コード例 #15
0
ファイル: metadata.py プロジェクト: lightbase/liblightbase
 def json(self):
     """ @property json: JSON format of base metadata model. 
     """
     return lbutils.object2json(self.asdict)
コード例 #16
0
ファイル: standard.py プロジェクト: benonisilva/liblightbase
 def validate(self, value):
     lbutils.object2json(value)
     self.__obj__ = value
     return value
コード例 #17
0
ファイル: conv.py プロジェクト: antonygc/liblightbase
def document2json(base, document, **kw):
    """
    Convert a BaseMetaClass object to JSON string.
    @param document: BaseMetaClass object
    """
    return lbutils.object2json(document2dict(base, document), **kw)
コード例 #18
0
 def json(self):
     """ @property json: JSON format of group model. 
     """
     return lbutils.object2json(self.asdict)
コード例 #19
0
ファイル: conv.py プロジェクト: benonisilva/liblightbase
 def json(self):
     return lbutils.object2json(self, default=lambda o: o.__dict__)
コード例 #20
0
ファイル: group.py プロジェクト: benonisilva/liblightbase
 def json(self):
     """ @property json: JSON format of group metadata model.
     """
     return lbutils.object2json(self.asdict)
コード例 #21
0
 def validate(self, value):
     lbutils.object2json(value)
     self.__obj__ = value
     return value