From f3046abd461b59609bf6bf0f18b6407b5b5dcc12 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 20 Jan 2014 11:19:19 +0530 Subject: [PATCH] added in db.py, bulk unsubscribe optional --- webnotes/db.py | 8 ++++++++ webnotes/utils/email_lib/bulk.py | 30 ++++++++++++++++-------------- webnotes/website/js/website.js | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/webnotes/db.py b/webnotes/db.py index 98df387a41..77233dbcb0 100644 --- a/webnotes/db.py +++ b/webnotes/db.py @@ -508,6 +508,14 @@ class Database: def get_table_columns(self, doctype): return [r[0] for r in self.sql("DESC `tab%s`" % doctype)] + + def add_index(self, doctype, fields, index_name=None): + if not index_name: + index_name = "_".join(fields) + "_index" + if not webnotes.conn.sql("""show index from `tab%s` where Key_name="%s" """ % (doctype, index_name)): + webnotes.conn.commit() + webnotes.conn.sql("""alter table `tab%s` + add index %s(%s)""" % (doctype, index_name, ", ".join(fields))) def close(self): if self._conn: diff --git a/webnotes/utils/email_lib/bulk.py b/webnotes/utils/email_lib/bulk.py index 30bcf02c8c..d9eb0facdd 100644 --- a/webnotes/utils/email_lib/bulk.py +++ b/webnotes/utils/email_lib/bulk.py @@ -4,12 +4,14 @@ from __future__ import unicode_literals import webnotes from webnotes.model.doc import Document -from webnotes.utils import cint +from webnotes.utils import cint, get_url +import urllib class BulkLimitCrossedError(webnotes.ValidationError): pass def send(recipients=None, sender=None, doctype='Profile', email_field='email', - subject='[No Subject]', message='[No Content]', ref_doctype=None, ref_docname=None): + subject='[No Subject]', message='[No Content]', ref_doctype=None, ref_docname=None, + add_unsubscribe_link=True): """send bulk mail if not unsubscribed and within conf.bulk_mail_limit""" import webnotes @@ -31,18 +33,18 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email', raise_exception=BulkLimitCrossedError) def update_message(doc): - from webnotes.utils import get_url - import urllib - updated = message + """
- - Unsubscribe from this list.
""" % (get_url(), - urllib.urlencode({ - "cmd": "webnotes.utils.email_lib.bulk.unsubscribe", - "email": doc.get(email_field), - "type": doctype, - "email_field": email_field - })) + updated = message + if add_unsubscribe_link: + updated += """
+ + Unsubscribe from this list.
""" % (get_url(), + urllib.urlencode({ + "cmd": "webnotes.utils.email_lib.bulk.unsubscribe", + "email": doc.get(email_field), + "type": doctype, + "email_field": email_field + })) return updated diff --git a/webnotes/website/js/website.js b/webnotes/website/js/website.js index 1363b66fd5..57b13ca564 100644 --- a/webnotes/website/js/website.js +++ b/webnotes/website/js/website.js @@ -19,7 +19,7 @@ $.extend(wn, { require: function(url) { if(wn._assets_loaded.indexOf(url)!==-1) return; $.ajax({ - url: url + "?q=" + Math.floor(Math.random() * 1000), + url: url, //+ "?q=" + Math.floor(Math.random() * 1000), async: false, dataType: "text", success: function(data) {