示例#1
0
文件: views.py 项目: JrtPec/coopkot
def add_connection_room_datastream(id):
    room = Room.query.get(id)
    if room == None:
        flash('Room not found.')
        abort(404)
    form = AddConnectionRoomDatastreamForm()
    form.datastream.choices = [(d.id, (d.xively_id+": "+d.info)) for d in room.property.get_all_datastreams()]
    form.datastream.choices.insert(0,(-1,'Select...'))
    if form.validate_on_submit():
        newConnection = Room_Datastream(datastream_id=form.datastream.data,room=room)
        db.session.add(newConnection)
        db.session.commit()
        flash('New connection between datastream '+newConnection.datastream.xively_id+' and room '+newConnection.room.name+' was added.')
        return redirect(url_for('room', id=room.id))
    return render_template('add_connection_room_datastream.html',
        room = room,
        form = form)
示例#2
0
文件: views.py 项目: JrtPec/coopkot
def edit_connection_room_datastream(id):
    connection = Room_Datastream.query.get(id)
    if connection == None:
        flash('connection not found.')
        abort(404)
    form = AddConnectionRoomDatastreamForm()
    form.datastream.choices = [(d.id, (d.xively_id+": "+d.info)) for d in connection.room.property.get_all_datastreams() if d.id != connection.datastream.id]
    form.datastream.choices.insert(0,(connection.datastream.id,(connection.datastream.xively_id+": "+connection.datastream.info)))
    if form.validate_on_submit():
        connection.datastream_id = form.datastream.data
        db.session.add(connection)
        db.session.commit()
        flash('Changes saved!')
        return redirect(url_for('room', id=connection.room.id))
    return render_template('edit_connection_room_datastream.html',
        connection = connection,
        room = connection.room,
        form = form)