def post(self): node_id = force_int(self.get_argument('node_id', 0), 0) node = Node.get(id=node_id) user = self.current_user form = TopicForm(self.request.arguments) if form.validate(): topic = form.save(user=user) topic.put_notifier() result = {'status': 'success', 'message': '主题创建成功', 'topic_url': topic.url} if self.is_ajax: return self.write(result) self.flash_message(**result) return self.redirect(topic.url) if self.is_ajax: return self.write(form.result) return self.render("topic/create.html", form=form, node=node)
def post(self, topic_id): topic = Topic.get(id=topic_id) if not topic or (topic.author != self.current_user and not self.current_user.is_admin): return self.redirect_next_url() user = self.current_user form = TopicForm(self.request.arguments) if form.validate(): topic = form.save(user=user, topic=topic) topic.put_notifier() result = {'status': 'success', 'message': '主题修改成功', 'topic_url': topic.url} if self.is_ajax: return self.write(result) self.flash_message(**result) return self.redirect(topic.url) if self.is_ajax: return self.write(form.result) return self.render("topic/create.html", form=form, node=topic.node)
def get(self): node_id = force_int(self.get_argument('node_id', 0), 0) node = Node.get(id=node_id) if node: selected = node.name else: selected = None choices = Node.get_node_choices() form = TopicForm.init(choices=choices, selected=selected) return self.render("topic/create.html", form=form, node=node)
def get(self, topic_id): topic = Topic.get(id=topic_id) if topic and\ (topic.author == self.current_user or self.current_user.is_admin): selected = topic.node.name else: return self.redirect_next_url() choices = Node.get_node_choices() kwargs = {'node_name': [selected], 'title': [topic.title], 'content': [topic.content]} form = TopicForm.init(choices=choices, selected=selected, **kwargs) return self.render("topic/create.html", form=form, node=topic.node)