def post(self, conv_id=None, msg_id=None): if not self.form.validate(): return self.show_form_for_new_message() # Adds a new message to conversation if conv_id and msg_id and conv_id.isdigit() and msg_id.isdigit(): msg = Conversation.add_new_message(self.form.sender.data, self.form.content.data, conv_id=conv_id) self.notify_user(self.form.sender.data, conv_id, msg) # new conversation: adds a new conversation with first message elif self.form.receiver.data and self.form.title.data and self.form.content.data: data = [self.form.data.get(i) for i in ('sender', 'receiver', 'title', 'content')] (conv, msg) = User.add_new_conversation(*data) self.notify_user(self.form.sender.data, conv.key.id(), msg) else: self.response.out.write("Error in Messages.post()") self.redirect(self.request.referer)