def parse_message(content): try: content = json.loads(content) msg = Message(type=content["type"], command=content["command"]) try: msg.status = content["status"] except KeyError: pass try: msg.body = content["body"] except KeyError: pass try: msg.hostname = content["hostname"] except KeyError: pass return msg except Exception as e: # logger.error(e) traceback.print_exc(e)
def post(self): """ Send a new message to a user. """ user = self.user if not user: return render_json(self, { 'status': 'error', 'error': 'User not logged in' }) recipient_name = cgi.escape(self.request.get('recipient')) body = cgi.escape(self.request.get('body')) recipient = UserPrefs.all()\ .filter('name =', recipient_name)\ .get() if not recipient: return render_json(self, { 'status': 'error', 'error': 'Recipient %(recipient_name)s not found' % locals() }) msg = Message() msg.user_from = user msg.user_to = recipient msg.body = body msg.put() # TODO: put this into a transaction recipient.unread_messages += 1 recipient.put() self.render_json({ 'status': 'ok' })
def post(self): """ Send a new message to a user. """ user = self.user if not user: return render_json(self, { 'status': 'error', 'error': 'User not logged in' }) recipient_name = cgi.escape(self.request.get('recipient')) body = cgi.escape(self.request.get('body')) recipient = UserPrefs.all()\ .filter('name =', recipient_name)\ .get() if not recipient: return render_json( self, { 'status': 'error', 'error': 'Recipient %(recipient_name)s not found' % locals() }) msg = Message() msg.user_from = user msg.user_to = recipient msg.body = body msg.put() # TODO: put this into a transaction recipient.unread_messages += 1 recipient.put() self.render_json({'status': 'ok'})