Example #1
0
def execute():
	for page in frappe.db.sql("""select * from `tabWeb Page`""", as_dict=1):
		# get parents
		
		route = frappe.db.get_value("Website Route", {"ref_doctype":"Web Page", "docname": page.name},
			["name", "lft", "rgt"], as_dict=1)
			
		if route and page.parent_website_route:
			path = frappe.get_app_path("frappe_io", "templates", "statics", 
				*page.parent_website_route.split("/"))
				
			print path
			if not os.path.exists(path):
				os.makedirs(path)

			index_txt_path = os.path.join(path, "index.txt")
			if not os.path.exists(index_txt_path):
				with open(index_txt_path, "w") as f:
					f.write("\n".join(frappe.db.sql_list("""select name from `tabWeb Page` 
						where parent_website_route=%s order by idx""", page.parent_website_route)))

			index_md = os.path.join(path, "index.md")
			if not os.path.exists(index_md):
				with open(index_md, "w") as f:
					f.write("")
				
			page_name = route.name.split("/")[-1]
			with open(os.path.join(path, page_name + ".md"), "w") as mdfile:
				mdfile.write(html2text(page.main_section or "").encode("utf-8"))
Example #2
0
 def set_html_as_text(self, html):
     """return html2text"""
     import HTMLParser
     from frappe.utils.email_lib.html2text import html2text
     try:
         self.set_text(html2text(html))
     except HTMLParser.HTMLParseError:
         pass
Example #3
0
	def set_html_as_text(self, html):
		"""return html2text"""
		import HTMLParser
		from frappe.utils.email_lib.html2text import html2text
		try:
			self.set_text(html2text(html))
		except HTMLParser.HTMLParseError:
			pass
Example #4
0
def send(recipients=None, sender=None, doctype='User', email_field='email',
		subject='[No Subject]', message='[No Content]', ref_doctype=None, ref_docname=None,
		add_unsubscribe_link=True):
	def is_unsubscribed(rdata):
		if not rdata:
			return 1
		return cint(rdata.unsubscribed)

	def check_bulk_limit(new_mails):
		this_month = frappe.db.sql("""select count(*) from `tabBulk Email` where
			month(creation)=month(%s)""" % nowdate())[0][0]

		monthly_bulk_mail_limit = frappe.conf.get('monthly_bulk_mail_limit') or 500

		if this_month + len(recipients) > monthly_bulk_mail_limit:
			throw(_("Bulk email limit {0} crossed").format(monthly_bulk_mail_limit),
				BulkLimitCrossedError)

	def update_message(formatted, doc, add_unsubscribe_link):
		updated = formatted
		if add_unsubscribe_link:
			unsubscribe_link = """<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": "frappe.utils.email_lib.bulk.unsubscribe",
					"email": doc.get(email_field),
					"type": doctype,
					"email_field": email_field
				}))

			updated = updated.replace("<!--unsubscribe link here-->", unsubscribe_link)

		return updated

	if not recipients: recipients = []
	if not sender or sender == "Administrator":
		sender = frappe.db.get_value('Outgoing Email Settings', None, 'auto_email_id')
	check_bulk_limit(len(recipients))

	formatted = get_formatted_html(subject, message)

	for r in filter(None, list(set(recipients))):
		rdata = frappe.db.sql("""select * from `tab%s` where %s=%s""" % (doctype,
			email_field, '%s'), (r,), as_dict=1)

		doc = rdata and rdata[0] or {}

		if not is_unsubscribed(doc):
			# add to queue
			updated = update_message(formatted, doc, add_unsubscribe_link)
			try:
				text_content = html2text(updated)
			except HTMLParser.HTMLParseError:
				text_content = "[See html attachment]"

			add(r, sender, subject, updated, text_content, ref_doctype, ref_docname)
def execute():
	frappe.reload_doc("aapkamanch", "doctype", "post")
	
	frappe.conn.sql("""update `tabPost` set status='Open' where status='Assigned'""")
	frappe.conn.sql("""update `tabPost` set status='Closed' where status='Completed'""")
	
	for name, content in frappe.conn.sql("""select name, content from `tabPost`"""):
		# extract text, strip and remove new lines and spaces
		title = html2text(content)
		title = title.strip().replace("\n", " ").replace("  ", " ")
		title = title[:100] + ("..." if len(title) > 100 else "")
		frappe.conn.set_value("Post", name, "title", title)
Example #6
0
def send(recipients=None,
         sender=None,
         doctype='Profile',
         email_field='email',
         subject='[No Subject]',
         message='[No Content]',
         ref_doctype=None,
         ref_docname=None,
         add_unsubscribe_link=True):
    def is_unsubscribed(rdata):
        if not rdata:
            return 1
        return cint(rdata.unsubscribed)

    def check_bulk_limit(new_mails):
        this_month = frappe.db.sql(
            """select count(*) from `tabBulk Email` where
			month(creation)=month(%s)""" % nowdate())[0][0]

        monthly_bulk_mail_limit = frappe.conf.get(
            'monthly_bulk_mail_limit') or 500

        if this_month + len(recipients) > monthly_bulk_mail_limit:
            throw("{bulk} ({limit}) {cross}".format(
                **{
                    "bulk": _("Monthly Bulk Mail Limit"),
                    "limit": monthly_bulk_mail_limit,
                    "cross": _("crossed")
                }),
                  exc=BulkLimitCrossedError)

    def update_message(formatted, doc, add_unsubscribe_link):
        updated = formatted
        if add_unsubscribe_link:
            unsubscribe_link = """<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": "frappe.utils.email_lib.bulk.unsubscribe",
                    "email": doc.get(email_field),
                    "type": doctype,
                    "email_field": email_field
                }))

            updated = updated.replace("<!--unsubscribe link here-->",
                                      unsubscribe_link)

        return updated

    if not recipients: recipients = []
    if not sender or sender == "Administrator":
        sender = frappe.db.get_value('Email Settings', None, 'auto_email_id')
    check_bulk_limit(len(recipients))

    formatted = get_formatted_html(subject, message)

    for r in filter(None, list(set(recipients))):
        rdata = frappe.db.sql("""select * from `tab%s` where %s=%s""" %
                              (doctype, email_field, '%s'), (r, ),
                              as_dict=1)

        doc = rdata and rdata[0] or {}

        if not is_unsubscribed(doc):
            # add to queue
            updated = update_message(formatted, doc, add_unsubscribe_link)
            try:
                text_content = html2text(updated)
            except HTMLParser.HTMLParseError:
                text_content = "[See html attachment]"

            add(r, sender, subject, updated, text_content, ref_doctype,
                ref_docname)