Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | # 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 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 17 | import webnotes |
| 18 | |
| 19 | from webnotes.utils import load_json, cint, cstr |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 20 | import json |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 21 | |
| 22 | # add a new question |
Rushabh Mehta | f17ce7b | 2012-02-13 16:50:52 +0530 | [diff] [blame] | 23 | @webnotes.whitelist() |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 24 | def add_question(arg): |
| 25 | args = load_json(arg) |
| 26 | |
| 27 | from webnotes.model.doc import Document |
| 28 | d = Document('Question') |
| 29 | d.question = args['question'].title() |
| 30 | d.points = 1 |
| 31 | d.save(1) |
| 32 | |
| 33 | if args['suggest']: |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 34 | from utilities.page.messages import messages |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 35 | for s in args['suggest']: |
| 36 | if s: |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 37 | messages.post(json.dumps({ |
| 38 | 'contact': s, |
| 39 | 'txt': 'Please help me and answer the question "%s" in the Knowledge Base' % d.question, |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 40 | 'notify': 1 |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 41 | })) |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 42 | |
Rushabh Mehta | f17ce7b | 2012-02-13 16:50:52 +0530 | [diff] [blame] | 43 | @webnotes.whitelist() |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 44 | def vote(arg): |
| 45 | args = load_json(arg) |
| 46 | |
| 47 | res = webnotes.conn.sql("select points, _users_voted from `tab%s` where name=%s" % (args['dt'], '%s'), args['dn'])[0] |
| 48 | p = cint(res[0]) |
| 49 | p = args['vote']=='up' and p+1 or p-1 |
| 50 | |
| 51 | # update |
| 52 | webnotes.conn.sql("update `tab%s` set points=%s, _users_voted=%s where name=%s" % (args['dt'], '%s', '%s', '%s'), \ |
| 53 | (p, cstr(res[1]) + ',' + webnotes.user.name, args['dn'])) |
| 54 | |
nabinhait | d9c3707 | 2011-06-17 17:09:15 +0530 | [diff] [blame] | 55 | return p |
Rushabh Mehta | e3393be | 2011-08-30 15:37:46 +0530 | [diff] [blame] | 56 | |
Rushabh Mehta | f17ce7b | 2012-02-13 16:50:52 +0530 | [diff] [blame] | 57 | @webnotes.whitelist() |
Rushabh Mehta | e3393be | 2011-08-30 15:37:46 +0530 | [diff] [blame] | 58 | def delete(arg): |
| 59 | """ |
| 60 | delete a question or answer (called from kb toolbar) |
| 61 | """ |
| 62 | args = load_json(arg) |
| 63 | from webnotes.model import delete_doc |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 64 | delete_doc(args['dt'], args['dn']) |