Пример #1
0
def get_list(arg=None):
	"""get list of messages"""
	webnotes.form_dict['limit_start'] = int(webnotes.form_dict['limit_start'])
	webnotes.form_dict['limit_page_length'] = int(webnotes.form_dict['limit_page_length'])
	webnotes.form_dict['user'] = webnotes.session['user']

	# set all messages as read
	webnotes.conn.begin()
	webnotes.conn.sql("""UPDATE `tabComment`
	set docstatus = 1 where comment_doctype in ('My Company', 'Message')
	and comment_docname = %s
	""", webnotes.user.name)
	
	delete_notification_count_for("Messages")
	
	webnotes.conn.commit()

	if webnotes.form_dict['contact'] == webnotes.session['user']:
		# return messages
		return webnotes.conn.sql("""select * from `tabComment` 
		where (owner=%(contact)s 
			or comment_docname=%(user)s 
			or (owner=comment_docname and ifnull(parenttype, "")!="Assignment"))
		and comment_doctype ='Message'
		order by creation desc
		limit %(limit_start)s, %(limit_page_length)s""", webnotes.local.form_dict, as_dict=1)		
	else:
		return webnotes.conn.sql("""select * from `tabComment` 
		where (owner=%(contact)s and comment_docname=%(user)s)
		or (owner=%(user)s and comment_docname=%(contact)s)
		or (owner=%(contact)s and comment_docname=%(contact)s)
		and comment_doctype ='Message'
		order by creation desc
		limit %(limit_start)s, %(limit_page_length)s""", webnotes.local.form_dict, as_dict=1)
Пример #2
0
def clear_cache(doctype=None):
	def clear_single(dt):
		webnotes.cache().delete_value(cache_name(dt, False))
		webnotes.cache().delete_value(cache_name(dt, True))

		if doctype_cache and (dt in doctype_cache):
			del doctype_cache[dt]

	if doctype:
		clear_single(doctype)
	
		# clear all parent doctypes
		for dt in webnotes.conn.sql("""select parent from tabDocField 
			where fieldtype="Table" and options=%s""", (doctype,)):
			clear_single(dt[0])
		
		# clear all notifications
		from webnotes.core.doctype.notification_count.notification_count import delete_notification_count_for
		delete_notification_count_for(doctype)
		
	else:
		# clear all
		for dt in webnotes.conn.sql("""select name from tabDocType"""):
			clear_single(dt[0])
Пример #3
0
def post(arg=None):
	import webnotes
	"""post message"""
	if not arg:
		arg = {}
		arg.update(webnotes.local.form_dict)
	
	if isinstance(arg, basestring):
		import json
		arg = json.loads(arg)

	from webnotes.model.doc import Document
	d = Document('Comment')
	d.parenttype = arg.get("parenttype")
	d.comment = arg['txt']
	d.comment_docname = arg['contact']
	d.comment_doctype = 'Message'
	d.save()
	
	delete_notification_count_for("Messages")

	import webnotes.utils
	if webnotes.utils.cint(arg.get('notify')):
		notify(arg)