def notify_mentions(self): if self.reference_doctype and self.reference_name and self.content: mentions = extract_mentions(self.content) if not mentions: return sender_fullname = get_fullname(frappe.session.user) title = get_title(self.reference_doctype, self.reference_name) recipients = [ frappe.db.get_value( "User", { "enabled": 1, "name": name, "user_type": "System User", "allowed_in_mentions": 1 }, "email") for name in mentions ] notification_message = _('''{0} mentioned you in a comment in {1} {2}''')\ .format(frappe.bold(sender_fullname), frappe.bold(self.reference_doctype), get_title_html(title)) notification_doc = { 'type': 'Mention', 'document_type': self.reference_doctype, 'document_name': self.reference_name, 'subject': notification_message, 'from_user': frappe.session.user, 'email_content': self.content } enqueue_create_notification(recipients, notification_doc)
def get_notification_message(doc): owner_name = get_fullname(doc.owner) points = doc.points title = get_title(doc.reference_doctype, doc.reference_name) if doc.type == 'Auto': owner_name = frappe.bold('You') if points == 1: message = _('{0} gained {1} point for {2} {3}') else: message = _('{0} gained {1} points for {2} {3}') message = message.format(owner_name, frappe.bold(points), doc.rule, get_title_html(title)) elif doc.type == 'Appreciation': if points == 1: message = _('{0} appreciated your work on {1} with {2} point') else: message = _('{0} appreciated your work on {1} with {2} points') message = message.format(frappe.bold(owner_name), get_title_html(title), frappe.bold(points)) elif doc.type == 'Criticism': if points == 1: message = _('{0} criticized your work on {1} with {2} point') else: message = _('{0} criticized your work on {1} with {2} points') message = message.format(frappe.bold(owner_name), get_title_html(title), frappe.bold(points)) elif doc.type == 'Revert': if points == 1: message = _('{0} reverted your point on {1}') else: message = _('{0} reverted your points on {1}') message = message.format(frappe.bold(owner_name), get_title_html(title)) return message
def notify_assignment(assigned_by, owner, doc_type, doc_name, action='CLOSE', description=None): """ Notify assignee that there is a change in assignment """ if not (assigned_by and owner and doc_type and doc_name): return # return if self assigned or user disabled if assigned_by == owner or not frappe.db.get_value('User', owner, 'enabled'): return # Search for email address in description -- i.e. assignee user_name = frappe.get_cached_value('User', frappe.session.user, 'full_name') title = get_title(doc_type, doc_name) description_html = "<div>{0}</div>".format(description) if description else None if action == 'CLOSE': subject = _('Your assignment on {0} {1} has been removed by {2}')\ .format(frappe.bold(doc_type), get_title_html(title), frappe.bold(user_name)) else: user_name = frappe.bold(user_name) document_type = frappe.bold(doc_type) title = get_title_html(title) subject = _('{0} assigned a new task {1} {2} to you').format(user_name, document_type, title) notification_doc = { 'type': 'Assignment', 'document_type': doc_type, 'subject': subject, 'document_name': doc_name, 'from_user': frappe.session.user, 'email_content': description_html } enqueue_create_notification(owner, notification_doc)
def notify_assignment(assigned_by, owner, doc_type, doc_name, action="CLOSE", description=None): """ Notify assignee that there is a change in assignment """ if not (assigned_by and owner and doc_type and doc_name): return # return if self assigned or user disabled if assigned_by == owner or not frappe.db.get_value("User", owner, "enabled"): return # Search for email address in description -- i.e. assignee user_name = frappe.get_cached_value("User", frappe.session.user, "full_name") title = get_title(doc_type, doc_name) description_html = "<div>{0}</div>".format( description) if description else None if action == "CLOSE": subject = _( "Your assignment on {0} {1} has been removed by {2}").format( frappe.bold(doc_type), get_title_html(title), frappe.bold(user_name)) else: user_name = frappe.bold(user_name) document_type = frappe.bold(doc_type) title = get_title_html(title) subject = _("{0} assigned a new task {1} {2} to you").format( user_name, document_type, title) notification_doc = { "type": "Assignment", "document_type": doc_type, "subject": subject, "document_name": doc_name, "from_user": frappe.session.user, "email_content": description_html, } enqueue_create_notification(owner, notification_doc)
def notify_assignment(shared_by, doctype, doc_name, everyone): if not (shared_by and doctype and doc_name) or everyone: return from frappe.utils import get_fullname title = get_title(doctype, doc_name) reference_user = get_fullname(frappe.session.user) notification_message = _('{0} shared a document {1} {2} with you').format( frappe.bold(reference_user), frappe.bold(doctype), get_title_html(title)) notification_doc = { 'type': 'Share', 'document_type': doctype, 'subject': notification_message, 'document_name': doc_name, 'from_user': frappe.session.user } enqueue_create_notification(shared_by, notification_doc)
def notify_assignment(shared_by, doctype, doc_name, everyone, notify=0): if not (shared_by and doctype and doc_name) or everyone or not notify: return from frappe.utils import get_fullname title = get_title(doctype, doc_name) reference_user = get_fullname(frappe.session.user) notification_message = _("{0} shared a document {1} {2} with you").format( frappe.bold(reference_user), frappe.bold(doctype), get_title_html(title)) notification_doc = { "type": "Share", "document_type": doctype, "subject": notification_message, "document_name": doc_name, "from_user": frappe.session.user, } enqueue_create_notification(shared_by, notification_doc)
def get_notification_message(doc): owner_name = get_fullname(doc.owner) points = doc.points title = get_title(doc.reference_doctype, doc.reference_name) if doc.type == "Auto": owner_name = frappe.bold("You") if points == 1: message = _("{0} gained {1} point for {2} {3}") else: message = _("{0} gained {1} points for {2} {3}") message = message.format(owner_name, frappe.bold(points), doc.rule, get_title_html(title)) elif doc.type == "Appreciation": if points == 1: message = _("{0} appreciated your work on {1} with {2} point") else: message = _("{0} appreciated your work on {1} with {2} points") message = message.format(frappe.bold(owner_name), get_title_html(title), frappe.bold(points)) elif doc.type == "Criticism": if points == 1: message = _("{0} criticized your work on {1} with {2} point") else: message = _("{0} criticized your work on {1} with {2} points") message = message.format(frappe.bold(owner_name), get_title_html(title), frappe.bold(points)) elif doc.type == "Revert": if points == 1: message = _("{0} reverted your point on {1}") else: message = _("{0} reverted your points on {1}") message = message.format(frappe.bold(owner_name), get_title_html(title)) return message