2012-02-23 07:05:32 +00:00
|
|
|
# ERPNext - web based ERP (http://erpnext.com)
|
|
|
|
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2012-07-19 08:10:31 +00:00
|
|
|
from __future__ import unicode_literals
|
2011-06-08 09:07:15 +00:00
|
|
|
import webnotes
|
|
|
|
|
2012-11-30 11:08:04 +00:00
|
|
|
from webnotes.utils import load_json
|
2012-04-06 12:24:17 +00:00
|
|
|
import json
|
2011-06-08 09:07:15 +00:00
|
|
|
|
2012-08-07 06:42:55 +00:00
|
|
|
@webnotes.whitelist()
|
|
|
|
def get_questions():
|
|
|
|
"""get list of questions"""
|
|
|
|
import json
|
|
|
|
conds = ''
|
|
|
|
|
|
|
|
if 'search_text' in webnotes.form_dict:
|
|
|
|
conds = ' and t1.question like "%'+ webnotes.form_dict['search_text'] + '%"'
|
|
|
|
|
|
|
|
if 'tag_filters' in webnotes.form_dict:
|
|
|
|
tag_filters = json.loads(webnotes.form_dict['tag_filters'])
|
|
|
|
for t in tag_filters:
|
|
|
|
conds += ' and t1._user_tags like "%'+ t +'%"'
|
|
|
|
|
|
|
|
return webnotes.conn.sql("""select t1.name, t1.owner, t1.question, t1.modified, t1._user_tags,
|
2012-12-18 09:17:54 +00:00
|
|
|
(select count(*) from tabAnswer where
|
2012-08-07 06:42:55 +00:00
|
|
|
tabAnswer.question = t1.name) as answers
|
|
|
|
from tabQuestion t1, tabProfile t2
|
|
|
|
where t1.docstatus!=2
|
|
|
|
and t1.owner = t2.name
|
|
|
|
%(conds)s
|
|
|
|
order by t1.modified desc""" % {"conds":conds}, as_dict=1)
|
|
|
|
|
2011-06-08 09:07:15 +00:00
|
|
|
# add a new question
|
2012-02-13 11:20:52 +00:00
|
|
|
@webnotes.whitelist()
|
2011-06-08 09:07:15 +00:00
|
|
|
def add_question(arg):
|
|
|
|
args = load_json(arg)
|
|
|
|
|
|
|
|
from webnotes.model.doc import Document
|
|
|
|
d = Document('Question')
|
2012-08-07 07:23:49 +00:00
|
|
|
d.question = args['question']
|
2011-06-08 09:07:15 +00:00
|
|
|
d.points = 1
|
|
|
|
d.save(1)
|
|
|
|
|
|
|
|
if args['suggest']:
|
2013-04-04 04:32:08 +00:00
|
|
|
from core.page.messages import messages
|
2011-06-08 09:07:15 +00:00
|
|
|
for s in args['suggest']:
|
|
|
|
if s:
|
2012-04-06 12:24:17 +00:00
|
|
|
messages.post(json.dumps({
|
|
|
|
'contact': s,
|
|
|
|
'txt': 'Please help me and answer the question "%s" in the Knowledge Base' % d.question,
|
2011-06-08 09:07:15 +00:00
|
|
|
'notify': 1
|
2012-04-06 12:24:17 +00:00
|
|
|
}))
|
2011-08-30 10:07:46 +00:00
|
|
|
|
2012-02-13 11:20:52 +00:00
|
|
|
@webnotes.whitelist()
|
2011-08-30 10:07:46 +00:00
|
|
|
def delete(arg):
|
|
|
|
"""
|
|
|
|
delete a question or answer (called from kb toolbar)
|
|
|
|
"""
|
|
|
|
args = load_json(arg)
|
|
|
|
from webnotes.model import delete_doc
|
2012-04-06 12:24:17 +00:00
|
|
|
delete_doc(args['dt'], args['dn'])
|