for message in pubsub.listen(): if message['type'] == 'message': yield 'data:%s\n\n' % message['data'] except ConnectionError: while True: print('lost connection; trying to reconnect...') try: redis.ping() except ConnectionError: time.sleep(10) else: pubsub.subscribe(channels) break @bp.route('/broadcast', methods=[ 'GET', 'POST' ]) @register_menu(bp, '.broadcast', 'Broadcast', visible_when=has_role('super-admin'), order=5) def broadcast(): form = BroadcastForm(flask.request.form) if form.validate_on_submit(): redis.publish('notifications', form.message.data) flask.flash('Message published') return flask.redirect(flask.url_for('.broadcast')) return flask.render_template('broadcast.html', form=form) @bp.route('/push') def push(): return flask.Response(event_stream(), mimetype='text/event-stream')
def push_is_visible(): return flask.current_app.config.get('PUSH_ENABLED') and has_role('super-admin')
redis.publish('notifications', form.message.data) flask.flash('Message published') return flask.redirect(flask.url_for('.broadcast')) return flask.render_template('broadcast.html', form=form) @bp.route('/push') @login_required @roles_required('super-admin') def push(): return flask.Response(event_stream(), mimetype='text/event-stream') @bp.route('/networks') @login_required @roles_required('super-admin') @register_menu(bp, '.networks', 'Networks', visible_when=has_role('super-admin'), order=10) def networks_index(): return flask.render_template('networks/index.html') @bp.route('/networks/new', methods=[ 'GET', 'POST' ]) @login_required @roles_required('super-admin') def networks_new(): network = Network() form = NetworkForm(flask.request.form, network) if form.validate_on_submit(): form.populate_obj(network) db.session.add(network) db.session.commit()
def push_is_visible(): return flask.current_app.config.get('PUSH_ENABLED') and has_role( 'super-admin')
return flask.render_template('broadcast.html', form=form) @bp.route('/push') @login_required @roles_required('super-admin') def push(): return flask.Response(event_stream(), mimetype='text/event-stream') @bp.route('/networks') @login_required @roles_required('super-admin') @register_menu(bp, '.networks', 'Networks', visible_when=has_role('super-admin'), order=10) def networks_index(): return flask.render_template('networks/index.html') @bp.route('/networks/new', methods=['GET', 'POST']) @login_required @roles_required('super-admin') def networks_new(): network = Network() form = NetworkForm(flask.request.form, network) if form.validate_on_submit(): form.populate_obj(network) db.session.add(network)