blob: 8e92ff9ec9462a1d3af5962ea40f331124d39923 [file] [log] [blame]
Rushabh Mehtaaaf86ba2012-02-28 17:40:13 +05301# ERPNext - web based ERP (http://erpnext.com)
2# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
Rushabh Mehtafdea9662012-02-27 18:03:54 +053017import webnotes
18
19@webnotes.whitelist()
20def get_list(arg=None):
21 """get list of messages"""
22 webnotes.form_dict['limit_start'] = int(webnotes.form_dict['limit_start'])
23 webnotes.form_dict['limit_page_length'] = int(webnotes.form_dict['limit_page_length'])
24 webnotes.form_dict['user'] = webnotes.session['user']
25
26 if webnotes.form_dict['contact'] == webnotes.session['user']:
Rushabh Mehta07a36a42012-02-27 18:17:57 +053027 # set all messages as read
28 webnotes.conn.sql("""UPDATE `tabComment Widget Record`
29 set docstatus = 1 where comment_doctype in ('My Company', 'Message')
30 and comment_docname = %s
31 """, webnotes.user.name)
32
33 # return messages
Rushabh Mehtafdea9662012-02-27 18:03:54 +053034 return webnotes.conn.sql("""select * from `tabComment Widget Record`
35 where (owner=%(contact)s or comment_docname=%(user)s)
36 and comment_doctype in ('My Company', 'Message')
37 order by creation desc
38 limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)
39 else:
40 return webnotes.conn.sql("""select * from `tabComment Widget Record`
41 where (owner=%(contact)s and comment_docname=%(user)s)
42 or (owner=%(user)s and comment_docname=%(contact)s)
43 and comment_doctype in ('My Company', 'Message')
44 order by creation desc
45 limit %(limit_start)s, %(limit_page_length)s""", webnotes.form_dict, as_dict=1)
46
47
48@webnotes.whitelist()
49def get_active_users(arg=None):
50 return webnotes.conn.sql("""select name from tabProfile
51 where enabled=1 and
52 name not in ('Administrator', 'Guest')
53 order by first_name""", as_dict=1)
54
55@webnotes.whitelist()
56def post(arg=None):
57 """post message"""
58 import json
59 arg = json.loads(arg)
60 from webnotes.model.doc import Document
61 d = Document('Comment Widget Record')
62 d.comment = arg['txt']
63 d.comment_docname = arg['contact']
64 d.comment_doctype = 'Message'
65 d.save()
Rushabh Mehtaef29e552012-02-27 18:41:11 +053066
67@webnotes.whitelist()
68def delete(arg=None):
69 webnotes.conn.sql("""delete from `tabComment Widget Record` where name=%s""",
70 webnotes.form_dict['name']);
Rushabh Mehtafdea9662012-02-27 18:03:54 +053071