def add_connection_datastream_room(id): datastream = Datastream.query.get(id) if datastream == None: flash('Datastream not found.') abort(404) form = AddConnectionDatastreamRoomForm() form.room.choices = [(r.id, r.name) for r in datastream.feed.property.rooms] form.room.choices.insert(0,(-1,'Select...')) if form.validate_on_submit(): newConnection = Room_Datastream(datastream=datastream,room_id=form.room.data) 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('datastream', id=datastream.id)) return render_template('add_connection_datastream_room.html', datastream = datastream, form = form)
def edit_connection_datastream_room(id): connection = Room_Datastream.query.get(id) if connection == None: flash('connection not found.') abort(404) form = AddConnectionDatastreamRoomForm() form.room.choices = [(r.id, r.name) for r in connection.datastream.feed.property.rooms if r.id != connection.room.id] form.room.choices.insert(0,(connection.room.id,connection.room.name)) if form.validate_on_submit(): connection.room_id = form.room.data db.session.add(connection) db.session.commit() flash('Changes saved!') return redirect(url_for('datastream', id=connection.datastream.id)) return render_template('edit_connection_datastream_room.html', connection = connection, datastream = connection.datastream, form = form)