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 | |
Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 17 | from __future__ import unicode_literals |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 18 | import webnotes |
| 19 | |
Anand Doshi | 0fd99e7 | 2012-11-30 16:38:04 +0530 | [diff] [blame] | 20 | from webnotes.utils import load_json |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 21 | import json |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 22 | |
Rushabh Mehta | c7dbe29 | 2012-08-07 12:12:55 +0530 | [diff] [blame] | 23 | @webnotes.whitelist() |
| 24 | def get_questions(): |
| 25 | """get list of questions""" |
| 26 | import json |
| 27 | conds = '' |
| 28 | |
| 29 | if 'search_text' in webnotes.form_dict: |
| 30 | conds = ' and t1.question like "%'+ webnotes.form_dict['search_text'] + '%"' |
| 31 | |
| 32 | if 'tag_filters' in webnotes.form_dict: |
| 33 | tag_filters = json.loads(webnotes.form_dict['tag_filters']) |
| 34 | for t in tag_filters: |
| 35 | conds += ' and t1._user_tags like "%'+ t +'%"' |
| 36 | |
| 37 | return webnotes.conn.sql("""select t1.name, t1.owner, t1.question, t1.modified, t1._user_tags, |
| 38 | t2.first_name, t2.last_name, (select count(*) from tabAnswer where |
| 39 | tabAnswer.question = t1.name) as answers |
| 40 | from tabQuestion t1, tabProfile t2 |
| 41 | where t1.docstatus!=2 |
| 42 | and t1.owner = t2.name |
| 43 | %(conds)s |
| 44 | order by t1.modified desc""" % {"conds":conds}, as_dict=1) |
| 45 | |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 46 | # add a new question |
Rushabh Mehta | f17ce7b | 2012-02-13 16:50:52 +0530 | [diff] [blame] | 47 | @webnotes.whitelist() |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 48 | def add_question(arg): |
| 49 | args = load_json(arg) |
| 50 | |
| 51 | from webnotes.model.doc import Document |
| 52 | d = Document('Question') |
Rushabh Mehta | 6252c13 | 2012-08-07 12:53:49 +0530 | [diff] [blame] | 53 | d.question = args['question'] |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 54 | d.points = 1 |
| 55 | d.save(1) |
| 56 | |
| 57 | if args['suggest']: |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 58 | from utilities.page.messages import messages |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 59 | for s in args['suggest']: |
| 60 | if s: |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 61 | messages.post(json.dumps({ |
| 62 | 'contact': s, |
| 63 | '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] | 64 | 'notify': 1 |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 65 | })) |
Rushabh Mehta | e3393be | 2011-08-30 15:37:46 +0530 | [diff] [blame] | 66 | |
Rushabh Mehta | f17ce7b | 2012-02-13 16:50:52 +0530 | [diff] [blame] | 67 | @webnotes.whitelist() |
Rushabh Mehta | e3393be | 2011-08-30 15:37:46 +0530 | [diff] [blame] | 68 | def delete(arg): |
| 69 | """ |
| 70 | delete a question or answer (called from kb toolbar) |
| 71 | """ |
| 72 | args = load_json(arg) |
| 73 | from webnotes.model import delete_doc |
Anand Doshi | 82042f1 | 2012-04-06 17:54:17 +0530 | [diff] [blame] | 74 | delete_doc(args['dt'], args['dn']) |