def get(self): # Get the id that indicate where is the start point of new messages: current_id = int(self.request.get('id')) messages = Message.all().order('-postID').filter("postID > ", current_id) msg_set = messages.fetch(10) self.response.headers['Content-Type'] = 'text/xml' self.response.headers['Cache-Control'] = 'no-cache' # Start writing the xml content: self.response.out.write('<?xml version="1.0"?>\n') self.response.out.write(' <response>\n') self.response.out.write(' <id>%d</id>\n' % Message.max_id() ) for msg in msg_set: if not msg.isRemoved: self.response.out.write(' <message>\n') self.response.out.write(' <author>%s</author>\n' % msg.author.nickname() ) self.response.out.write(' <postID>%d</postID>\n' % msg.postID ) self.response.out.write(' <content>%s</content>\n' % msg.content ) self.response.out.write(' <rcount>%d</rcount>\n' % msg.rCount ) self.response.out.write(' <time>%s</time>\n' % msg.postDate ) self.response.out.write(' </message>\n') self.response.out.write(' </response>\n')
def post(self): message = Message() user = users.get_current_user() if user: message.author = user #Added the content to the message: message.content = cgi.escape(self.request.get('content')) #Assigned the id to the message: message.postID = Message.max_id() + 1 message.put()