diff --git a/cgi-bin/core/doctype/doctype/doctype.py b/cgi-bin/core/doctype/doctype/doctype.py
index 3b022ae663..3ac2e0f7b6 100644
--- a/cgi-bin/core/doctype/doctype/doctype.py
+++ b/cgi-bin/core/doctype/doctype/doctype.py
@@ -80,7 +80,7 @@ class DocType:
self.change_modified_of_parent()
- import webnotes.defs
+ from webnotes import defs
from webnotes.utils.transfer import in_transfer
if (not in_transfer) and getattr(webnotes.defs,'developer_mode', 0):
diff --git a/cgi-bin/core/doctype/sandbox/sandbox.txt b/cgi-bin/core/doctype/sandbox/sandbox.txt
index cae1065f59..c0dd5a3a94 100644
--- a/cgi-bin/core/doctype/sandbox/sandbox.txt
+++ b/cgi-bin/core/doctype/sandbox/sandbox.txt
@@ -76,7 +76,18 @@
'fieldname': 'test_link',
'fieldtype': 'Link',
'idx': 2,
- 'label': 'Test Link'
+ 'label': 'Test Link',
+ 'options': 'Profile'
+ },
+
+ # DocField
+ {
+ 'doctype': 'DocField',
+ 'fieldname': 'test_select',
+ 'fieldtype': 'Select',
+ 'idx': 2,
+ 'label': 'Test Select',
+ 'options': 'A\nB\nC'
},
# DocField
diff --git a/cgi-bin/webnotes/__init__.py b/cgi-bin/webnotes/__init__.py
index 6b77d0c7d3..06833e2e77 100644
--- a/cgi-bin/webnotes/__init__.py
+++ b/cgi-bin/webnotes/__init__.py
@@ -57,6 +57,8 @@ cookies = {}
auto_masters = {}
tenant_id = None
+from webnotes.utils import cstr
+
#
# Custom Class (no traceback)
#
@@ -90,13 +92,13 @@ def errprint(msg):
"""
Append to the :data:`debug log`
"""
- debug_log.append(str(msg or ''))
+ debug_log.append(cstr(msg or ''))
def msgprint(msg, small=0, raise_exception=0):
"""
Append to the :data:`message_log`
"""
- message_log.append((small and '__small:' or '')+str(msg or ''))
+ message_log.append((small and '__small:' or '')+cstr(msg or ''))
if raise_exception:
raise ValidationError
diff --git a/cgi-bin/webnotes/model/doclist.py b/cgi-bin/webnotes/model/doclist.py
index 6e0b816974..2da46a795e 100644
--- a/cgi-bin/webnotes/model/doclist.py
+++ b/cgi-bin/webnotes/model/doclist.py
@@ -97,7 +97,7 @@ class DocList:
"""
from webnotes.model.meta import is_single
- if (not is_single(self.doc.doctype)) and (not self.doc.fields.get('__islocal')):
+ if (not is_single(self.doc.doctype)) and (not cint(self.doc.fields.get('__islocal'))):
tmp = webnotes.conn.sql("""
SELECT modified FROM `tab%s` WHERE name="%s" for update"""
% (self.doc.doctype, self.doc.name))
@@ -130,7 +130,7 @@ class DocList:
webnotes.msgprint("""[Link Validation] Could not find the following values: %s.
Please correct and resave. Document Not Saved.""" % ', '.join(err_list), raise_exception=1)
- def update_timestamps(self):
+ def update_timestamps_and_docstatus(self):
"""
Update owner, creation, modified_by, modified, docstatus
"""
@@ -156,7 +156,7 @@ class DocList:
self.check_permission()
if check_links:
self.check_links()
- self.update_timestamps()
+ self.update_timestamps_and_docstatus()
def run_method(self, method):
"""
@@ -239,7 +239,10 @@ class DocList:
"""
Update after submit - some values changed after submit
"""
+ if self.doc.docstatus != 1:
+ msgprint("Only to called after submit", raise_exception=1)
self.to_docstatus = 1
+ self.prepare_for_save(1)
self.save_main()
self.save_children()
self.run_method('on_update_after_submit')
diff --git a/cgi-bin/webnotes/utils/__init__.py b/cgi-bin/webnotes/utils/__init__.py
index e770963a7c..f8156046c2 100644
--- a/cgi-bin/webnotes/utils/__init__.py
+++ b/cgi-bin/webnotes/utils/__init__.py
@@ -295,7 +295,10 @@ def cstr(s):
s = s.encode('utf-8', 'ignore')
except:
pass
- return str(s)
+ try:
+ return unicode(s)
+ except UnicodeDecodeError:
+ return unicode(s, 'utf-8')
def str_esc_quote(s):
"""
diff --git a/cgi-bin/webnotes/utils/file_manager.py b/cgi-bin/webnotes/utils/file_manager.py
index 26575ffd5f..181403cb05 100644
--- a/cgi-bin/webnotes/utils/file_manager.py
+++ b/cgi-bin/webnotes/utils/file_manager.py
@@ -7,20 +7,86 @@ def upload():
dn = form.getvalue('docname')
at_id = form.getvalue('at_id')
+ webnotes.response['type'] = 'iframe'
+ if not webnotes.form['filedata'].filename:
+ webnotes.response['result'] = """
+ """ % dt
+ return
+
# save
fid, fname = save_uploaded()
- if fid:
+ # save it in the form
+ updated = add_file_list(dt, dn, fname, fid)
+
+ if fid and updated:
# refesh the form!
+ # with the new modified timestamp
webnotes.response['result'] = """
- """ % (dt, dn, fid, fname.replace("'", "\\'"), at_id, dt, dn)
+ """ % {
+ 'dt': dt,
+ 'dn': dn,
+ 'fid': fid,
+ 'fname': fname.replace("'", "\\'"),
+ 'at_id': at_id,
+ 'mod': webnotes.conn.get_value(dt, dn, 'modified')
+ }
# -------------------------------------------------------
+def add_file_list(dt, dn, fname, fid):
+ """
+ udpate file_list attribute of the record
+ """
+ import webnotes
+ try:
+ # get the old file_list
+ fl = webnotes.conn.get_value(dt, dn, 'file_list') or ''
+ if fl:
+ fl += '\n'
+
+ # add new file id
+ fl += fname + ',' + fid
+
+ # save
+ webnotes.conn.set_value(dt, dn, 'file_list', fl)
+
+ return True
+
+ except Exception, e:
+ webnotes.response['result'] = """
+""" % str(e)
+
+
+def remove_file_list(dt, dn, fid):
+ """
+ Remove fid from the give file_list
+ """
+ import webnotes
+
+ # get the old file_list
+ fl = webnotes.conn.get_value(dt, dn, 'file_list') or ''
+ new_fl = []
+ fl = fl.split('\n')
+ for f in fl:
+ if f.split(',')[1]!=fid:
+ new_fl.append(f)
+
+ # update the file_list
+ webnotes.conn.set_value(dt, dn, 'file_list', '\n'.join(new_fl))
+
+ # return the new timestamp
+ return webnotes.conn.get_value(dt, dn, 'modified')
+
def make_thumbnail(blob, size):
from PIL import Image
import cStringIO
diff --git a/cgi-bin/webnotes/utils/scheduler.py b/cgi-bin/webnotes/utils/scheduler.py
index 69f9c488e5..96db7bb5d8 100644
--- a/cgi-bin/webnotes/utils/scheduler.py
+++ b/cgi-bin/webnotes/utils/scheduler.py
@@ -138,7 +138,7 @@ class Scheduler:
# if recurring, update next_execution
if e['recurring']:
- self.conn.sql("update Event set next_execution = addtime(now(), sec_to_time(%s))", e['interval'])
+ self.conn.sql("update Event set next_execution = addtime(now(), sec_to_time(%s)) where event=%s", (e['interval'], e['event']))
# else clear
else:
diff --git a/cgi-bin/webnotes/widgets/form.py b/cgi-bin/webnotes/widgets/form.py
index fea70d61c0..7f5a325770 100644
--- a/cgi-bin/webnotes/widgets/form.py
+++ b/cgi-bin/webnotes/widgets/form.py
@@ -197,6 +197,7 @@ def runserverobj():
doclist = DocList()
doclist.from_compressed(form.getvalue('docs'), dn)
so = doclist.make_obj()
+ doclist.check_if_latest()
check_guest_access(so.doc)
@@ -288,6 +289,9 @@ def remove_attach():
fid = webnotes.form.getvalue('fid')
webnotes.utils.file_manager.delete_file(fid, verbose=1)
+
+ # remove from dt dn
+ return str(webnotes.utils.file_manager.remove_file_list(webnotes.form.getvalue('dt'), webnotes.form.getvalue('dn'), fid))
# Get Fields - Counterpart to $c_get_fields
#===========================================================================================
diff --git a/js/form.compressed.js b/js/form.compressed.js
index 32c2369634..41980e4ee4 100644
--- a/js/form.compressed.js
+++ b/js/form.compressed.js
@@ -474,7 +474,9 @@ for(var i=0;i