Пример #1
0
def test_asDict():
    """docstring for asDict"""
    d = gnrstring.asDict('height=22, weight=73')
    assert d['height'] == '22' and d['weight'] == '73' and isinstance(d, dict)
    d = gnrstring.asDict('height=$myheight, weight=73',
                         symbols={'myheight': 55})
    assert d['height'] == '55' and d['weight'] == '73' and isinstance(d, dict)
Пример #2
0
 def _df_handleGetter(self, fb, code=None, getter=None):
     kw = asDict(getter['where'].replace('\n', ','))
     _iflist = [
         k for k, v in kw.items() if v.startswith('^') or v.startswith('=')
     ]
     if _iflist:
         kw['_if'] = ' && '.join(_iflist)
     fb.dataRemote('.%s' % code,
                   self._df_remoteGetter,
                   table=getter['table'],
                   column=getter['column'],
                   innerpath=getter['innerpath'],
                   **kw)
Пример #3
0
    def getMenuBag(self,root_id=None,userTags=None,exportMode=None):
        root_id = root_id or self.rootId()
        q = self.query(where="$hierarchical_pkey LIKE :root_id || '/%%' " ,
                        root_id=root_id,columns='*,$hlevel,$page_label,$page_filepath,$page_tbl,$page_metadata',
                        order_by='$_h_count')

        f = q.fetch()
        if not f:
            return
        result = Bag()
        app = self.db.application
        forbidden = []
        for i,r in enumerate(f):
            if userTags is True or (app.checkResourcePermission(r['tags'], userTags) and not r['parent_id'] in forbidden):
                kw = dict()      
                r = dict(r)   
                if r['page_id']:       
                    kw['table'] = r.pop('page_tbl',None)
                    kw['file'] = r.pop('page_filepath',None)
                    if r['page_metadata']:
                        kw.update(asDict(r['page_metadata']))
                        labelClass = 'menu_shape menu_page'
                else:
                    kw['isDir'] = True
                    labelClass='menu_shape menu_level_%i' %(r['hlevel']-2)
                if not exportMode:
                    kw['labelClass'] = labelClass
                result.setItem(r['hierarchical_pkey'].split('/')[1:],None,label=r['label'],tags=r['tags'],
                                **kw)  
            else:
                forbidden.append(r['id'])
        empty = True

        while empty:
            empty = False
            for pathlist,n in result.getIndex():
                if n.attr.get('isDir') and  ( (n.value is None) or not n.value):
                    result.popNode(pathlist)
                    empty = True
        return result
Пример #4
0
def test_asDict():
    """docstring for asDict"""
    d = gnrstring.asDict('height=22, weight=73')
    assert d['height'] == '22' and d['weight'] == '73' and isinstance(d, dict)
    d = gnrstring.asDict('height=$myheight, weight=73', symbols={'myheight': 55})
    assert d['height'] == '55' and d['weight'] == '73' and isinstance(d, dict)
Пример #5
0
 def _df_handleGetter(self,fb,code=None,getter=None):
     kw = asDict(getter['where'].replace('\n',','))
     _iflist = [k for k,v in kw.items() if v.startswith('^') or v.startswith('=')]
     if _iflist:
         kw['_if'] = ' && '.join(_iflist)
     fb.dataRemote('.%s' %code,self._df_remoteGetter,table=getter['table'],column=getter['column'],innerpath=getter['innerpath'],**kw)
Пример #6
0
def test_stringDict():
    """docstring for test_stringDict"""
    d = {'height': '22', 'width': '33'}
    assert gnrstring.asDict(gnrstring.stringDict(d)) == d