Exemple #1
0
def node_add(org_name, env_name, grp_name):
    org = g.user.organizations.filter_by(name = org_name).first()
    env = org.envs.filter_by(name = env_name).first()
    grp = env.groups.filter_by(name = grp_name).first()
    form = NodeEditForm(org, env, grp, "")
    if form.validate_on_submit():
        node = Node(name = form.name.data, grp =grp, timestamp = datetime.utcnow(), ip = form.ip.data)
        db.session.add(node)
        db.session.commit()
        flash(gettext('Your settings have been saved.'))
        return redirect(url_for('org_deploy', name = org.name))
    return render_template('node_edit.html', form = form)
Exemple #2
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)
Exemple #3
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)
Exemple #4
0
def node_edit(org_name, env_name, grp_name, node_name):
    org = g.user.organizations.filter_by(name = org_name).first()
    env = org.envs.filter_by(name = env_name).first()
    grp = env.groups.filter_by(name = grp_name).first()
    node = grp.nodes.filter_by(name = node_name).first()
    form = NodeEditForm(org, env, grp, node.name)
    if form.validate_on_submit():
        node.name = form.name.data
        node.ip = form.ip.data
        db.session.add(node)
        db.session.commit()
        flash(gettext('Your changes have been saved.'))
        return redirect(url_for('org_deploy', name = org.name))
    elif request.method != "POST":
        form.name.data = node.name
        form.ip.data = node.ip
    return render_template('node_edit.html',
        form = form)
Exemple #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)
Exemple #6
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)
Exemple #7
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)
Exemple #8
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)