Ejemplo n.º 1
0
def get_print_style(style=None, print_format=None, for_legacy=False):
    print_settings = dataent.get_doc("Print Settings")

    if not style:
        style = print_settings.print_style or ''

    context = {
        "print_settings": print_settings,
        "print_style": style,
        "font": get_font(print_settings, print_format, for_legacy)
    }

    css = dataent.get_template("templates/styles/standard.css").render(context)

    if style and dataent.db.exists('Print Style', style):
        css = css + '\n' + dataent.db.get_value('Print Style', style, 'css')

    # move @import to top
    for at_import in list(set(re.findall("(@import url\([^\)]+\)[;]?)", css))):
        css = css.replace(at_import, "")

        # prepend css with at_import
        css = at_import + css

    if print_format and print_format.css:
        css += "\n\n" + print_format.css

    return css
Ejemplo n.º 2
0
def build_page(path):
    if not getattr(dataent.local, "path", None):
        dataent.local.path = path

    context = get_context(path)

    if context.source:
        html = dataent.render_template(context.source, context)

    elif context.template:
        if path.endswith('min.js'):
            html = dataent.get_jloader().get_source(dataent.get_jenv(),
                                                    context.template)[0]
        else:
            html = dataent.get_template(context.template).render(context)

    if '{index}' in html:
        html = html.replace('{index}', get_toc(context.route))

    if '{next}' in html:
        html = html.replace('{next}', get_next_link(context.route))

    # html = dataent.get_template(context.base_template_path).render(context)

    if can_cache(context.no_cache):
        page_cache = dataent.cache().hget("website_page", path) or {}
        page_cache[dataent.local.lang] = html
        dataent.cache().hset("website_page", path, page_cache)

    return html
Ejemplo n.º 3
0
def get_toc(route, url_prefix=None, app=None):
    '''Insert full index (table of contents) for {index} tag'''
    from dataent.website.utils import get_full_index

    full_index = get_full_index(app=app)

    return dataent.get_template("templates/includes/full_index.html").render({
        "full_index":
        full_index,
        "url_prefix":
        url_prefix or "/",
        "route":
        route.rstrip('/')
    })
Ejemplo n.º 4
0
def add_comment(args=None):
	"""
		args = {
			'comment': '',
			'comment_by': '',
			'comment_by_fullname': '',
			'reference_doctype': '',
			'reference_name': '',
			'route': '',
		}
	"""

	if not args:
		args = dataent.local.form_dict

	route = args.get("route")

	doc = dataent.get_doc(args["reference_doctype"], args["reference_name"])
	comment = doc.add_comment("Comment", args["comment"], comment_by=args["comment_by"])
	comment.flags.ignore_permissions = True
	comment.sender_full_name = args["comment_by_fullname"]
	comment.save()

	# since comments are embedded in the page, clear the web cache
	clear_cache(route)

	# notify commentors
	commentors = [d[0] for d in dataent.db.sql("""select sender from `tabCommunication`
		where
			communication_type = 'Comment' and comment_type = 'Comment'
			and reference_doctype=%s
			and reference_name=%s""", (comment.reference_doctype, comment.reference_name))]

	owner = dataent.db.get_value(doc.doctype, doc.name, "owner")
	recipients = list(set(commentors if owner=="Administrator" else (commentors + [owner])))

	message = _("{0} by {1}").format(dataent.utils.markdown(args.get("comment")), comment.sender_full_name)
	message += "<p><a href='{0}/{1}' style='font-size: 80%'>{2}</a></p>".format(dataent.utils.get_request_site_address(),
		route, _("View it in your browser"))

	from dataent.email.queue import send

	send(recipients=recipients,
		subject = _("New comment on {0} {1}").format(doc.doctype, doc.name),
		message = message,
		reference_doctype=doc.doctype, reference_name=doc.name)

	template = dataent.get_template("templates/includes/comments/comment.html")

	return template.render({"comment": comment.as_dict()})
Ejemplo n.º 5
0
def get_attach_link(doc, print_format):
    """Returns public link for the attachment via `templates/emails/print_link.html`."""
    return dataent.get_template("templates/emails/print_link.html").render({
        "url":
        get_url(),
        "doctype":
        doc.reference_doctype,
        "name":
        doc.reference_name,
        "print_format":
        print_format,
        "key":
        get_parent_doc(doc).get_signature()
    })
Ejemplo n.º 6
0
def monthly_updates():
    translators = dataent.db.sql_list("""select distinct modified_by from
		`tabTranslated Message`""")

    message = dataent.get_template(
        "/templates/emails/translator_update.md").render({"dataent": dataent})

    # refer unsubscribe against the administrator
    # document for test
    dataent.sendmail(translators,
                     "EPAAS Translator <*****@*****.**>",
                     "Montly Update",
                     message,
                     bulk=True,
                     reference_doctype="User",
                     reference_name="Administrator")
