Przeglądaj źródła

fixes to import in doctype.py

version-14
Rushabh Mehta 14 lat temu
rodzic
commit
1ccb9dc139
3 zmienionych plików z 19 dodań i 17 usunięć
  1. +13
    -10
      cgi-bin/webnotes/model/doctype.py
  2. +5
    -0
      cgi-bin/webnotes/model/utils.py
  3. +1
    -7
      cgi-bin/webnotes/modules/import_module.py

+ 13
- 10
cgi-bin/webnotes/model/doctype.py Wyświetl plik

@@ -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]
# in doclist
d.fields[field_to_update] = new_value
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 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))


+ 5
- 0
cgi-bin/webnotes/model/utils.py Wyświetl plik

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

+ 1
- 7
cgi-bin/webnotes/modules/import_module.py Wyświetl plik

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


Ładowanie…
Anuluj
Zapisz