From e45ef41f2e403db83f1dccd7c7d3ac59742327ef Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 2 Aug 2011 15:53:27 +0530 Subject: [PATCH 1/8] defs fix in doctype --- cgi-bin/core/doctype/doctype/doctype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgi-bin/core/doctype/doctype/doctype.py b/cgi-bin/core/doctype/doctype/doctype.py index de8e2e1d4c..b96ec932f1 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(defs,'developer_mode', 0): From a7241e27dd05fd9ba413f34d4ebcb32df5400332 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 11 Aug 2011 12:30:42 +0530 Subject: [PATCH 2/8] use cstr instead of str in msgprint --- cgi-bin/core/doctype/sandbox/sandbox.txt | 13 ++++++++++++- cgi-bin/webnotes/__init__.py | 6 ++++-- cgi-bin/webnotes/utils/__init__.py | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) 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/utils/__init__.py b/cgi-bin/webnotes/utils/__init__.py index e770963a7c..5ee963863f 100644 --- a/cgi-bin/webnotes/utils/__init__.py +++ b/cgi-bin/webnotes/utils/__init__.py @@ -295,7 +295,7 @@ def cstr(s): s = s.encode('utf-8', 'ignore') except: pass - return str(s) + return unicode(s) def str_esc_quote(s): """ From aee16cdfdc5f8e34fba70e888a92ffd4d349507a Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 11 Aug 2011 13:27:15 +0530 Subject: [PATCH 3/8] fix for unicode, ask to use utf-8 encoding --- cgi-bin/webnotes/utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgi-bin/webnotes/utils/__init__.py b/cgi-bin/webnotes/utils/__init__.py index 5ee963863f..1f3e661515 100644 --- a/cgi-bin/webnotes/utils/__init__.py +++ b/cgi-bin/webnotes/utils/__init__.py @@ -295,7 +295,7 @@ def cstr(s): s = s.encode('utf-8', 'ignore') except: pass - return unicode(s) + return unicode(s, 'utf-8') def str_esc_quote(s): """ From 1fc02c18870ad3b1944586594f6bdc113712b378 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 11 Aug 2011 13:32:20 +0530 Subject: [PATCH 4/8] fix for unicode, ask to use utf-8 encoding --- cgi-bin/webnotes/utils/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cgi-bin/webnotes/utils/__init__.py b/cgi-bin/webnotes/utils/__init__.py index 1f3e661515..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 unicode(s, 'utf-8') + try: + return unicode(s) + except UnicodeDecodeError: + return unicode(s, 'utf-8') def str_esc_quote(s): """ From 796773bc67e173397f5d97ff8dd0ea96958b6d22 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 11 Aug 2011 13:57:42 +0530 Subject: [PATCH 5/8] fix to update_after_submit --- cgi-bin/webnotes/model/doclist.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cgi-bin/webnotes/model/doclist.py b/cgi-bin/webnotes/model/doclist.py index 6e0b816974..b6f687991d 100644 --- a/cgi-bin/webnotes/model/doclist.py +++ b/cgi-bin/webnotes/model/doclist.py @@ -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): """ @@ -240,6 +240,7 @@ class DocList: Update after submit - some values changed after submit """ self.to_docstatus = 1 + self.prepare_for_save(1) self.save_main() self.save_children() self.run_method('on_update_after_submit') From bcf64716125b28b0b5adc8a42cc0c264583d195a Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 11 Aug 2011 14:02:08 +0530 Subject: [PATCH 6/8] fix to update_after_submit --- cgi-bin/webnotes/model/doclist.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cgi-bin/webnotes/model/doclist.py b/cgi-bin/webnotes/model/doclist.py index b6f687991d..cb70bc2df5 100644 --- a/cgi-bin/webnotes/model/doclist.py +++ b/cgi-bin/webnotes/model/doclist.py @@ -239,6 +239,8 @@ 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() From a1c43e51bbc8208f30cdcf7ab024d71de4a05a82 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 11 Aug 2011 15:46:19 +0530 Subject: [PATCH 7/8] fixed attachments - now not reqd to save after attaching --- cgi-bin/webnotes/model/doclist.py | 2 +- cgi-bin/webnotes/utils/file_manager.py | 74 ++++++++++++++++++++++++-- cgi-bin/webnotes/widgets/form.py | 4 ++ js/form.compressed.js | 15 +++--- js/wn/widgets/form/attachments.js | 37 ++++++------- 5 files changed, 102 insertions(+), 30 deletions(-) diff --git a/cgi-bin/webnotes/model/doclist.py b/cgi-bin/webnotes/model/doclist.py index cb70bc2df5..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)) diff --git a/cgi-bin/webnotes/utils/file_manager.py b/cgi-bin/webnotes/utils/file_manager.py index 26575ffd5f..cccc4f9a64 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.sql("select file_list from `tab%s` where name=%s" % (dt, '%s'), dn)[0][0] 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.sql("select file_list from `tab%s` where name=%s" % (dt, '%s'), dn)[0][0] 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/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 Date: Thu, 11 Aug 2011 15:50:51 +0530 Subject: [PATCH 8/8] fixed attachments - now not reqd to save after attaching --- cgi-bin/webnotes/utils/file_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cgi-bin/webnotes/utils/file_manager.py b/cgi-bin/webnotes/utils/file_manager.py index cccc4f9a64..181403cb05 100644 --- a/cgi-bin/webnotes/utils/file_manager.py +++ b/cgi-bin/webnotes/utils/file_manager.py @@ -48,7 +48,7 @@ def add_file_list(dt, dn, fname, fid): import webnotes try: # get the old file_list - fl = webnotes.conn.sql("select file_list from `tab%s` where name=%s" % (dt, '%s'), dn)[0][0] or '' + fl = webnotes.conn.get_value(dt, dn, 'file_list') or '' if fl: fl += '\n' @@ -74,7 +74,7 @@ def remove_file_list(dt, dn, fid): import webnotes # get the old file_list - fl = webnotes.conn.sql("select file_list from `tab%s` where name=%s" % (dt, '%s'), dn)[0][0] or '' + fl = webnotes.conn.get_value(dt, dn, 'file_list') or '' new_fl = [] fl = fl.split('\n') for f in fl: