blob: 5f8b209fe26d257fe48b9884508259433f20c1cf [file] [log] [blame]
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05301import webnotes
2
3from webnotes.utils import load_json, cint, cstr
4
5# add a new question
6def add_question(arg):
7 args = load_json(arg)
8
9 from webnotes.model.doc import Document
10 d = Document('Question')
11 d.question = args['question'].title()
12 d.points = 1
13 d.save(1)
14
15 if args['suggest']:
nabinhaitd9c37072011-06-17 17:09:15 +053016 from home.page.my_company.my_company import post_comment
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053017 for s in args['suggest']:
18 if s:
19 post_comment({
20 'uid': s,
21 'comment': 'Please help me and answer the question "%s" in the Knowledge Base' % d.question,
22 'notify': 1
23 })
24
25
26def vote(arg):
27 args = load_json(arg)
28
29 res = webnotes.conn.sql("select points, _users_voted from `tab%s` where name=%s" % (args['dt'], '%s'), args['dn'])[0]
30 p = cint(res[0])
31 p = args['vote']=='up' and p+1 or p-1
32
33 # update
34 webnotes.conn.sql("update `tab%s` set points=%s, _users_voted=%s where name=%s" % (args['dt'], '%s', '%s', '%s'), \
35 (p, cstr(res[1]) + ',' + webnotes.user.name, args['dn']))
36
nabinhaitd9c37072011-06-17 17:09:15 +053037 return p
Rushabh Mehtae3393be2011-08-30 15:37:46 +053038
39def delete(arg):
40 """
41 delete a question or answer (called from kb toolbar)
42 """
43 args = load_json(arg)
44 from webnotes.model import delete_doc
45 delete_doc(args['dt'], args['dn'])