Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 1 | import webnotes |
| 2 | |
| 3 | from webnotes.utils import load_json, cint, cstr |
| 4 | |
| 5 | # add a new question |
| 6 | def 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']: |
nabinhait | d9c3707 | 2011-06-17 17:09:15 +0530 | [diff] [blame] | 16 | from home.page.my_company.my_company import post_comment |
Pratik Vyas | c1e6e4c | 2011-06-08 14:37:15 +0530 | [diff] [blame] | 17 | 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 | |
| 26 | def 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 | |
nabinhait | d9c3707 | 2011-06-17 17:09:15 +0530 | [diff] [blame] | 37 | return p |