Browse Source

added in db.py, bulk unsubscribe optional

version-14
Rushabh Mehta 11 years ago
parent
commit
f3046abd46
3 changed files with 25 additions and 15 deletions
  1. +8
    -0
      webnotes/db.py
  2. +16
    -14
      webnotes/utils/email_lib/bulk.py
  3. +1
    -1
      webnotes/website/js/website.js

+ 8
- 0
webnotes/db.py View File

@@ -508,6 +508,14 @@ class Database:
def get_table_columns(self, doctype): def get_table_columns(self, doctype):
return [r[0] for r in self.sql("DESC `tab%s`" % 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): def close(self):
if self._conn: if self._conn:


+ 16
- 14
webnotes/utils/email_lib/bulk.py View File

@@ -4,12 +4,14 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.model.doc import Document 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 class BulkLimitCrossedError(webnotes.ValidationError): pass


def send(recipients=None, sender=None, doctype='Profile', email_field='email', 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""" """send bulk mail if not unsubscribed and within conf.bulk_mail_limit"""
import webnotes import webnotes
@@ -31,18 +33,18 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email',
raise_exception=BulkLimitCrossedError) raise_exception=BulkLimitCrossedError)


def update_message(doc): def update_message(doc):
from webnotes.utils import get_url
import urllib
updated = message + """<div style="padding: 7px; border-top: 1px solid #aaa;
margin-top: 17px;">
<small><a href="%s/?%s">
Unsubscribe</a> from this list.</small></div>""" % (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 += """<div style="padding: 7px; border-top: 1px solid #aaa;
margin-top: 17px;">
<small><a href="%s/?%s">
Unsubscribe</a> from this list.</small></div>""" % (get_url(),
urllib.urlencode({
"cmd": "webnotes.utils.email_lib.bulk.unsubscribe",
"email": doc.get(email_field),
"type": doctype,
"email_field": email_field
}))
return updated return updated


+ 1
- 1
webnotes/website/js/website.js View File

@@ -19,7 +19,7 @@ $.extend(wn, {
require: function(url) { require: function(url) {
if(wn._assets_loaded.indexOf(url)!==-1) return; if(wn._assets_loaded.indexOf(url)!==-1) return;
$.ajax({ $.ajax({
url: url + "?q=" + Math.floor(Math.random() * 1000),
url: url, //+ "?q=" + Math.floor(Math.random() * 1000),
async: false, async: false,
dataType: "text", dataType: "text",
success: function(data) { success: function(data) {


Loading…
Cancel
Save