From 8ac78c5f77725ab3433675007eb47fac208828de Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 30 Nov 2012 10:57:27 +0530 Subject: [PATCH 1/2] cleanup of notification control: now in boot --- core/doctype/communication/communication.py | 2 +- public/js/legacy/widgets/form/form.js | 7 ++++--- public/js/wn/views/communication.js | 15 +++++++++------ webnotes/model/doc.py | 14 +++++++++++--- webnotes/model/doctype.py | 1 - 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/core/doctype/communication/communication.py b/core/doctype/communication/communication.py index e2904a4bbe..cc4aca3a57 100644 --- a/core/doctype/communication/communication.py +++ b/core/doctype/communication/communication.py @@ -77,7 +77,7 @@ def send_comm_email(d, name, sent_via=None, print_html=None, attachments='[]', s d.content = sent_via.get_content(d) from webnotes.utils.email_lib.smtp import get_email - mail = get_email(d.recipients.split(","), sender=d.sender, subject=d.subject, + mail = get_email(d.recipients, sender=d.sender, subject=d.subject, msg=d.content) if send_me_a_copy: diff --git a/public/js/legacy/widgets/form/form.js b/public/js/legacy/widgets/form/form.js index 3f3b102ef5..8711f6bc0d 100644 --- a/public/js/legacy/widgets/form/form.js +++ b/public/js/legacy/widgets/form/form.js @@ -199,12 +199,13 @@ _f.Frm.prototype.print_doc = function() { } // email the form -_f.Frm.prototype.email_doc = function() { +_f.Frm.prototype.email_doc = function(message) { new wn.views.CommunicationComposer({ doc: this.doc, subject: get_doctype_label(this.meta.name) + ': ' + this.docname, recipients: this.doc.email || this.doc.email_id || this.doc.contact_email, - attach_document_print: true + attach_document_print: true, + message: message }); } @@ -1139,7 +1140,7 @@ _f.Frm.prototype.call_server = function(method, args, callback) { _f.Frm.prototype.get_files = function() { return $.map((cur_frm.doc.file_list || "").split("\n"), function(f) { - return f.split(",")[0]; + return f.split(",")[0] || null; }); } diff --git a/public/js/wn/views/communication.js b/public/js/wn/views/communication.js index cd94ed74f0..25452df041 100644 --- a/public/js/wn/views/communication.js +++ b/public/js/wn/views/communication.js @@ -29,7 +29,7 @@ wn.views.CommunicationList = Class.extend({ this.comm_list[0].find('.comm-content').toggle(true); } else { this.body.remove() - $("
No Communication with this " + $("
No Communication tagged with this " + this.doc.doctype +" yet.
").appendTo(this.wrapper); } @@ -43,7 +43,7 @@ wn.views.CommunicationList = Class.extend({
\
\ + Add Message
\ ") .appendTo(this.parent); @@ -103,7 +103,8 @@ wn.views.CommunicationComposer = Class.extend({ title: "Add Reply: " + (this.subject || ""), no_submit_on_enter: true, fields: [ - {label:"To", fieldtype:"Data", reqd: 1, fieldname:"recipients"}, + {label:"To", fieldtype:"Data", reqd: 1, fieldname:"recipients", + description:"Email addresses, separted by commas"}, {label:"Subject", fieldtype:"Data", reqd: 1}, {label:"Message", fieldtype:"Text Editor", reqd: 1, fieldname:"content"}, {label:"Add Reply", fieldtype:"Button"}, @@ -147,9 +148,9 @@ wn.views.CommunicationComposer = Class.extend({ var attach = $(fields.select_attachments.wrapper); var files = cur_frm.get_files(); - if(files) { + if(files.length) { $("

Add Attachments:

").appendTo(attach); - $.each(cur_frm.get_files(), function(i, f) { + $.each(files, function(i, f) { $(repl("

%(file)s

", {file:f})).appendTo(attach) }); @@ -205,6 +206,7 @@ wn.views.CommunicationComposer = Class.extend({ ? cur_frm.communication_view.list : []; var signature = wn.boot.profile.email_signature || ""; + if(signature.indexOf("
")==-1 && signature.indexOf(""); @@ -217,7 +219,8 @@ wn.views.CommunicationComposer = Class.extend({ +"-----In response to-----

" + comm_list[0].content); } else { - fields.content.input.set_input("

" + signature) + fields.content.input.set_input((this.message || "") + + "

" + signature) } }, setup_autosuggest: function() { diff --git a/webnotes/model/doc.py b/webnotes/model/doc.py index 7c0fbd3702..c72f587ef7 100755 --- a/webnotes/model/doc.py +++ b/webnotes/model/doc.py @@ -356,9 +356,6 @@ class Document: tmp = webnotes.conn.sql("""SELECT name FROM `tab%s` WHERE name = %s""" % (dt, '%s'), dn) return tmp and tmp[0][0] or ''# match case - - # Update query - # --------------------------------------------------------------------------- def _update_values(self, issingle, link_list, ignore_fields=0, keep_timestamps=False): if issingle: @@ -568,6 +565,17 @@ class Document: return d + def get_values(self): + """get non-null fields dict withouth standard fields""" + from webnotes.model import default_fields + ret = {} + for key in self.fields: + if key not in default_fields and self.fields[key]: + ret[key] = self.fields[key] + + return ret + + def addchild(parent, fieldname, childtype = '', local=0, doclist=None): """ diff --git a/webnotes/model/doctype.py b/webnotes/model/doctype.py index 88f44cbbbd..3443633ca3 100644 --- a/webnotes/model/doctype.py +++ b/webnotes/model/doctype.py @@ -408,7 +408,6 @@ class DocTypeDocList(webnotes.model.doclist.DocList): def get_parent_doclist(self): return webnotes.doclist([self[0]] + self.get({"parent": self[0].name})) - def rename_field(doctype, old_fieldname, new_fieldname, lookup_field=None): """this function assumes that sync is NOT performed""" import webnotes.model From 5995a910157898c23c963c5f56472a63b26b3943 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 30 Nov 2012 12:02:00 +0530 Subject: [PATCH 2/2] fixed employee permissions, fixed bug in import_merge of timestamps --- webnotes/model/sync.py | 2 +- webnotes/modules/__init__.py | 4 ++-- webnotes/modules/import_merge.py | 12 +++++++----- webnotes/widgets/reportview.py | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/webnotes/model/sync.py b/webnotes/model/sync.py index c0848e8c3e..a997844e83 100644 --- a/webnotes/model/sync.py +++ b/webnotes/model/sync.py @@ -49,7 +49,7 @@ def walk_and_sync(start_path, force=0): if doctype == 'doctype': sync(module_name, name, force) elif doctype in document_type: - if reload_doc(module_name, doctype, name): + if reload_doc(module_name, doctype, name, force): print module_name + ' | ' + doctype + ' | ' + name return modules diff --git a/webnotes/modules/__init__.py b/webnotes/modules/__init__.py index 35a33c0e30..4ac35bd161 100644 --- a/webnotes/modules/__init__.py +++ b/webnotes/modules/__init__.py @@ -68,9 +68,9 @@ def get_doc_path(module, doctype, name): dt, dn = scrub_dt_dn(doctype, name) return os.path.join(get_module_path(module), dt, dn) -def reload_doc(module, dt=None, dn=None): +def reload_doc(module, dt=None, dn=None, force=True): from webnotes.modules.import_file import import_files - return import_files(module, dt, dn, force=True) + return import_files(module, dt, dn, force) def export_doc(doctype, name, module=None): """write out a doc""" diff --git a/webnotes/modules/import_merge.py b/webnotes/modules/import_merge.py index 1fa571ec7f..307523a5c6 100644 --- a/webnotes/modules/import_merge.py +++ b/webnotes/modules/import_merge.py @@ -89,23 +89,23 @@ class UpdateDocument: if self.exists: self.delete_existing() self.save() - self.update_modified() self.run_on_update() + self.update_modified() webnotes.conn.commit() # check modified def is_modified(self): try: - timestamp = webnotes.conn.sql("select modified from `tab%s` where name=%s" % (self.doc.doctype, '%s'), self.doc.name) + timestamp = webnotes.conn.get_value(self.doc.doctype, self.doc.name, "modified") except Exception ,e: if(e.args[0]==1146): return else: raise e - + if timestamp: self.exists = 1 - if str(timestamp[0][0]) == self.doc.modified: + if str(timestamp) == self.doc.modified: self.log.append('%s %s, No change' % (self.doc.doctype, self.doc.name)) else: return 1 @@ -116,7 +116,9 @@ class UpdateDocument: # update modified timestamp def update_modified(self): - webnotes.conn.set(self.doc, 'modified', self.modified) + webnotes.conn.sql("""update `tab{doctype}` + SET modified=%s WHERE name=%s""".format(doctype=self.doc.doctype), + (self.modified, self.doc.name)) def save(self): # parent diff --git a/webnotes/widgets/reportview.py b/webnotes/widgets/reportview.py index 264c49b4b8..3583761e59 100644 --- a/webnotes/widgets/reportview.py +++ b/webnotes/widgets/reportview.py @@ -32,7 +32,7 @@ roles = [] @webnotes.whitelist() def get(arg=None): query = build_query(arg) - return compress(webnotes.conn.sql(query, as_dict=1)) + return compress(webnotes.conn.sql(query, as_dict=1, debug=1)) def build_query(arg=None): """ @@ -189,7 +189,7 @@ def build_match_conditions(data, conditions): match_conditions = [] match = True for d in doctypes[data['doctype']]: - if d.doctype == 'DocPerm': + if d.doctype == 'DocPerm' and d.parent == data['doctype']: if d.role in roles: if d.match: # role applicable for v in webnotes.user.defaults.get(d.match, ['**No Match**']): @@ -199,7 +199,7 @@ def build_match_conditions(data, conditions): # don't restrict if another read permission at level 0 # exists without a match restriction match = False - + if match_conditions and match: conditions.append('('+ ' or '.join(match_conditions) +')')