def answer(self, req): card = self.card if req.user and req.user.id == card.id and req.get_method() == 'POST': text = req.get_form_var("update_text", '').strip() upload_file = req.get_form_var("update_file", None) question_id = req.get_form_var("question_id", None) filename = '' ftype = '' if upload_file: filename = upload_file.tmp_filename ftype = upload_file.content_type if (text or filename) and question_id: Answer.new(question_id, req.user.id, text, filename=filename, ftype=ftype) return req.redirect(card.path)