diff --git a/public/js/wn/form/assign_to.js b/public/js/wn/form/assign_to.js index dd4816e9a6..8d6facadd0 100644 --- a/public/js/wn/form/assign_to.js +++ b/public/js/wn/form/assign_to.js @@ -136,7 +136,8 @@ wn.ui.form.AssignTo = Class.extend({ msgprint("Email sent to " + assign_to); me.render(r.message); } - } + }, + btn: this }); } } diff --git a/webnotes/db.py b/webnotes/db.py index 8e25792527..d3007a7ce3 100644 --- a/webnotes/db.py +++ b/webnotes/db.py @@ -146,14 +146,17 @@ class Database: return self._cursor.fetchall() def explain_query(self, query, values=None): - webnotes.errprint("--- query explain ---") - if values is None: - self._cursor.execute("explain " + query) - else: - self._cursor.execute("explain " + query, values) - import json - webnotes.errprint(json.dumps(self.fetch_as_dict(), indent=1)) - webnotes.errprint("--- query explain end ---") + try: + webnotes.errprint("--- query explain ---") + if values is None: + self._cursor.execute("explain " + query) + else: + self._cursor.execute("explain " + query, values) + import json + webnotes.errprint(json.dumps(self.fetch_as_dict(), indent=1)) + webnotes.errprint("--- query explain end ---") + except: + webnotes.errprint("error in query explain") def sql_list(self, query, values=(), debug=False): return [r[0] for r in self.sql(query, values, debug=debug)] @@ -336,10 +339,10 @@ class Database: return [] if as_dict: - return values + return values and [values] or [] if isinstance(fields, list): - return map(lambda d: values.get(d), fields) + return [map(lambda d: values.get(d), fields)] else: r = self.sql("""select field, value @@ -350,10 +353,7 @@ class Database: if as_dict: return r and [webnotes._dict(r)] or [] else: - if r: - return [[i[1] for i in r]] - else: - return [] + return r and [[i[1] for i in r]] or [] def get_values_from_table(self, fields, filters, doctype, as_dict, debug): fl = fields diff --git a/webnotes/model/doclist.py b/webnotes/model/doclist.py index ca42e82f8a..7bbbc54b1f 100644 --- a/webnotes/model/doclist.py +++ b/webnotes/model/doclist.py @@ -29,7 +29,8 @@ class DocList(list): def get(self, filters, limit=0): """pass filters as: {"key": "val", "key": ["!=", "val"], - "key": ["in", "val"], "key": ["not in", "val"], "key": "^val"}""" + "key": ["in", "val"], "key": ["not in", "val"], "key": "^val", + "key" : True (exists), "key": False (does not exist) }""" out = [] @@ -39,7 +40,11 @@ class DocList(list): for f in filters: fval = filters[f] - if not isinstance(fval, list): + if fval==True: + fval = ["not None", fval] + elif fval==False: + fval = ["None", fval] + elif not isinstance(fval, list): if isinstance(fval, basestring) and fval.startswith("^"): fval = ["^", fval[1:]] else: diff --git a/webnotes/model/utils.py b/webnotes/model/utils.py index d4396af83c..bc33881fc2 100644 --- a/webnotes/model/utils.py +++ b/webnotes/model/utils.py @@ -214,9 +214,7 @@ def check_if_doc_is_linked(dt, dn, method="Delete"): link_fields = get_link_fields(dt) link_fields = [[lf['parent'], lf['fieldname']] for lf in link_fields] - for l in link_fields: - link_dt, link_field = l - + for link_dt, link_field in link_fields: item = webnotes.conn.get_value(link_dt, {link_field:dn}, ["name", "parent", "parenttype", "docstatus"], as_dict=True) diff --git a/webnotes/utils/__init__.py b/webnotes/utils/__init__.py index 2a94c130a0..fa31b9c502 100644 --- a/webnotes/utils/__init__.py +++ b/webnotes/utils/__init__.py @@ -825,6 +825,8 @@ operator_map = { "<": lambda (a, b): operator.lt(a, b), ">=": lambda (a, b): operator.ge(a, b), "<=": lambda (a, b): operator.le(a, b), + "not None": lambda (a, b): a and True or False, + "None": lambda (a, b): (not a) and True or False } def compare(val1, condition, val2): diff --git a/webnotes/utils/email_lib/receive.py b/webnotes/utils/email_lib/receive.py index 3d4a448c46..320239ba5b 100644 --- a/webnotes/utils/email_lib/receive.py +++ b/webnotes/utils/email_lib/receive.py @@ -21,6 +21,7 @@ # from __future__ import unicode_literals +import webnotes from webnotes.utils import extract_email_id, convert_utc_to_user_timezone class IncomingMail: @@ -31,7 +32,6 @@ class IncomingMail: import email import email.utils import datetime - import time self.mail = email.message_from_string(content) diff --git a/webnotes/utils/scheduler.py b/webnotes/utils/scheduler.py index eeeff28d24..7a00334692 100644 --- a/webnotes/utils/scheduler.py +++ b/webnotes/utils/scheduler.py @@ -52,14 +52,19 @@ def execute(): out = [] - # if first task of the day execute daily tasks nowtime = webnotes.utils.now_datetime() last = webnotes.conn.get_global('scheduler_last_event') + + # set scheduler last event + webnotes.conn.begin() + webnotes.conn.set_global('scheduler_last_event', nowtime.strftime(format)) + webnotes.conn.commit() + if last: last = datetime.strptime(last, format) if nowtime.day != last.day: - + # if first task of the day execute daily tasks out.append('daily:' + trigger('execute_daily')) if nowtime.month != last.month: @@ -73,10 +78,6 @@ def execute(): out.append('all:' + trigger('execute_all')) - webnotes.conn.begin() - webnotes.conn.set_global('scheduler_last_event', nowtime.strftime(format)) - webnotes.conn.commit() - return '\n'.join(out) def trigger(method): @@ -90,12 +91,16 @@ def trigger(method): webnotes.conn.commit() return 'ok' - except Exception, e: + except Exception: return log(method) def log(method): """log error in patch_log""" import webnotes + + if not (webnotes.conn and webnotes.conn._conn): + webnotes.connect() + webnotes.conn.rollback() traceback = webnotes.getTraceback() diff --git a/webnotes/webutils.py b/webnotes/webutils.py index 2e50f1f990..41daa64bc8 100644 --- a/webnotes/webutils.py +++ b/webnotes/webutils.py @@ -28,7 +28,7 @@ def get_html(page_name): # load from cache, if auto cache clear is falsy if not (hasattr(conf, 'auto_cache_clear') and conf.auto_cache_clear or 0): - if not get_page_settings().get("page_name", {}).get("no_cache", None): + if not get_page_settings().get(page_name, {}).get("no_cache"): html = webnotes.cache().get_value("page:" + page_name) from_cache = True diff --git a/webnotes/widgets/form/assign_to.py b/webnotes/widgets/form/assign_to.py index 0f67174a54..227d966ab3 100644 --- a/webnotes/widgets/form/assign_to.py +++ b/webnotes/widgets/form/assign_to.py @@ -66,7 +66,7 @@ def add(args=None): # notify if not args.get("no_notification"): - notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', notify=args.get('notify')) + notify_assignment(d.assigned_by, d.owner, d.reference_type, d.reference_name, action='ASSIGN', description=args.get("description"), notify=args.get('notify')) # update feeed try: @@ -106,7 +106,8 @@ def clear(doctype, name): where reference_type=%(doctype)s and reference_name=%(name)s""", locals()): remove(doctype, name, assign_to) -def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', notify=0): +def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', + description=None, notify=0): """ Notify assignee that there is a change in assignment """ @@ -143,9 +144,10 @@ def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', no else: arg = { 'contact': owner, - 'txt': "A new task, %s, has been assigned to you by %s." \ + 'txt': "A new task, %s, has been assigned to you by %s. %s" \ % (assignment, - user_info.get(webnotes.session.get('user'), {}).get('fullname')), + user_info.get(webnotes.session.get('user'), {}).get('fullname'), + description and ("

Description: " + description + "

") or ""), 'notify': notify }