Ejemplo n.º 7
0
def get_item_for_list_in_html(context):
    # add missing absolute link in files
    # user may forget it during upload
    if (context.get("website_image") or "").startswith("files/"):
        context["website_image"] = "/" + urllib.quote(context["website_image"])

    context["show_availability_status"] = cint(
        dataent.db.get_single_value('Products Settings',
                                    'show_availability_status'))

    products_template = 'templates/includes/products_as_grid.html'
    if cint(
            dataent.db.get_single_value('Products Settings',
                                        'products_as_list')):
        products_template = 'templates/includes/products_as_list.html'

    return dataent.get_template(products_template).render(context)
Ejemplo n.º 8
0
	def send_auto_reply(self, communication, email):
		"""Send auto reply if set."""
		if self.enable_auto_reply:
			set_incoming_outgoing_accounts(communication)

			if self.send_unsubscribe_message:
				unsubscribe_message = _("Leave this conversation")
			else:
				unsubscribe_message = ""

			dataent.sendmail(recipients = [email.from_email],
				sender = self.email_id,
				reply_to = communication.incoming_email_account,
				subject = _("Re: ") + communication.subject,
				content = render_template(self.auto_reply_message or "", communication.as_dict()) or \
					 dataent.get_template("templates/emails/auto_reply.html").render(communication.as_dict()),
				reference_doctype = communication.reference_doctype,
				reference_name = communication.reference_name,
				in_reply_to = email.mail.get("Message-Id"), # send back the Message-Id as In-Reply-To
				unsubscribe_message = unsubscribe_message)
Ejemplo n.º 9
0
    def make_blog(self):
        blog_category = dataent.get_doc({
            "doctype": "Blog Category",
            "category_name": "general",
            "published": 1,
            "title": _("General")
        }).insert()

        if not self.user:
            # Admin setup
            return

        blogger = dataent.new_doc("Blogger")
        user = dataent.get_doc("User", self.user)
        blogger.user = self.user
        blogger.full_name = user.first_name + (" " + user.last_name
                                               if user.last_name else "")
        blogger.short_name = user.first_name.lower()
        blogger.avatar = user.user_image
        blogger.insert()

        dataent.get_doc({
            "doctype":
            "Blog Post",
            "title":
            "Welcome",
            "published":
            1,
            "published_on":
            nowdate(),
            "blogger":
            blogger.name,
            "blog_category":
            blog_category.name,
            "blog_intro":
            "My First Blog",
            "content":
            dataent.get_template(
                "setup/setup_wizard/data/sample_blog_post.html").render(),
        }).insert()
Ejemplo n.º 10
0
def get_formatted_html(subject, message, footer=None, print_html=None,
		email_account=None, header=None, unsubscribe_link=None, sender=None):
	if not email_account:
		email_account = get_outgoing_email_account(False, sender=sender)

	rendered_email = dataent.get_template("templates/emails/standard.html").render({
		"header": get_header(header),
		"content": message,
		"signature": get_signature(email_account),
		"footer": get_footer(email_account, footer),
		"title": subject,
		"print_html": print_html,
		"subject": subject
	})

	html = scrub_urls(rendered_email)

	if unsubscribe_link:
		html = html.replace("<!--unsubscribe link here-->", unsubscribe_link.html)

	html = inline_style_in_html(html)
	return html
Ejemplo n.º 11
0
def notify_errors(doc, doctype, party, owner, name):
    recipients = get_system_managers(only_name=True)
    dataent.sendmail(
        recipients + [dataent.db.get_value("User", owner, "email")],
        subject=_("[Urgent] Error while creating recurring %s for %s" %
                  (doctype, doc)),
        message=dataent.get_template(
            "templates/emails/recurring_document_failed.html").render({
                "type":
                _(doctype),
                "name":
                doc,
                "party":
                party or "",
                "auto_repeat":
                name
            }))
    try:
        assign_task_to_owner(name, _("Recurring Documents Failed"), recipients)
    except Exception:
        dataent.log_error(dataent.get_traceback(),
                          _("Recurring Documents Failed"))
Ejemplo n.º 12
0
    def supplier_rfq_mail(self, data, update_password_link, rfq_link):
        full_name = get_user_fullname(dataent.session['user'])
        if full_name == "Guest":
            full_name = "Administrator"

        args = {
            'update_password_link':
            update_password_link,
            'message':
            dataent.render_template(self.message_for_supplier, data.as_dict()),
            'rfq_link':
            rfq_link,
            'user_fullname':
            full_name
        }

        subject = _("Request for Quotation")
        template = "templates/emails/request_for_quotation.html"
        sender = dataent.session.user not in STANDARD_USERS and dataent.session.user or None
        message = dataent.get_template(template).render(args)
        attachments = self.get_attachments()

        self.send_email(data, sender, subject, message, attachments)