fixes to new import/export

This commit is contained in:
Rushabh Mehta 2011-07-01 11:08:05 +05:30
parent 5d1a9965a3
commit b19653a8a2
4 changed files with 20 additions and 6 deletions

View file

@ -30,7 +30,15 @@ def set_fieldname(field_id, fieldname):
#================================================================================= #=================================================================================
def get_link_fields(doctype): def get_link_fields(doctype):
return webnotes.conn.sql("SELECT fieldname, options, label FROM tabDocField WHERE parent='%s' and (fieldtype='Link' or (fieldtype='Select' and `options` like 'link:%%'))" % (doctype)) """
Returns list of link fields for a doctype in tuple (fieldname, options, label)
"""
return webnotes.conn.sql("""
SELECT fieldname, options, label
FROM tabDocField
WHERE parent='%s'
and (fieldtype='Link' or (fieldtype='Select' and `options` like 'link:%%'))
and fieldname!='owner'""" % (doctype))
#================================================================================= #=================================================================================

View file

@ -168,7 +168,7 @@ def to_html(doclist):
return out return out
def commonify_doclist(doclist): def commonify_doclist(doclist, with_comments=1):
""" """
Makes a doclist more readable by extracting common properties. Makes a doclist more readable by extracting common properties.
This is used for printing Documents in files This is used for printing Documents in files
@ -239,7 +239,7 @@ def uncommonify_doclist(dl):
final = [] final = []
for d in dl[1:]: for d in dl[1:]:
if d['name']=='__common__': if 'name' in d and d['name']=='__common__':
del d['name'] del d['name']
common_dict[d['doctype']] = d common_dict[d['doctype']] = d
else: else:

View file

@ -69,7 +69,7 @@ def write_document_file(doclist, record_module=None):
Write a doclist to file, can optionally specify module name Write a doclist to file, can optionally specify module name
""" """
import os import os
from webnotes.utils import pprint_doclist from webnotes.model.utils import pprint_doclist
module = get_module_name(doclist, record_module) module = get_module_name(doclist, record_module)

View file

@ -37,14 +37,20 @@ def import_module(module, verbose=0):
def get_doclist(path, doctype, docname): def get_doclist(path, doctype, docname):
"returns a doclist (list of dictionaries) of multiple records for the given parameters" "returns a doclist (list of dictionaries) of multiple records for the given parameters"
import os import os
from webnotes.utils import peval_doclist from webnotes.model.utils import peval_doclist
do_not_import = ('control_panel') do_not_import = ('control_panel')
fname = os.path.join(path,doctype,docname,docname+'.txt') fname = os.path.join(path,doctype,docname,docname+'.txt')
if os.path.exists(fname) and (doctype not in do_not_import): if os.path.exists(fname) and (doctype not in do_not_import):
f = open(fname,'r') f = open(fname,'r')
dl = peval_doclist(f.read()) txt = f.read()
# if exported using pprint_doclist, then file starts with a comment
if txt.startswith('#'):
dl = peval_doclist(txt)
else:
dl = eval(txt)
f.close() f.close()
return dl return dl
else: else: