From b19653a8a2e05bd113eaf0dbb2b3d7ca08e5668c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 1 Jul 2011 11:08:05 +0530 Subject: [PATCH] fixes to new import/export --- cgi-bin/webnotes/model/meta.py | 10 +++++++++- cgi-bin/webnotes/model/utils.py | 4 ++-- cgi-bin/webnotes/modules/export_module.py | 2 +- cgi-bin/webnotes/modules/import_module.py | 10 ++++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cgi-bin/webnotes/model/meta.py b/cgi-bin/webnotes/model/meta.py index f9fa156e33..054a78ee5c 100644 --- a/cgi-bin/webnotes/model/meta.py +++ b/cgi-bin/webnotes/model/meta.py @@ -30,7 +30,15 @@ def set_fieldname(field_id, fieldname): #================================================================================= 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)) #================================================================================= diff --git a/cgi-bin/webnotes/model/utils.py b/cgi-bin/webnotes/model/utils.py index 0d692d8f93..a842762937 100644 --- a/cgi-bin/webnotes/model/utils.py +++ b/cgi-bin/webnotes/model/utils.py @@ -168,7 +168,7 @@ def to_html(doclist): return out -def commonify_doclist(doclist): +def commonify_doclist(doclist, with_comments=1): """ Makes a doclist more readable by extracting common properties. This is used for printing Documents in files @@ -239,7 +239,7 @@ def uncommonify_doclist(dl): final = [] for d in dl[1:]: - if d['name']=='__common__': + if 'name' in d and d['name']=='__common__': del d['name'] common_dict[d['doctype']] = d else: diff --git a/cgi-bin/webnotes/modules/export_module.py b/cgi-bin/webnotes/modules/export_module.py index c9bad8650c..3055fc5db9 100644 --- a/cgi-bin/webnotes/modules/export_module.py +++ b/cgi-bin/webnotes/modules/export_module.py @@ -69,7 +69,7 @@ def write_document_file(doclist, record_module=None): Write a doclist to file, can optionally specify module name """ import os - from webnotes.utils import pprint_doclist + from webnotes.model.utils import pprint_doclist module = get_module_name(doclist, record_module) diff --git a/cgi-bin/webnotes/modules/import_module.py b/cgi-bin/webnotes/modules/import_module.py index 6be48d646b..fa6b260581 100644 --- a/cgi-bin/webnotes/modules/import_module.py +++ b/cgi-bin/webnotes/modules/import_module.py @@ -37,14 +37,20 @@ def import_module(module, verbose=0): def get_doclist(path, doctype, docname): "returns a doclist (list of dictionaries) of multiple records for the given parameters" import os - from webnotes.utils import peval_doclist + from webnotes.model.utils import peval_doclist do_not_import = ('control_panel') fname = os.path.join(path,doctype,docname,docname+'.txt') if os.path.exists(fname) and (doctype not in do_not_import): 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() return dl else: