exportoo/renderers.py

55 lines
1.3 KiB
Python
Raw Normal View History

2022-01-16 18:41:00 +01:00
from __future__ import print_function
# TABLE VIEW COLUMNS
cols = {
'': [ 'id', 'name' ], # default
'ir.model': [ 'id', 'model' ],
'ir.model.fields': [ 'id', 'name', 'ttype', 'create_uid', 'relation', 'display_name', 'complete_name' ],
}
def tsv( *fields ):
print( *fields, sep='\t' )
def csv( *fields ):
print( *[ '"' + f.replace('"','\\"') + '"' for f in fields ], sep=',' )
def render_tsv( model, list ):
if model in cols:
_cols = cols[model]
else:
_cols = cols['']
tsv( *_cols )
for obj in list:
tsv( *[ obj[col] for col in _cols] )
def render_csv( model, list ):
if model in cols:
_cols = cols[model]
else:
_cols = cols['']
csv( *_cols )
for obj in list:
csv( *[ obj[col] for col in _cols] )
def render_json( model, list ):
jlog( list )
#def render_json( model, obj ):
def render( opts, model, list ): # +format=json,xml,csv +json +tsv
2022-01-16 19:09:33 +01:00
if ( 'json' in opts and opts['json'] ) or ( 'format' in opts and 'json' in opts['format'] ):
render_json( model, list )
2022-01-16 19:09:33 +01:00
if ( 'tsv' in opts and opts['tsv'] ) or ( 'format' in opts and 'tsv' in opts['format'] ):
render_tsv( model, list )
2022-01-16 19:09:33 +01:00
if ( 'csv' in opts and opts['csv'] ) or ( 'format' in opts and 'csv' in opts['format'] ):
render_csv( model, list )
2022-01-16 19:09:33 +01:00
# if ( 'xml' in opts and opts['xml'] ) or ( 'format' in opts and 'xml' in opts['format'] ):
# render_xml( model, list )