Beispiel #1
0
 def post(self, urlname):
     node = Node.get(urlname=urlname)
     if not node:
         return self.redirect_next_url()
     user = self.current_user
     kwargs = self.request.arguments
     try:
         selected = kwargs.get('parent_name')
         print(selected)
     except:
         selected = [n.name for n in node.parent_nodes]
         kwargs = {
             'name': [node.name],
             'urlname': [node.urlname],
             'description': [node.description],
             'style': [node.style]
         }
     form = NodeEditForm.init(Node.get_node_choices(),
                              selected,
                              node=node,
                              **kwargs)
     if form.validate():
         node = form.save(user, node=node)
         result = {
             'status': 'success',
             'message': '节点修改成功',
             'node_url': node.url
         }
         if self.is_ajax:
             return self.write(result)
         self.flash_message(**result)
         return self.redirect(node.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("node/edit.html", form=form, node=node)
Beispiel #2
0
 def post(self, urlname):
     node = Node.get(urlname=urlname)
     if not node:
         return self.redirect_next_url()
     user = self.current_user
     kwargs = self.request.arguments
     try:
         selected = kwargs.get("parent_name")
         print(selected)
     except:
         selected = [n.name for n in node.parent_nodes]
         kwargs = {
             "name": [node.name],
             "urlname": [node.urlname],
             "description": [node.description],
             "style": [node.style],
         }
     form = NodeEditForm.init(Node.get_node_choices(), selected, node=node, **kwargs)
     if form.validate():
         node = form.save(user, node=node)
         result = {"status": "success", "message": "节点修改成功", "node_url": node.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(**result)
         return self.redirect(node.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("node/edit.html", form=form, node=node)
Beispiel #3
0
 def get(self):
     node_id = int(self.get_argument('node_id', 0))
     node = Node.get(id=node_id)
     if node:
         selected = [node.name]
     else:
         selected = []
     form = NodeForm.init(Node.get_node_choices(), selected)
     return self.render("node/create.html", form=form)
Beispiel #4
0
 def get(self):
     node_id = int(self.get_argument("node_id", 0))
     node = Node.get(id=node_id)
     if node:
         selected = [node.name]
     else:
         selected = []
     form = NodeForm.init(Node.get_node_choices(), selected)
     return self.render("node/create.html", form=form)
Beispiel #5
0
 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)
Beispiel #6
0
 def get(self, urlname):
     node = Node.get(urlname=urlname)
     if node:
         selected = [n.name for n in node.parent_nodes]
     else:
         return self.redirect_next_url()
     kwargs = {'name': [node.name], 'urlname': [node.urlname],
               'description': [node.description], 'style': [node.style]}
     form = NodeEditForm.init(Node.get_node_choices(), selected, node=node, **kwargs)
     return self.render("node/edit.html", form=form, node=node)
Beispiel #7
0
 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)
Beispiel #8
0
 def get(self, urlname):
     node = Node.get(urlname=urlname)
     if node:
         selected = [n.name for n in node.parent_nodes]
     else:
         return self.redirect_next_url()
     kwargs = {'name': [node.name], 'urlname': [node.urlname],
               'description': [node.description], 'style': [node.style]}
     form = NodeEditForm.init(Node.get_node_choices(), selected, node=node, **kwargs)
     return self.render("node/edit.html", form=form, node=node)
Beispiel #9
0
 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)
Beispiel #10
0
 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)