Beispiel #1
0
 def post(self, urlname):
     if not self.has_permission:
         return
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     node = Node.get(urlname=urlname)
     if not node:
         return self.redirect_next_url()
     user = self.current_user
     args = self.request.arguments
     try:
         selected = args.get('parent_name')
         print(selected)
     except:
         selected = [n.name for n in node.parent_nodes]
         args = {'name': [node.name], 'urlname': [node.urlname],
                 'description': [node.description], 'style': [node.style]}
     form = NodeEditForm.init(Node.get_node_choices(), selected, args=args,
             node=node)
     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, 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 #6
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 #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, 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()
     args = {'node_name': [selected], 'title': [topic.title], 'content':
             [topic.content]}
     form = TopicForm.init(choices=choices, selected=selected, args=args)
     return self.render("topic/create.html", form=form, node=topic.node)
Beispiel #9
0
 def get(self):
     if not self.has_permission:
         return
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     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 #10
0
 def get(self):
     if not self.has_permission:
         return
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     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 #11
0
 def get(self, topic_id):
     if not self.has_permission:
         return
     topic = Topic.get(id=topic_id)
     if topic:
         selected = topic.node.name
     else:
         return self.redirect_next_url()
     choices = Node.get_node_choices()
     args = {'node_name': [selected], 'title': [topic.title], 'content':
             [topic.content]}
     form = TopicForm.init(choices=choices, selected=selected, args=args)
     return self.render("topic/create.html", form=form, node=topic.node)
Beispiel #12
0
 def get(self, topic_id):
     if not self.has_permission:
         return
     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()
     args = {'node_name': [selected], 'title': [topic.title], 'content':
             [topic.content]}
     form = TopicForm.init(choices=choices, selected=selected, args=args)
     return self.render("topic/create.html", form=form, node=topic.node)
Beispiel #13
0
 def get(self, urlname):
     if not self.has_permission:
         return
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     node = Node.get(urlname=urlname)
     if node:
         selected = [n.name for n in node.parent_nodes]
     else:
         return self.redirect_next_url()
     args = {'name': [node.name], 'urlname': [node.urlname],
             'description': [node.description], 'style': [node.style]}
     form = NodeEditForm.init(Node.get_node_choices(), selected, args=args,
             node=node)
     return self.render("node/edit.html", form=form, node=node)
Beispiel #14
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 #15
0
 def get(self, urlname):
     if not self.has_permission:
         return
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     node = Node.get(urlname=urlname)
     if node:
         selected = [n.name for n in node.parent_nodes]
     else:
         return self.redirect_next_url()
     args = {
         'name': [node.name],
         'urlname': [node.urlname],
         'description': [node.description],
         'style': [node.style]
     }
     form = NodeEditForm.init(Node.get_node_choices(),
                              selected,
                              args=args,
                              node=node)
     return self.render("node/edit.html", form=form, node=node)