def th_menuQueries(self,table=None,th_root=None,pyqueries=None,editor=True,favoriteQueryPath=None,**kwargs): querymenu = Bag() if editor: querymenu.setItem('__basequery__',None,caption='!!Plain Query',description='', extended=False) querymenu.setItem('r_1',None,caption='-') savedquerymenu = self.db.table('adm.userobject').userObjectMenu(table,objtype='query') if 'adm' in self.db.packages else [] if savedquerymenu: querymenu.update(savedquerymenu) querymenu.setItem('r_2',None,caption='-') if pyqueries: for n in pyqueries: querymenu.setItem(n.label,n.value,caption=n.attr.get('description'),_attributes=n.attr) querymenu.setItem('r_3',None,caption='-') if editor: querymenu.setItem('__queryeditor__',None,caption='!!Query editor',action=""" var currentQuery = GET .query.currentQuery; SET .query.queryAttributes.extended=true; SET .query.queryEditor=true;""") else: querymenu.setItem('__newquery__',None,caption='!!New query',description='', extended=True) if self.application.checkResourcePermission('_DEV_,dbadmin', self.userTags): querymenu.setItem('__custom_columns__',None,caption='!!Custom columns',action="""FIRE .handle_custom_column;""") querymenu.walk(self._th_checkFavoriteLine,favPath=favoriteQueryPath) return querymenu
def saveLocalizationFile(self, data=None, **kwargs): changesdict = dict() for k, v in data['griddata'].items(): filtered = v.filter(lambda n: '_loadedValue' in n.attr) if filtered: changesdict[v['_lockey']] = dict(filtered) localizer = self.db.application.localizer updatablebags = localizer.updatableLocBags['all' if self.isDeveloper( ) else 'unprotected'] def cb(n, changedNodes=None, localizationDict=None): if n.label in changesdict: n.attr.update(changesdict[n.label]) changedNodes.append(n.label) localizer_item = localizationDict.get(n.label) if localizer_item: localizer_item.update(changesdict[n.label]) for destFolder in updatablebags: locbagpath = os.path.join(destFolder, 'localization.xml') locbag = Bag(locbagpath) if os.path.exists(locbagpath) else Bag() changedNodes = [] locbag.walk(cb, changedNodes=changedNodes, localizationDict=localizer.localizationDict) if changedNodes: locbag.toXml(locbagpath)
def ht_htableViewStore(self,pane,table=None,storepath='.store',caption_field=None,condition=None,caption=None, dbstore=None,root_id=None,columns=None,related_kwargs=None,resolved=False,**kwargs): b = Bag() tblobj = self.db.table(table) caption = caption or tblobj.name_plural if condition: d = pane.dataRpc(storepath,self.ht_remoteHtableViewStore, table=table, caption_field=caption_field, condition=condition, childname='store',caption=caption,dbstore=dbstore, columns=columns,related_kwargs=related_kwargs, **kwargs) return d v = TableHandlerTreeResolver(_page=self,table=table,caption_field=caption_field,dbstore=dbstore,related_kwargs=related_kwargs, root_id=root_id,columns=columns) b.setItem('root',v,caption=tblobj.name_long, child_count=1,pkey='',treeIdentifier='_root_') if resolved: def cb(self,*args,**kwargs): pass b.walk(cb) d = pane.data(storepath,b,childname='store',caption=caption,table=table) return d
def ht_htableViewStore(self, pane, table=None, storepath='.store', caption_field=None, condition=None, caption=None, dbstore=None, root_id=None, columns=None, related_kwargs=None, resolved=False, **kwargs): b = Bag() tblobj = self.db.table(table) caption = caption or tblobj.name_plural if condition: d = pane.dataRpc(storepath, self.ht_remoteHtableViewStore, table=table, caption_field=caption_field, condition=condition, childname='store', caption=caption, dbstore=dbstore, columns=columns, related_kwargs=related_kwargs, **kwargs) return d v = TableHandlerTreeResolver(_page=self, table=table, caption_field=caption_field, dbstore=dbstore, related_kwargs=related_kwargs, root_id=root_id, columns=columns) b.setItem('root', v, caption=tblobj.name_long, child_count=1, pkey='', treeIdentifier='_root_') if resolved: def cb(self, *args, **kwargs): pass b.walk(cb) d = pane.data(storepath, b, childname='store', caption=caption, table=table) return d
def _printAndMailMenu(self,table=None,flags=None,from_resource=True,res_type=None,**kwargs): result = Bag() if from_resource: resources = self.table_script_resource_tree_data(table=table,res_type=res_type) if resources: result.update(resources) flags = flags or 'is_%s' %res_type templates = self.db.table('adm.userobject').userObjectMenu(table=table,objtype='template',flags=flags) if templates and len(templates)>0: result.update(templates) result.walk(self._th_addTpl,res_type=res_type) return result
def getHierarchicalData(self, caption_field=None, condition=None, condition_kwargs=None, caption=None, dbstore=None, columns=None, related_kwargs=None, resolved=False, parent_id=None, root_id=None, alt_pkey_field=None, **kwargs): b = Bag() caption = caption or self.tblobj.name_plural condition_kwargs = condition_kwargs or dict() condition_kwargs.update(dictExtract(kwargs, 'condition_')) related_kwargs = related_kwargs or {} v = TableHandlerTreeResolver(_page=self, table=self.tblobj.fullname, caption_field=caption_field, condition=condition, dbstore=dbstore, columns=columns, related_kwargs=related_kwargs, condition_kwargs=condition_kwargs, root_id=root_id, parent_id=parent_id, alt_pkey_field=alt_pkey_field) b.setItem( 'root', v, caption=caption, child_count=1, pkey='', treeIdentifier='_root_', table=self.tblobj.fullname, search_method=self.tblobj.hierarchicalSearch, search_related_table=related_kwargs.get('table'), search_related_path=related_kwargs.get('path'), search_related_caption_field=related_kwargs.get('caption_field')) if resolved: def cb(self, *args, **kwargs): pass b.walk(cb, _mode='') return b
def getHierarchicalData(self,caption_field=None,condition=None, condition_kwargs=None,caption=None, dbstore=None,columns=None,related_kwargs=None, resolved=False,parent_id=None,root_id=None,**kwargs): b = Bag() caption = caption or self.tblobj.name_plural condition_kwargs = condition_kwargs or dict() condition_kwargs.update(dictExtract(kwargs,'condition_')) v = TableHandlerTreeResolver(_page=self,table=self.tblobj.fullname,caption_field=caption_field,condition=condition,dbstore=dbstore,columns=columns,related_kwargs=related_kwargs, condition_kwargs=condition_kwargs,root_id=root_id,parent_id=parent_id) b.setItem('root',v,caption=caption,child_count=1,pkey='',treeIdentifier='_root_') if resolved: def cb(self,*args,**kwargs): pass b.walk(cb) return b
def th_menuViews(self,table=None,th_root=None,pyviews=None,favoriteViewPath=None,currentView=None,**kwargs): result = Bag() currentView = currentView or favoriteViewPath or '__baseview__' gridId = '%s_grid' %th_root result.setItem('__baseview__', None,caption='Base View',gridId=gridId,checked = currentView=='__baseview__') if pyviews: for k,caption in pyviews: result.setItem(k.replace('_','.'),None,description=caption,caption=caption,viewkey=k,gridId=gridId) userobjects = self.db.table('adm.userobject').userObjectMenu(objtype='view',flags='%s_%s' % (self.pagename, gridId),table=table) if self.pagename.startswith('thpage'): #compatibility old saved views userobjects.update(self.db.table('adm.userobject').userObjectMenu(objtype='view',flags='thpage_%s' % gridId,table=table)) if len(userobjects)>0: result.update(userobjects) result.walk(self._th_checkFavoriteLine,favPath=favoriteViewPath,currentView=currentView,gridId=gridId) return result
def loadLocalizationFile(self, path=None, currentLocalizationBlock=None, enabledLanguages=None, **kwargs): localizationpath = os.path.join(path, 'localization.xml') localization = Bag(localizationpath) if os.path.exists( localizationpath) else Bag() localization.setBackRef() enabledLanguages = enabledLanguages.split( ',') if enabledLanguages else [] griddata = Bag() treedata = Bag() treedata.setItem('root', Bag(), caption=currentLocalizationBlock) treeroot = treedata['root'] def cb(n): if n.attr.get('path'): treeroot.setItem(n.fullpath or n.label, None, path=n.attr['path'], ext=n.attr['ext'], caption=n.label) elif not n.value: row = griddata[n.label] parentNode = n.parentNode parentAttr = parentNode.attr module = parentAttr.get('path') if not row: row = Bag() griddata[n.label] = row row['base'] = n.attr.get('base') row['ext'] = parentAttr.get('ext') row['_lockey'] = n.label row['path'] = [] row['_pkey'] = n.label row['path'].append(module) #row['_treepath'] = '%s.%s' %((parentNode.fullpath or parentNode.label),parentAttr.get('ext')) for lang in enabledLanguages: row[lang] = row[lang] or n.attr.get(lang) localization.walk(cb) griddata.sort('base') return Bag(dict(content=Bag(griddata=griddata), treedata=treedata))
def getHierarchicalData(self,caption_field=None,condition=None, condition_kwargs=None,caption=None, dbstore=None,columns=None,related_kwargs=None, resolved=False,parent_id=None,root_id=None,alt_pkey_field=None,**kwargs): b = Bag() caption = caption or self.tblobj.name_plural condition_kwargs = condition_kwargs or dict() condition_kwargs.update(dictExtract(kwargs,'condition_')) related_kwargs = related_kwargs or {} v = TableHandlerTreeResolver(_page=self,table=self.tblobj.fullname,caption_field=caption_field,condition=condition,dbstore=dbstore,columns=columns,related_kwargs=related_kwargs, condition_kwargs=condition_kwargs,root_id=root_id,parent_id=parent_id,alt_pkey_field=alt_pkey_field) b.setItem('root',v,caption=caption,child_count=1,pkey='',treeIdentifier='_root_',table=self.tblobj.fullname, search_method=self.tblobj.hierarchicalSearch,search_related_table=related_kwargs.get('table'), search_related_path=related_kwargs.get('path'),search_related_caption_field=related_kwargs.get('caption_field')) if resolved: def cb(self,*args,**kwargs): pass b.walk(cb,_mode='') return b