示例#1
0
def node():
    nodes = network_info()
    form = NodeForm()
    if request.method == "POST":
        if form.validate() == False:
            return render_template("node.html", form=form, nodes=nodes)
        else:
            name = form.name.data
            humdity = form.humdity.data
            temperature = form.temperature.data
            mode = form.mode.data
            if mode:
                protocol = "cord"
            else:
                protocol = "rott"
            eid = session['current_experiment']

            print("name: " + str(name) + " humdity: " + str(humdity) +
                  " temperature: " + str(temperature) + " mode:" + str(mode))
            node = Node(eid=eid,
                        name=name,
                        humdity=humdity,
                        temperature=temperature,
                        protocol=protocol)
            db.session.add(node)
            db.session.commit()
            return redirect(url_for("node"))
    elif request.method == "GET":
        return render_template("node.html", form=form, nodes=nodes)
示例#2
0
文件: node.py 项目: ljtyzhr/collipa
 def post(self):
     user = self.current_user
     form = NodeForm(self.request.arguments)
     if form.validate():
         node = form.save(user)
         return self.redirect(node.url)
     return self.render("node/create.html", form=form)
示例#3
0
文件: views.py 项目: ygxing/flaskbbs
def bbs_add_node():
    form = NodeForm(request.form)
    form.section.query_factory = Section.query.all

    if request.method == 'POST' and form.validate():
        section = form.data["section"]
        print section, type(section)
        if not section:
            form.section.errors.append(u"Section不存在!")
            return render_template("add_node.html", form=form)

        node = Node(section=section,
                    name=form.data["node_name"].strip(),
                    title=form.data["node_title"],
                    descp=form.data["descp"],
                    item_per_page=form.data["item_per_page"],
                    header=form.data["header"],
                    footer=form.data["footer"],
                    sidebar=form.data["sidebar"],
                    sidebar_ads=form.data["sidebar_ads"],
                    avatar_url=form.data["avatar_url"])
        node.created = datetime.now()

        section.node_count += 1
        db.session.add_all([node, section])
        db.session.commit()
        return redirect(url_for(".bbs_node",
                                node_name=urllib.quote(node.name)))

    return render_template("add_node.html", form=form)
示例#4
0
 def post(self):
     user = self.current_user
     form = NodeForm(self.request.arguments)
     if form.validate():
         node = form.save(user)
         return self.redirect(node.url)
     return self.render("node/create.html", form=form)
示例#5
0
文件: node.py 项目: KeenTurbo/collipa
 def post(self):
     if not self.has_permission:
         return
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     user = self.current_user
     form = NodeForm(self.request.arguments)
     if form.validate():
         node = form.save(user)
         return self.redirect(node.url)
     return self.render("node/create.html", form=form)
示例#6
0
 def post(self):
     if not self.has_permission:
         return
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     user = self.current_user
     form = NodeForm(self.request.arguments)
     if form.validate():
         node = form.save(user)
         return self.redirect(node.url)
     return self.render("node/create.html", form=form)
示例#7
0
def bbs_add_node():
    form = NodeForm(request.form)
    form.section.query_factory = Section.query.all

    if request.method == 'POST' and form.validate():
        section = form.data["section"]
        print section, type(section)
        if not section:
            form.section.errors.append(u"Section不存在!")
            return render_template("add_node.html", form=form)

        node = Node(section=section, name=form.data["node_name"].strip(), title=form.data["node_title"],
                    descp=form.data["descp"], item_per_page=form.data["item_per_page"], header=form.data["header"],
                    footer=form.data["footer"], sidebar=form.data["sidebar"], sidebar_ads=form.data["sidebar_ads"],
                    avatar_url=form.data["avatar_url"]
                )
        node.created = datetime.now()

        section.node_count += 1
        db.session.add_all([node, section])
        db.session.commit()
        return redirect(url_for(".bbs_node", node_name=urllib.quote(node.name)))

    return render_template("add_node.html", form=form)
