def post_comment(): user = session.get('user_info') chat = {'author':user.get('username'), 'date':datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'message':request.values.get('message')} if len(request.values.get('message')) > 0: r_session.lpush('comments_list',json.dumps(chat)) return redirect(url_for('comments'))
def post_comment(): user = session.get('user_info') chat = { 'author': user.get('username'), 'date': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'message': request.values.get('message') } if len(request.values.get('message')) > 0: r_session.lpush('comments_list', json.dumps(chat)) return redirect(url_for('comments'))
def send_msg(username, subject, content, expire=3600 * 24 * 31, sender='Admin'): if bytes(username, 'utf-8') not in r_session.smembers('users'): return '找不到该用户。' msgs_key = 'user_messages:%s' % username msg_id = str(uuid.uuid1()) msg = dict(id=msg_id, subject=subject, content=content,sender=sender, is_read=False, time=datetime.now().strftime('%Y-%m-%d %H:%M')) msg_key = 'user_message:%s' % msg_id r_session.setex(msg_key, expire, json.dumps(msg)) r_session.lpush(msgs_key, msg_id) return '发送成功'