From 1ccb9dc1398fb65249f7b29d06cbfe1cfe9ede4b Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 1 Jul 2011 13:52:11 +0530 Subject: [PATCH] fixes to import in doctype.py --- cgi-bin/webnotes/model/doctype.py | 23 +++++++++++++---------- cgi-bin/webnotes/model/utils.py | 5 +++++ cgi-bin/webnotes/modules/import_module.py | 8 +------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/cgi-bin/webnotes/model/doctype.py b/cgi-bin/webnotes/model/doctype.py index ce61b3c8fd..39a6137496 100644 --- a/cgi-bin/webnotes/model/doctype.py +++ b/cgi-bin/webnotes/model/doctype.py @@ -131,10 +131,12 @@ class _DocType: Returns a dictionary of DocFields by fieldname or label """ try: - doclist = open(file_name, 'r').read() + txt = open(file_name, 'r').read() except: return - doclist = eval(doclist) + from webnotes.model.utils import peval_doclist + + doclist = peval_doclist(txt) fields = {} for d in doclist: if d['doctype']=='DocField': @@ -179,15 +181,16 @@ class _DocType: # update the values for field_to_update in update_fields: - new_value = fields[key][field_to_update] + if field_to_update in fields[key] and fields[key][field_to_update] != d.fields[field_to_update]: + new_value = fields[key][field_to_update] - # in doclist - d.fields[field_to_update] = new_value - - # in database - webnotes.conn.sql("update tabDocField set `%s` = %s where parent=%s and `%s`=%s" % \ - (field_to_update, '%s', '%s', (d.fieldname and 'fieldname' or 'label'), '%s'), \ - (new_value, doc.name, key)) + # in doclist + d.fields[field_to_update] = new_value + + # in database + webnotes.conn.sql("update tabDocField set `%s` = %s where parent=%s and `%s`=%s" % \ + (field_to_update, '%s', '%s', (d.fieldname and 'fieldname' or 'label'), '%s'), \ + (new_value, doc.name, key)) webnotes.conn.sql("update tabDocType set _last_update=%s where name=%s", (time_stamp, doc.name)) diff --git a/cgi-bin/webnotes/model/utils.py b/cgi-bin/webnotes/model/utils.py index a842762937..2d019273f1 100644 --- a/cgi-bin/webnotes/model/utils.py +++ b/cgi-bin/webnotes/model/utils.py @@ -264,4 +264,9 @@ def peval_doclist(txt): """ Restore a pretty printed doclist """ + if txt.startswith('#'): + return uncommonify_doclist(eval(txt)) + else: + return eval(txt) + return uncommonify_doclist(eval(txt)) diff --git a/cgi-bin/webnotes/modules/import_module.py b/cgi-bin/webnotes/modules/import_module.py index fa6b260581..ed885f48e8 100644 --- a/cgi-bin/webnotes/modules/import_module.py +++ b/cgi-bin/webnotes/modules/import_module.py @@ -44,13 +44,7 @@ def get_doclist(path, doctype, docname): 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') - 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) + dl = peval_doclist(f.read()) f.close() return dl else: