Exemple #1
0
 def _columnPythonCode(self,col,relation=None):
     attributes = Bag()
     col = col.deepcopy()
     name = col.pop('name')
     dtype = col.pop('dtype')
     size = col.pop('size')
     name_long = col.pop('name_long')
     name_short = col.pop('name_short')
     tag = col.pop('tag') #column,formulaColumn,aliasColumn,pyColumn
     if dtype and dtype not in ('A','T','C'):
         attributes['dtype'] = dtype
     if size:
         attributes['size'] = size
     attributes.setItem('name_long', name_long or name,localized=True)
     if name_short:
         attributes.setItem('name_short', name_short,localized=True)
     attributes.update(col)
     relationCode = ''
     if relation and relation['relation']:
         relationCode = '.%s' %self._relationPythonCode(relation)
     coltype = 'column'
     if attributes['sql_formula'] or attributes['select'] or attributes['exists']:
         coltype = 'formulaColumn'
     elif attributes['relation_path']:
         coltype = 'aliasColumn'
     elif attributes['pymethod']:
         coltype = 'pyColumn'
     return "tbl.%s('%s'%s)%s" % (coltype,name, self.bagToArgString(attributes),relationCode)
Exemple #2
0
 def _columnPythonCode(self, col, relation=None):
     attributes = Bag()
     col = col.deepcopy()
     name = col.pop('name')
     dtype = col.pop('dtype')
     size = col.pop('size')
     name_long = col.pop('name_long')
     name_short = col.pop('name_short')
     tag = col.pop('tag')  #column,formulaColumn,aliasColumn,pyColumn
     if dtype and dtype not in ('A', 'T', 'C'):
         attributes['dtype'] = dtype
     if size:
         attributes['size'] = size
     attributes.setItem('name_long', name_long or name, localized=True)
     if name_short:
         attributes.setItem('name_short', name_short, localized=True)
     attributes.update(col)
     relationCode = ''
     if relation and relation['relation']:
         relationCode = '.%s' % self._relationPythonCode(relation)
     coltype = 'column'
     if attributes['sql_formula'] or attributes['select'] or attributes[
             'exists']:
         coltype = 'formulaColumn'
     elif attributes['relation_path']:
         coltype = 'aliasColumn'
     elif attributes['pymethod']:
         coltype = 'pyColumn'
     return "tbl.%s('%s'%s)%s" % (
         coltype, name, self.bagToArgString(attributes), relationCode)
Exemple #3
0
 def loadTableModule(self,pkey=None,project=None,package=None,**kwargs):
     if pkey=='*newrecord*':
         record = Bag()
         record['_sysFields'] = self.handleSysFields()
         resultAttr = dict(_pkey=pkey,_newrecord=True,project=project,package=package)
         return record,resultAttr
     table = pkey
     red = self.get_redbaron(os.path.join(os.path.join(self.getPackagePath(project,package),'model','%s.py' %table)))
     resultAttr = dict(_pkey=pkey,_newrecord=False,project=project,package=package)
     record = Bag()
     record['name'] = table
     record['_sysFields'] = self.handleSysFields(red)
     config_db = red.find('def','config_db')
     if config_db:
         targs,tkwargs = self.parsBaronNodeCall(config_db.find('name','table').parent[2])
         record.update(tkwargs)
         columnsvalue = Bag()
         for colNode in red.find_all('name','column'):
             cbag = self._loadColumnBag(colNode)
             cbag['tag'] = 'column'
             columnsvalue[cbag['name']] = cbag
         for colNode in red.find_all('name','aliasColumn'):
             cbag = self._getColBag(colNode,'relation_path')
             cbag['tag'] = 'aliasColumn'
             columnsvalue.setItem(cbag['name'],cbag,_customClasses='aliasColumnRow')
         for colNode in red.find_all('name','formulaColumn'):
             cbag = self._getColBag(colNode,'sql_formula')
             cbag['tag'] = 'formulaColumn'
             columnsvalue.setItem(cbag['name'],cbag,_customClasses='formulaColumnRow')
         for colNode in red.find_all('name','pyColumn'):
             cbag = self._getColBag(colNode,'py_method')
             cbag['tag'] = 'pyColumn'
             columnsvalue.setItem(cbag['name'],cbag,_customClasses='pyColumnRow')
         record.setItem('_columns',columnsvalue,_sendback=True)
     return record,resultAttr
Exemple #4
0
    def te_renderTemplate(self, templateBuilder, record_id=None, extraData=None, locale=None,contentOnly=False,**kwargs):
        record = Bag()
        if record_id:
            record = templateBuilder.data_tblobj.record(pkey=record_id,
                                                        virtual_columns=templateBuilder.virtual_columns).output('bag')
        else:
            record = templateBuilder.data_tblobj.record(pkey='*sample*',ignoreMissing=True,
                                                        virtual_columns=templateBuilder.virtual_columns).output('sample')
        if extraData:
            record.update(extraData)
        locale = locale or templateBuilder.locale
        formats = templateBuilder.formats or dict()
        masks = templateBuilder.masks or dict()
        editcols = templateBuilder.editcols or dict()

        df_templates = templateBuilder.df_templates or dict()
        dtypes = templateBuilder.dtypes or dict()

        record.setItem('_env_', Bag(self.db.currentEnv))
        #record.setItem('_template_', templateBuilder.doctemplate_info)
        htmlContent = templateReplace(templateBuilder.doctemplate,record, safeMode=True,noneIsBlank=False,locale=locale, 
                                                            formats=formats,masks=masks,editcols=editcols,df_templates=df_templates,
                                                            dtypes=dtypes,localizer=self.localizer,
                                                            urlformatter=self.externalUrl)
        if contentOnly:
            return htmlContent
        body = templateBuilder(htmlContent=htmlContent,
                            record=record,page_debug='silver',**kwargs)
        return body
Exemple #5
0
class ViewRecordHistory(BaseComponent):
    def th_hiddencolumns(self):
        return '$event,$data'

    def th_struct(self,struct):
        r = struct.view().rows()
        r.fieldcell('version',name='V',width='4em')
        r.fieldcell('__ins_ts',name='TS',width='10em')
        r.fieldcell('username',name='User',width='10em')
        r.cell('changed_fields',name='Changes',width='15em',calculated=True)


    @public_method
    def th_applymethod(self,selection):
        selection.sort('version') 
        self._curr_audit_record = Bag()
        def cb(row):
            b = Bag(row['data'])
            result = dict()
            if row['version'] >0:
                result['changed_fields'] = '<br/>'.join(b.keys())
            b.pop('__ins_ts')
            b.pop('__version')
            b.pop('__mod_ts')
            self._curr_audit_record.update(b)
            result['__value__'] = self._curr_audit_record.deepcopy()
            return result
        selection.apply(cb)
        selection.sort('version:d') 

    def th_order(self):
        return 'version:d'

    def th_query(self):
        return dict(column='tablename', op='contains', val='')
Exemple #6
0
    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
Exemple #7
0
 def writeError(self,description=None,error_type=None,user=None,user_ip=None,user_agent=None,**kwargs):
     error_data = Bag(self.db.currentEnv)
     error_data.update(kwargs)
     rec = dict(description=description,error_data=error_data,username=user,user_ip=user_ip,user_agent=user_agent,error_type=error_type or 'ERR')
     with self.db.tempEnv(connectionName='system',storename=self.db.rootstore):
         self.insert(rec)
         self.db.commit()
     return rec
Exemple #8
0
 def crt_menuCharts(self,table=None,pyviews=None,favoriteViewPath=None,gridId=None,**kwargs):
     result = Bag()
     userobjects = self.db.table('adm.userobject').userObjectMenu(objtype='chartjs',flags='%s_%s' % (self.pagename, gridId) if gridId else None,table=table)
     if len(userobjects)>0:
         result.update(userobjects)
         result.setItem('r_sep',None,caption='-')
     result.setItem('__newchart__',None,caption='!!New Chart')
     return result
Exemple #9
0
 def test_update(self):
     b = Bag(BAG_DATA)
     c = Bag()
     c.setItem('hobbie.sport', 'soccer', role='forward')
     c.setItem('name', 'John K.')
     b.update(c)
     assert b['name'] == 'John K.'
     assert b.getAttr('hobbie.sport', 'role') == 'forward'
Exemple #10
0
 def test_update(self):
     b = Bag(BAG_DATA)
     c = Bag()
     c.setItem('hobbie.sport', 'soccer', role='forward')
     c.setItem('name', 'John K.')
     b.update(c)
     assert b['name'] == 'John K.'
     assert b.getAttr('hobbie.sport', 'role') == 'forward'
Exemple #11
0
 def renderTemplate(self, templateBuilder, record_id=None, extraData=None):
     record = Bag()
     if record_id:
         record = templateBuilder.data_tblobj.record(pkey=record_id,
                                                     virtual_columns=templateBuilder.virtual_columns).output('bag')
     if extraData:
         record.update(extraData)
     record.setItem('_env_', Bag(self.db.currentEnv))
     record.setItem('_template_', templateBuilder.doctemplate_info)
     templateBuilder.record = record
     return templateBuilder(htmlContent=templateReplace(templateBuilder.doctemplate, record, True))
Exemple #12
0
 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
Exemple #13
0
 def rpc_getMessages(self):
     msgbag = Bag()
     msgfolder = self.pageLocalDocument(os.path.join('_messages'))
     if os.path.exists(msgfolder):
         files = [(os.stat(os.path.join(msgfolder, f)).st_mtime, f) for f in os.listdir(msgfolder)]
         files.sort()
         for f in files:
             if not f.startswith('.'):
                 fname = os.path.join(msgfolder, f)
                 b = Bag(fname)
                 msgbag.update(b)
                 os.remove(fname)
     return msgbag
Exemple #14
0
 def renderTemplate(self, templateBuilder, record_id=None, extraData=None):
     record = Bag()
     if record_id:
         record = templateBuilder.data_tblobj.record(
             pkey=record_id,
             virtual_columns=templateBuilder.virtual_columns).output('bag')
     if extraData:
         record.update(extraData)
     record.setItem('_env_', Bag(self.db.currentEnv))
     record.setItem('_template_', templateBuilder.doctemplate_info)
     templateBuilder.record = record
     return templateBuilder(htmlContent=templateReplace(
         templateBuilder.doctemplate, record, True))
Exemple #15
0
 def loadTableModule(self, pkey=None, project=None, package=None, **kwargs):
     if pkey == '*newrecord*':
         record = Bag()
         record['_sysFields'] = self.handleSysFields()
         resultAttr = dict(_pkey=pkey,
                           _newrecord=True,
                           project=project,
                           package=package)
         return record, resultAttr
     table = pkey
     red = self.get_redbaron(
         os.path.join(
             os.path.join(self.getPackagePath(project, package), 'model',
                          '%s.py' % table)))
     resultAttr = dict(_pkey=pkey,
                       _newrecord=False,
                       project=project,
                       package=package)
     record = Bag()
     record['name'] = table
     record['_sysFields'] = self.handleSysFields(red)
     config_db = red.find('def', 'config_db')
     if config_db:
         targs, tkwargs = self.parsBaronNodeCall(
             config_db.find('name', 'table').parent[2])
         record.update(tkwargs)
         columnsvalue = Bag()
         for colNode in red.find_all('name', 'column'):
             cbag = self._loadColumnBag(colNode)
             cbag['tag'] = 'column'
             columnsvalue[cbag['name']] = cbag
         for colNode in red.find_all('name', 'aliasColumn'):
             cbag = self._getColBag(colNode, 'relation_path')
             cbag['tag'] = 'aliasColumn'
             columnsvalue.setItem(cbag['name'],
                                  cbag,
                                  _customClasses='aliasColumnRow')
         for colNode in red.find_all('name', 'formulaColumn'):
             cbag = self._getColBag(colNode, 'sql_formula')
             cbag['tag'] = 'formulaColumn'
             columnsvalue.setItem(cbag['name'],
                                  cbag,
                                  _customClasses='formulaColumnRow')
         for colNode in red.find_all('name', 'pyColumn'):
             cbag = self._getColBag(colNode, 'py_method')
             cbag['tag'] = 'pyColumn'
             columnsvalue.setItem(cbag['name'],
                                  cbag,
                                  _customClasses='pyColumnRow')
         record.setItem('_columns', columnsvalue, _sendback=True)
     return record, resultAttr
Exemple #16
0
 def rpc_getMessages(self):
     msgbag = Bag()
     msgfolder = self.pageLocalDocument(os.path.join('_messages'))
     if os.path.exists(msgfolder):
         files = [(os.stat(os.path.join(msgfolder, f)).st_mtime, f)
                  for f in os.listdir(msgfolder)]
         files.sort()
         for f in files:
             if not f.startswith('.'):
                 fname = os.path.join(msgfolder, f)
                 b = Bag(fname)
                 msgbag.update(b)
                 os.remove(fname)
     return msgbag
Exemple #17
0
    def te_renderTemplate(self,
                          templateBuilder,
                          record_id=None,
                          extraData=None,
                          locale=None,
                          contentOnly=False,
                          **kwargs):
        record = Bag()
        if record_id:
            record = templateBuilder.data_tblobj.record(
                pkey=record_id,
                virtual_columns=templateBuilder.virtual_columns).output('bag')
        else:
            record = templateBuilder.data_tblobj.record(
                pkey='*sample*',
                ignoreMissing=True,
                virtual_columns=templateBuilder.virtual_columns).output(
                    'sample')
        if extraData:
            record.update(extraData)
        locale = locale or templateBuilder.locale
        formats = templateBuilder.formats or dict()
        masks = templateBuilder.masks or dict()
        editcols = templateBuilder.editcols or dict()

        df_templates = templateBuilder.df_templates or dict()
        dtypes = templateBuilder.dtypes or dict()

        record.setItem('_env_', Bag(self.db.currentEnv))
        #record.setItem('_template_', templateBuilder.doctemplate_info)
        htmlContent = templateReplace(templateBuilder.doctemplate,
                                      record,
                                      safeMode=True,
                                      noneIsBlank=False,
                                      locale=locale,
                                      formats=formats,
                                      masks=masks,
                                      editcols=editcols,
                                      df_templates=df_templates,
                                      dtypes=dtypes,
                                      localizer=self.localizer,
                                      urlformatter=self.externalUrl)
        if contentOnly:
            return htmlContent
        body = templateBuilder(htmlContent=htmlContent,
                               record=record,
                               page_debug='silver',
                               **kwargs)
        return body
Exemple #18
0
 def resourcesAtPath(self, pkg, path, ext):
     """add???
     
     :param pkg: add???
     :param path: add???
     :param ext: add???
     :returns: add???
     """
     result = Bag()
     locations = list(self.package_resourceDirs(pkg))
     for dpath in locations:
         dirpath = os.path.join(dpath, path)
         if os.path.isdir(dirpath):
             b = DirectoryResolver(dirpath, include='*.py', dropext=True)
             result.update(b, resolved=True)
     return result
Exemple #19
0
 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
Exemple #20
0
 def crt_menuCharts(self,
                    table=None,
                    pyviews=None,
                    favoriteViewPath=None,
                    gridId=None,
                    **kwargs):
     result = Bag()
     userobjects = self.db.table('adm.userobject').userObjectMenu(
         objtype='chartjs',
         flags='%s_%s' % (self.pagename, gridId) if gridId else None,
         table=table)
     if len(userobjects) > 0:
         result.update(userobjects)
         result.setItem('r_sep', None, caption='-')
     result.setItem('__newchart__', None, caption='!!New Chart')
     return result
Exemple #21
0
 def resourcesAtPath(self, pkg, path, ext):
     """add???
     
     :param pkg: add???
     :param path: add???
     :param ext: add???
     :returns: add???
     """
     result = Bag()
     locations = list(self.package_resourceDirs(pkg))
     for dpath in locations:
         dirpath = os.path.join(dpath, path)
         if os.path.isdir(dirpath):
             b = DirectoryResolver(dirpath, include='*.py', dropext=True)
             result.update(b, resolved=True)
     return result
 def resourcesAtPath(self,page=None, pkg=None, path=None, ext='py'):
     """TODO
     
     :param pkg: the :ref:`package <packages>` object
     :param path: TODO
     :param ext: TODO"""
     result = Bag()
     if pkg:
         locations = list(self.package_resourceDirs(pkg))
     else:
         locations = page.resourceDirs
     for dpath in locations:
         dirpath = os.path.join(dpath, path)
         if os.path.isdir(dirpath):
             b = DirectoryResolver(dirpath, include='*.py', dropext=True)
             result.update(b, resolved=True)
     return result
Exemple #23
0
 def resourcesAtPath(self,page=None, pkg=None, path=None, ext='py'):
     """TODO
     
     :param pkg: the :ref:`package <packages>` object
     :param path: TODO
     :param ext: TODO"""
     result = Bag()
     if pkg:
         locations = list(self.package_resourceDirs(pkg))
     else:
         locations = page.resourceDirs
     for dpath in locations:
         dirpath = os.path.join(dpath, path)
         if os.path.isdir(dirpath):
             b = DirectoryResolver(dirpath, include='*.py', dropext=True)
             result.update(b, resolved=True)
     return result