blob: 0adeb8da9855113099666fd6e0dafc547d326ea7 [file] [log] [blame]
Rushabh Mehtafdea9662012-02-27 18:03:54 +05301import webnotes
2
3@webnotes.whitelist()
4def get_list(arg=None):
5 """get list of messages"""
6 webnotes.form_dict['limit_start'] = int(webnotes.form_dict['limit_start'])
7 webnotes.form_dict['limit_page_length'] = int(webnotes.form_dict['limit_page_length'])
8 webnotes.form_dict['user'] = webnotes.session['user']
9
10 if webnotes.form_dict['contact'] == webnotes.session['user']:
11 return webnotes.conn.sql("""select * from `tabComment Widget Record`
12 where (owner=%(contact)s or comment_docname=%(user)s)
13 and comment_doctype in ('My Company', 'Message')
14 order by creation desc
15 limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)
16 else:
17 return webnotes.conn.sql("""select * from `tabComment Widget Record`
18 where (owner=%(contact)s and comment_docname=%(user)s)
19 or (owner=%(user)s and comment_docname=%(contact)s)
20 and comment_doctype in ('My Company', 'Message')
21 order by creation desc
22 limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)
23
24
25@webnotes.whitelist()
26def get_active_users(arg=None):
27 return webnotes.conn.sql("""select name from tabProfile
28 where enabled=1 and
29 name not in ('Administrator', 'Guest')
30 order by first_name""", as_dict=1)
31
32@webnotes.whitelist()
33def post(arg=None):
34 """post message"""
35 import json
36 arg = json.loads(arg)
37 from webnotes.model.doc import Document
38 d = Document('Comment Widget Record')
39 d.comment = arg['txt']
40 d.comment_docname = arg['contact']
41 d.comment_doctype = 'Message'
42 d.save()
43