Esempio n. 1
0
def _get_communications(doctype, name, start=0, limit=20):
	match_conditions = get_feed_match_conditions()
	communications = frappe.db.sql("""select name, communication_type,
			communication_medium, comment_type,
			content, sender, sender_full_name, creation, subject, delivery_status, _liked_by,
			timeline_doctype, timeline_name,
			reference_doctype, reference_name,
			"Communication" as doctype
		from tabCommunication
		where
			communication_type in ("Communication", "Comment")
			and (
				(reference_doctype=%(doctype)s and reference_name=%(name)s)
				or (timeline_doctype=%(doctype)s and timeline_name=%(name)s)
			)
			and (comment_type is null or comment_type != 'Update')
			{match_conditions}
		order by creation desc limit %(start)s, %(limit)s"""
			.format(match_conditions=("and " + match_conditions) if match_conditions else ""),
			{ "doctype": doctype, "name": name, "start": frappe.utils.cint(start), "limit": limit },
			as_dict=True)

	for c in communications:
		if c.communication_type=="Communication":
			c.attachments = json.dumps(frappe.get_all("File",
				fields=["file_url", "is_private"],
				filters={"attached_to_doctype": "Communication",
					"attached_to_name": c.name}
				))

	return communications
Esempio n. 2
0
def get_feed(limit_start, limit_page_length, show_likes=False):
	"""get feed"""
	match_conditions = get_feed_match_conditions(frappe.session.user)

	result = frappe.db.sql("""select name, owner, modified, creation, seen, comment_type,
			reference_doctype, reference_name, link_doctype, link_name, subject,
			communication_type, communication_medium, content
		from `tabCommunication`
		where
			communication_type in ("Communication", "Comment")
			and (comment_type is null or comment_type != "Like"
				or (comment_type="Like" and (owner=%(user)s or reference_owner=%(user)s)))
			{match_conditions}
			{show_likes}
		order by creation desc
		limit %(limit_start)s, %(limit_page_length)s"""
		.format(match_conditions="and {0}".format(match_conditions) if match_conditions else "",
			show_likes="and comment_type='Like'" if show_likes else ""),
		{
			"user": frappe.session.user,
			"limit_start": cint(limit_start),
			"limit_page_length": cint(limit_page_length)
		}, as_dict=True)

	if show_likes:
		# mark likes as seen!
		frappe.db.sql("""update `tabCommunication` set seen=1
			where comment_type='Like' and reference_owner=%s""", frappe.session.user)
		frappe.local.flags.commit = True

	return result
Esempio n. 3
0
def _get_communications(doctype, name, start=0, limit=20):
    match_conditions = get_feed_match_conditions()
    communications = frappe.db.sql("""select name, communication_type,
			communication_medium, comment_type,
			content, sender, sender_full_name, creation, subject, delivery_status, _liked_by,
			timeline_doctype, timeline_name,
			reference_doctype, reference_name,
			link_doctype, link_name,
			"Communication" as doctype
		from tabCommunication
		where
			communication_type in ("Communication", "Comment")
			and (
				(reference_doctype=%(doctype)s and reference_name=%(name)s)
				or (timeline_doctype=%(doctype)s and timeline_name=%(name)s)
			)
			and (comment_type is null or comment_type != 'Update')
			{match_conditions}
		order by creation desc limit %(start)s, %(limit)s""".format(
        match_conditions=("and " +
                          match_conditions) if match_conditions else ""), {
                              "doctype": doctype,
                              "name": name,
                              "start": frappe.utils.cint(start),
                              "limit": limit
                          },
                                   as_dict=True)

    for c in communications:
        if c.communication_type == "Communication":
            c.attachments = json.dumps(
                frappe.get_all("File",
                               fields=["file_url", "is_private"],
                               filters={
                                   "attached_to_doctype": "Communication",
                                   "attached_to_name": c.name
                               }))

        elif c.communication_type == "Comment" and c.comment_type == "Comment":
            c.content = frappe.utils.markdown(c.content)

    return communications