示例#8
0
def addEditNode(node_id):    
    node = None
    # get choices for node leaders
    leader_choices = [(0, 'Self')]
    for x in Node.query.filter_by(leader_id=0):   # @UndefinedVariable
        leader_choices.append((x.id,x.name))
    form = NodeForm()
    form.leader.choices = leader_choices
    form.leader.default = 0    
    if node_id is not None:
        node = Node.query.get(node_id)  # @UndefinedVariable
        
    if request.method == 'GET':
        if node is None:
            form.new.data = True
        else:
            form.new.data = False
            form.id.data = node.id
            form.name.data = node.name
            form.rid.data = node.rid
            form.ip.data = node.ip
            form.location.lat.data = node.location.lat
            form.location.lon.data = node.location.lon
            form.leader.data = node.leader_id    
 
            jumppoints = []
            for jp in node.jumppoints:
                form.jumppoints.append_entry({"jp_id": jp.id, "lat": jp.location.lat, "lon":jp.location.lon })
            goals = []
            for goal in node.goals:
                form.goals.append_entry({"goal_id": goal.id, "lat": goal.location.lat, "lon":goal.location.lon })  
    elif request.method == 'POST' and form.validate():  # @UndefinedVariable
        if node is None:
            #new node has passed validation, add to db
            location = Location(lat=form.location.lat.data, lon=form.location.lon.data)
            db.session.add(location)  # @UndefinedVariable
            node = Node(name=form.name.data, leader_id=form.leader.data, location=location, rid=form.rid.data, ip=form.ip.data)
            db.session.add(node)  # @UndefinedVariable
            db.session.commit()  # @UndefinedVariable
            
            for index, point in enumerate(form.jumppoints.data):
                jp = JumpPoint()
                
                location = Location(lat=point['lat'], lon=point['lon'])
                db.session.add(location)  # @UndefinedVariable
                
                jp.location = location
                jp.position = int(point['pos']) + 1
                
                db.session.add(jp)
                node.jumppoints.append(jp)
            
            for index, point in enumerate(form.goals.data):
                goal = Goal()
                
                location = Location(lat=point['lat'], lon=point['lon'])
                db.session.add(location)  # @UndefinedVariable
                
                goal.location = location
                goal.position = int(point['pos']) + 1
                
                db.session.add(goal)
                node.goals.append(goal)
                
            db.session.commit()  # @UndefinedVariable
            flash("Node has been created")
        else: 
            #node has been updated. save updates
            node.name = form.name.data
            node.rid = form.rid.data
            node.ip = form.ip.data
            location = Location.query.get(node.loc_id)  # @UndefinedVariable
            location.lat = form.location.lat.data
            location.lon = form.location.lon.data
            node.location = location
            node.leader_id = form.leader.data

            # create a list of all points already included on this path. will be used to determine if
            # any points were deleted from the list.
            deleteList = [] 
            for jp in node.jumppoints:
                deleteList.append(jp.id)
            for index, jp in enumerate(form.jumppoints.data):
                if int(jp['jp_id']) == 0:
                    
                    newjp = JumpPoint()
                
                    location = Location(lat=jp['lat'], lon=jp['lon'])
                    db.session.add(location)  # @UndefinedVariable
                
                    newjp.location = location
                    newjp.position = int(jp['pos']) + 1            
                    db.session.add(newjp)
                    node.jumppoints.append(newjp)
                else: 
                    # found existing point. update and remove from delete list
                    savedjp = JumpPoint.query.get(jp['jp_id'])   # @UndefinedVariable
                    savedjp.position = int(jp['pos']) + 1
                    savedLoc = Location.query.get(savedjp.loc_id)   # @UndefinedVariable
                    savedLoc.lat = jp['lat']
                    savedLoc.lon = jp['lon']
            
                    deleteList.remove(int(jp['jp_id']))
                    
            for id in deleteList:
                jp= JumpPoint.query.get(id)  # @UndefinedVariable
                db.session.delete(jp)
            
            deleteList = [] 
            for goal in node.goals:
                deleteList.append(goal.id)
            for index, goal in enumerate(form.goals.data):
                if int(goal['goal_id']) == 0:
                    
                    newgoal = Goal()
                
                    location = Location(lat=goal['lat'], lon=goal['lon'])
                    db.session.add(location)  # @UndefinedVariable
                
                    newgoal.location = location
                    newgoal.position = int(goal['pos']) + 1            
                    db.session.add(newgoal)
                    node.goals.append(newgoal)
                else: 
                    # found existing point. update and remove from delete list
                    savedGoal = Goal.query.get(goal['goal_id'])   # @UndefinedVariable
                    savedGoal.position = int(goal['pos']) + 1
                    savedLoc = Location.query.get(savedGoal.loc_id)   # @UndefinedVariable
                    savedLoc.lat = goal['lat']
                    savedLoc.lon = goal['lon']
            
                    deleteList.remove(int(goal['goal_id']))
                    
            for id in deleteList:
                goal= Goal.query.get(id)  # @UndefinedVariable
                db.session.delete(goal)
            db.session.commit()                    
            flash("Node has been updated")
        
            
        # after creating the new state, redirect them back to dce config page
        return redirect(url_for("nodePage"))    
    return render_template("nodeForm.html", form=form)