fixes to import in doctype.py
This commit is contained in:
parent
b19653a8a2
commit
1ccb9dc139
3 changed files with 19 additions and 17 deletions
|
|
@ -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))
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue