Example #1
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='')