From ba54cf6eef9e736a8d6ca2af6fccf9543e83eea2 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 3 Aug 2012 14:14:02 +0530 Subject: [PATCH] added 'Email Send' feature in blog to send blog by mail to all subscribers --- erpnext/website/doctype/blog/blog.js | 25 +++++++++++++++++++++++++ erpnext/website/doctype/blog/blog.py | 25 +++++++++++++++++++++++++ erpnext/website/doctype/blog/blog.txt | 14 ++++++++++++-- 3 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 erpnext/website/doctype/blog/blog.js diff --git a/erpnext/website/doctype/blog/blog.js b/erpnext/website/doctype/blog/blog.js new file mode 100644 index 0000000000..b0c1ec284d --- /dev/null +++ b/erpnext/website/doctype/blog/blog.js @@ -0,0 +1,25 @@ +// ERPNext - web based ERP (http://erpnext.com) +// Copyright (C) 2012 Web Notes Technologies Pvt Ltd +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +cur_frm.cscript.refresh = function(doc) { + if(!doc.__islocal && doc.published && !doc.email_sent) { + cur_frm.add_custom_button('Email Subscribers', function() { + $c_obj(make_doclist(doc.doctype, doc.name), 'send_emails', '', function(r) { + cur_frm.refresh(); + }); + }) + } +} \ No newline at end of file diff --git a/erpnext/website/doctype/blog/blog.py b/erpnext/website/doctype/blog/blog.py index e361ece996..786941c7e1 100644 --- a/erpnext/website/doctype/blog/blog.py +++ b/erpnext/website/doctype/blog/blog.py @@ -29,6 +29,31 @@ class DocType(website.web_page.Page): super(DocType, self).__init__('Blog') self.doc, self.doclist = d, dl + def send_emails(self): + """send emails to subscribers""" + if self.doc.email_sent: + webnotes.msgprint("""Blog Subscribers already updated""", raise_exception=1) + + from webnotes.utils.email_lib.bulk import send + from markdown2 import markdown + import webnotes.utils + + # get leads that are subscribed to the blog + recipients = [e[0] for e in webnotes.conn.sql("""select distinct email_id from tabLead where + ifnull(blog_subscriber,0)=1""")] + + # make heading as link + content = '

%s

\n\n%s' % (webnotes.utils.get_request_site_address(), + self.doc.page_name, self.doc.title, markdown(self.doc.content)) + + # send the blog + send(recipients = recipients, doctype='Lead', email_field='email_id', + first_name_field = 'lead_name', last_name_field="", subject=self.doc.title, + message = markdown(content)) + + webnotes.conn.set(self.doc, 'email_sent', 1) + webnotes.msgprint("""Scheduled to send to %s subscribers""" % len(recipients)) + def on_update(self): super(DocType, self).on_update() if not webnotes.utils.cint(self.doc.published): diff --git a/erpnext/website/doctype/blog/blog.txt b/erpnext/website/doctype/blog/blog.txt index 6ed7143b2d..35d31c67d9 100644 --- a/erpnext/website/doctype/blog/blog.txt +++ b/erpnext/website/doctype/blog/blog.txt @@ -3,9 +3,9 @@ # These values are common in all dictionaries { - 'creation': '2012-07-13 13:02:27', + 'creation': '2012-07-27 19:32:53', 'docstatus': 0, - 'modified': '2012-07-27 14:15:24', + 'modified': '2012-08-03 12:18:36', 'modified_by': u'Administrator', 'owner': u'Administrator' }, @@ -113,6 +113,16 @@ 'permlevel': 1 }, + # DocField + { + 'doctype': u'DocField', + 'fieldname': u'email_sent', + 'fieldtype': u'Check', + 'hidden': 1, + 'label': u'Email Sent', + 'permlevel': 0 + }, + # DocField { 'doctype': u'DocField',