def PostMessage(): content = request.json MessageObj = DObject() MessageObj.title = "" MessageObj.content = content["content"] #MessageObj.timestamp = content["timestamp"] MessageObj.from_user_id = content["from_user_id"] MessageObj.to_user_id = content["to_user_id"] if InsertMessage(MessageObj): return json.dumps({"success": True}) else: return json.dumps({"success": False})
def getMessagesFromUser(): to_user_id = request.args.get('to_user_id') from_user_id = request.args.get('from_user_id') data = GetMessages(from_user_id, to_user_id) ret_messages = [] if not data: return json.dumps([]) for d in data: message = d complex_obj = DObject() complex_obj.title = message.title complex_obj.content = message.content complex_obj.timestamp = str(message.timestamp) complex_obj.from_user_id = message.from_user_id complex_obj.to_user_id = message.to_user_id ret_messages.append(complex_obj.__dict__) return json.dumps(ret_messages)