Merge branch 'master' of git://github.com/rmehta/wnframework

This commit is contained in:
nabinhait 2011-07-01 15:10:37 +05:30
commit 5e574e413e
3 changed files with 19 additions and 17 deletions

View file

@ -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))

View file

@ -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))

View file

@ -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: