def stats(): users_data = Users().select() user_data_all = [] if request.method == 'POST': res = request.form if not res['User'] or not res['Cost']: print('throwing error') print(res) else: add_expense(res['User'], 'T-mobile', res['Cost']) flash('write {0}'.format('OK')) return redirect(url_for('stats')) elif request.method == 'GET': exp_data = Expenses().select().join(Users) for row in exp_data: print(row) user_data_all.append({ "name": row.user.name, "date": row.date.strftime('%Y-%m-%d'), "cost": row.cost }) print(user_data_all) return render_template('stats.html', user_data=users_data, exp_data=user_data_all)
def _assert_add_expense(self, original_content, part_result_content, print_content=False): content = add_expense(self.userid, original_content) if print_content is True: print content self.assertNotEqual(content.find(part_result_content), -1)
def api_add_expense(): userid = request.values["userid"] notes = request.values["notes"] msg = add_expense(userid, notes) # TODO: report error content = """ { "errorcode":"200", "message":"%s" } """ % msg return content
def _response_code(msg): if msg['MsgType'] == 'voice': content = reply_voice(msg) return util._response_text_msg(msg, content) if msg['MsgType'] == 'image': content = reply_image(msg) return util._response_text_msg(msg, content) code = msg['Content'].lower().strip() if code.endswith("。"): code = code[:len("。")] if code == MSG.CODE_MUTE: return util._response_text_msg(msg, MSG.REPLY_MUTE) if code == MSG.CODE_MANUAL or code == MSG.CODE_MANUAL2 or code == MSG.CODE_MANUAL3: return util._response_text_msg(msg, MSG.REPLY_MANUAL) if code == MSG.CODE_MORE or code == MSG.CODE_MORE2: return util._response_text_msg(msg, MSG.REPLY_MANUAL_MORE) if code == MSG.CODE_MORE_MORE or code == MSG.CODE_MORE_MORE2: return util._response_text_msg(msg, MSG.REPLY_MANUAL_MORE_MORE) if code == MSG.CODE_HISTORY: userid = msg['FromUserName'] content = view_history(userid) url = "http://h.woojuu.cc/u/%s" % (userid) picurl = "" return util._response_single_picture_msg(msg, "消费历史", content, picurl, url) if code == MSG.CODE_QRCODE: return util._response_single_picture_msg( msg, "莴苣二维码", "扫扫二维码,添加莴苣微信公众号", "http://wechat.woojuu.cc/qrcode", "") if code.find(MSG.CODE_SEARCH) == 0 or code.find(MSG.CODE_SEARCH2) == 0 \ or code.find(MSG.CODE_SEARCH3) == 0: content = search_record(msg['FromUserName'], msg['Content']) return util._response_text_msg(msg, content) if code == MSG.CODE_DELETE: content = delete_last_record(msg['FromUserName']) return util._response_text_msg(msg, content) content = add_expense(msg['FromUserName'], msg['Content']) return util._response_text_msg(msg, content)
def _response_code(msg): if msg['MsgType'] == 'voice': content = reply_voice(msg) return util._response_text_msg(msg, content) if msg['MsgType'] == 'image': content = reply_image(msg) return util._response_text_msg(msg, content) code = msg['Content'].lower().strip() if code.endswith("。"): code = code[:len("。")] if code == MSG.CODE_MUTE: return util._response_text_msg(msg, MSG.REPLY_MUTE) if code == MSG.CODE_MANUAL or code == MSG.CODE_MANUAL2 or code == MSG.CODE_MANUAL3: return util._response_text_msg(msg, MSG.REPLY_MANUAL) if code == MSG.CODE_MORE or code == MSG.CODE_MORE2: return util._response_text_msg(msg, MSG.REPLY_MANUAL_MORE) if code == MSG.CODE_MORE_MORE or code == MSG.CODE_MORE_MORE2: return util._response_text_msg(msg, MSG.REPLY_MANUAL_MORE_MORE) if code == MSG.CODE_HISTORY: userid = msg['FromUserName'] content = view_history(userid) url = "http://h.woojuu.cc/u/%s" % (userid) picurl = "" return util._response_single_picture_msg(msg, "消费历史", content, picurl, url) if code == MSG.CODE_QRCODE: return util._response_single_picture_msg(msg, "莴苣二维码", "扫扫二维码,添加莴苣微信公众号", "http://wechat.woojuu.cc/qrcode", "") if code.find(MSG.CODE_SEARCH) == 0 or code.find(MSG.CODE_SEARCH2) == 0 \ or code.find(MSG.CODE_SEARCH3) == 0: content = search_record(msg['FromUserName'], msg['Content']) return util._response_text_msg(msg, content) if code == MSG.CODE_DELETE: content = delete_last_record(msg['FromUserName']) return util._response_text_msg(msg, content) content = add_expense(msg['FromUserName'], msg['Content']) return util._response_text_msg(msg, content)
def _assert_add_expense(self, original_content, part_result_content, print_content = False): content = add_expense(self.userid, original_content) if print_content is True: print content self.assertNotEqual(content.find(part_result_content), -1)