blob: bd9efc7385fe49067920d759d331317fb7fb878f [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
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053017import webnotes
18
19from webnotes.utils import load_json, cint, cstr
Anand Doshi82042f12012-04-06 17:54:17 +053020import json
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053021
Rushabh Mehtac7dbe292012-08-07 12:12:55 +053022@webnotes.whitelist()
23def get_questions():
24 """get list of questions"""
25 import json
26 conds = ''
27
28 if 'search_text' in webnotes.form_dict:
29 conds = ' and t1.question like "%'+ webnotes.form_dict['search_text'] + '%"'
30
31 if 'tag_filters' in webnotes.form_dict:
32 tag_filters = json.loads(webnotes.form_dict['tag_filters'])
33 for t in tag_filters:
34 conds += ' and t1._user_tags like "%'+ t +'%"'
35
36 return webnotes.conn.sql("""select t1.name, t1.owner, t1.question, t1.modified, t1._user_tags,
37 t2.first_name, t2.last_name, (select count(*) from tabAnswer where
38 tabAnswer.question = t1.name) as answers
39 from tabQuestion t1, tabProfile t2
40 where t1.docstatus!=2
41 and t1.owner = t2.name
42 %(conds)s
43 order by t1.modified desc""" % {"conds":conds}, as_dict=1)
44
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053045# add a new question
Rushabh Mehtaf17ce7b2012-02-13 16:50:52 +053046@webnotes.whitelist()
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053047def add_question(arg):
48 args = load_json(arg)
49
50 from webnotes.model.doc import Document
51 d = Document('Question')
52 d.question = args['question'].title()
53 d.points = 1
54 d.save(1)
55
56 if args['suggest']:
Anand Doshi82042f12012-04-06 17:54:17 +053057 from utilities.page.messages import messages
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053058 for s in args['suggest']:
59 if s:
Anand Doshi82042f12012-04-06 17:54:17 +053060 messages.post(json.dumps({
61 'contact': s,
62 'txt': 'Please help me and answer the question "%s" in the Knowledge Base' % d.question,
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053063 'notify': 1
Anand Doshi82042f12012-04-06 17:54:17 +053064 }))
Rushabh Mehtae3393be2011-08-30 15:37:46 +053065
Rushabh Mehtaf17ce7b2012-02-13 16:50:52 +053066@webnotes.whitelist()
Rushabh Mehtae3393be2011-08-30 15:37:46 +053067def delete(arg):
68 """
69 delete a question or answer (called from kb toolbar)
70 """
71 args = load_json(arg)
72 from webnotes.model import delete_doc
Anand Doshi82042f12012-04-06 17:54:17 +053073 delete_doc(args['dt'], args['dn'])