From fd8a99e36217929edd4f18499c6531006ed4cd06 Mon Sep 17 00:00:00 2001 From: spl0k Date: Sat, 5 Apr 2014 17:03:15 +0200 Subject: [PATCH] Converting api:chat --- api/chat.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/api/chat.py b/api/chat.py index 56fdee5..0e67b61 100644 --- a/api/chat.py +++ b/api/chat.py @@ -19,8 +19,8 @@ # along with this program. If not, see . from flask import request -from web import app -from db import ChatMessage, session +from web import app, store +from db import ChatMessage @app.route('/rest/getChatMessages.view', methods = [ 'GET', 'POST' ]) def get_chat(): @@ -30,9 +30,9 @@ def get_chat(): except: return request.error_formatter(0, 'Invalid parameter') - query = ChatMessage.query.order_by(ChatMessage.time) + query = store.find(ChatMessage).order_by(ChatMessage.time) if since: - query = query.filter(ChatMessage.time > since) + query = query.find(ChatMessage.time > since) return request.formatter({ 'chatMessages': { 'chatMessage': [ msg.responsize() for msg in query ] }}) @@ -42,7 +42,10 @@ def add_chat_message(): if not msg: return request.error_formatter(10, 'Missing message') - session.add(ChatMessage(user = request.user, message = msg)) - session.commit() + chat = ChatMessage() + chat.user_id = request.user.id + chat.message = msg + store.add(chat) + store.commit() return request.formatter({})