blob: a16c058ad9b814436a097c3bbee7f021c6cd93ed [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +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
Anand Doshi486f9df2012-07-19 13:40:31 +053017from __future__ import unicode_literals
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053018import webnotes
19
20from webnotes.utils import load_json, cint, cstr
Anand Doshi82042f12012-04-06 17:54:17 +053021import json
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053022
23# add a new question
Rushabh Mehtaf17ce7b2012-02-13 16:50:52 +053024@webnotes.whitelist()
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053025def add_question(arg):
26 args = load_json(arg)
27
28 from webnotes.model.doc import Document
29 d = Document('Question')
30 d.question = args['question'].title()
31 d.points = 1
32 d.save(1)
33
34 if args['suggest']:
Anand Doshi82042f12012-04-06 17:54:17 +053035 from utilities.page.messages import messages
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053036 for s in args['suggest']:
37 if s:
Anand Doshi82042f12012-04-06 17:54:17 +053038 messages.post(json.dumps({
39 'contact': s,
40 'txt': 'Please help me and answer the question "%s" in the Knowledge Base' % d.question,
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053041 'notify': 1
Anand Doshi82042f12012-04-06 17:54:17 +053042 }))
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053043
Rushabh Mehtaf17ce7b2012-02-13 16:50:52 +053044@webnotes.whitelist()
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053045def vote(arg):
46 args = load_json(arg)
47
48 res = webnotes.conn.sql("select points, _users_voted from `tab%s` where name=%s" % (args['dt'], '%s'), args['dn'])[0]
49 p = cint(res[0])
50 p = args['vote']=='up' and p+1 or p-1
51
52 # update
53 webnotes.conn.sql("update `tab%s` set points=%s, _users_voted=%s where name=%s" % (args['dt'], '%s', '%s', '%s'), \
54 (p, cstr(res[1]) + ',' + webnotes.user.name, args['dn']))
55
nabinhaitd9c37072011-06-17 17:09:15 +053056 return p
Rushabh Mehtae3393be2011-08-30 15:37:46 +053057
Rushabh Mehtaf17ce7b2012-02-13 16:50:52 +053058@webnotes.whitelist()
Rushabh Mehtae3393be2011-08-30 15:37:46 +053059def delete(arg):
60 """
61 delete a question or answer (called from kb toolbar)
62 """
63 args = load_json(arg)
64 from webnotes.model import delete_doc
Anand Doshi82042f12012-04-06 17:54:17 +053065 delete_doc(args['dt'], args['dn'])