def config(): if not is_admin(): return redirect(url_for("bp_main.home")) pcfg = {"title": "Application Config"} _config = Config.query.one() if not _config: flash("Config not found", "error") return redirect(url_for("bp_main.home")) form = ConfigForm(request.form, obj=_config) if form.validate_on_submit(): _config.clublog_api_key = form.clublog_api_key.data _config.eqsl_download_url = form.eqsl_download_url.data _config.eqsl_rcvd_mark = form.eqsl_rcvd_mark.data _config.eqsl_upload_url = form.eqsl_upload_url.data _config.lotw_download_url = form.lotw_download_url.data _config.lotw_upload_url = form.lotw_upload_url.data _config.lotw_login_url = form.lotw_login_url.data _config.lotw_rcvd_mark = form.lotw_rcvd_mark.data db.session.commit() flash("Configuration updated", "info") return redirect(url_for("bp_admin.config")) return render_template("admin/config.jinja2", pcfg=pcfg, form=form)
def config(id=None): print id action = '/frm/config' if request.method == 'GET' and not id: # just get the new form for adding form = ConfigForm() method = 'POST' template_name = 'frm-config.html' return render_template(template_name, form=form, action=action, method=method, id=id) if request.method == 'GET' and id: # get the config conf = Config.query.get(id) form = ConfigForm() form.process(obj=conf) action += "/%s" % id method = 'POST' template_name = 'frm-config.html' return render_template(template_name, form=form, action=action, method=method, id=id) if request.method == 'POST' and not id: # new record conf = Config() form = ConfigForm(request.form) form.populate_obj(conf) db.session.add(conf) db.session.commit() return json.dumps({'status': 'OK', 'cluster': conf.dict}) if request.method == 'POST' and id: conf = Config.query.get(id) form = ConfigForm(request.form) form.populate_obj(conf) db.session.add(conf) db.session.commit() return json.dumps({'status': 'OK', 'cluster': conf.dict})
def settings(request): if request.method == 'POST': config = Config.objects.get() request.FILES['privFile'] = check_request_file('privFile', request, config.privFile) request.FILES['pubFile'] = check_request_file('pubFile', request, config.pubFile) config_form = ConfigForm(request.POST, request.FILES) if config_form.is_valid(): config_form.save() config_form = ConfigForm(instance=Config.objects.get()) messages.info(request, 'Settings saved') else: messages.info(request, 'Invalid form') else: config_form = ConfigForm(instance=Config.objects.get()) return render(request, 'settings.html', {'config_form': config_form})
def config(): config_form = ConfigForm() peer_form = BGPPeer() if config_form.validate_on_submit(): bgp_config.update(bgp_config.find_one(), {'$set': { 'local-as': int(config_form.asn.data), 'router-id': config_form.router_id.data, 'local-address': config_form.local_ip.data } }) flash('Config successfully updated.', 'success') return redirect(url_for('config', _anchor='exabgp')) if peer_form.validate_on_submit(): try: # Create the new peer new_peer = { 'ip': peer_form.ip_address.data, 'asn': int(peer_form.asn.data), 'state': 'down', 'enabled': peer_form.enabled.data } bgp_peers.insert_one(new_peer) except: flash('Error adding peer %s.' % peer_form.ip_address.data, 'warning') else: flash('Peer %s added' % peer_form.ip_address.data, 'success') return redirect(url_for('config', _anchor='peers')) else: peers = list(bgp_peers.find()) config = bgp_config.find_one() prefix_counts = {} for peer in bgp_peers.find(): prefix_counts[peer['ip']] = { 'received': len(bgp_peers.distinct('current_prefixes', {'ip': {'$eq': peer['ip']}})), 'advertised': len(adv_routes.distinct('prefix', {'peer': {'$eq': peer['ip']}})) } config_form.asn.data = config['local-as'] config_form.router_id.data = config['router-id'] config_form.local_ip.data = config['local-address'] return render_template('config.html', peers=peers, config=config, config_form=config_form, peer_form=peer_form, prefix_counts=prefix_counts)
def topics_config(): """Docstring.""" if only_check(): if request.method == 'POST': cform = ConfigForm() cform.validate_on_submit() # to get error messages to the browser # if cform.validate() is False: # flash('Please check that all the fields are valid!.', # 'critical') # return check_and_render('topics_config.html', # form=cform) # else: update_config(cform) flash('updated Config for Topic : ' + cform.topic.data) return redirect(url_for('topics')) elif request.method == 'GET': topic_name = request.args.get('topic') config = get_config(topic_name) conv_config = config_convert_to_python(config) cform = ConfigForm(topic=topic_name, **conv_config) return check_and_render('topics_config.html', form=cform) else: return check_and_render('index.html')
def config_page(): form = ConfigForm() if form.validate_on_submit(): flash('requested for user {}, {}'.format(form.ssid.data, form.email.data)) print(form.ssid.data, form.email.data, form.ip_address.data) ssid = form.ssid.data password = form.password.data if on_raspi: wifi_connect(ssid, password) sys.exit(0) return redirect('/') else: for field, error in form.errors.items(): flash( f'Troubles with field {getattr(form, field).label.text}: {" ".join(error)}' ) return render_template('config.html', title='config', form=form)
def config(): if not is_admin(): return redirect(url_for("bp_main.home")) pcfg = {"title": gettext("Application Config")} _config = Config.query.one() if not _config: flash(gettext("Config not found"), "error") return redirect(url_for("bp_main.home")) form = ConfigForm(request.form, obj=_config) if form.validate_on_submit(): _config.app_name = form.app_name.data _config.app_description = form.app_description.data db.session.commit() flash(gettext("Configuration updated"), "info") return redirect(url_for("bp_admin.config")) return render_template("admin/config.jinja2", pcfg=pcfg, form=form)
def set_config(): # return the response generated along with the specific media # type (mime type) form = ConfigForm() if request.method == 'POST': if form.validate_on_submit(): spectro_pointer_config = {} spectro_pointer_config[ 'use_raspberry'] = form.use_raspberry.data spectro_pointer_config[ 'correct_vertical_camera'] = form.correct_vertical_camera.data spectro_pointer_config[ 'correct_horizontal_camera'] = form.correct_horizontal_camera.data spectro_pointer_config[ 'center_radius'] = form.center_radius.data spectro_pointer_config[ 'show_center_circle'] = form.show_center_circle.data spectro_pointer_config['enable_photo'] = form.enable_photo.data spectro_pointer_config['enable_video'] = form.enable_video.data spectro_pointer_config[ 'record_seconds'] = form.record_seconds.data spectro_pointer_config['threshold'] = form.threshold.data spectro_pointer_config['resolution'] = form.resolution.data spectro_pointer_config['framerate'] = form.framerate.data spectro_pointer_config['sensor_mode'] = form.sensor_mode.data spectro_pointer_config[ 'shutter_speed'] = form.shutter_speed.data spectro_pointer_config['iso'] = form.iso.data with lock: set_sp_config(app, **spectro_pointer_config) update_params(app, set_camera_attr_en=True) return redirect(url_for('set_config')) else: form.use_raspberry.render_kw = { 'value': get_sp_config('USE_RASPBERRY', app) } form.correct_vertical_camera.render_kw = { 'value': get_sp_config('CORRECT_VERTICAL_CAMERA', app) } form.correct_horizontal_camera.render_kw = { 'value': get_sp_config('CORRECT_HORIZONTAL_CAMERA', app) } form.center_radius.render_kw = { 'value': get_sp_config('CENTER_RADIUS', app) } form.show_center_circle.render_kw = { 'value': get_sp_config('SHOW_CENTER_CIRCLE', app) } form.enable_photo.render_kw = { 'value': get_sp_config('ENABLE_PHOTO', app) } form.enable_video.render_kw = { 'value': get_sp_config('ENABLE_VIDEO', app) } form.record_seconds.render_kw = { 'value': get_sp_config('RECORD_SECONDS', app) } form.threshold.render_kw = { 'value': get_sp_config('THRESHOLD', app) } form.resolution.data = get_sp_config('RESOLUTION', app) form.framerate.render_kw = { 'value': get_sp_config('FRAMERATE', app) } form.sensor_mode.render_kw = { 'value': get_sp_config('SENSOR_MODE', app) } form.shutter_speed.render_kw = { 'value': get_sp_config('SHUTTER_SPEED', app) } form.iso.render_kw = {'value': get_sp_config('ISO', app)} form.use_raspberry.label = 'USE RASPBERRY:' form.correct_vertical_camera.label = 'CORRECT VERTICAL CAMERA:' form.correct_horizontal_camera.label = 'CORRECT HORIZONTAL CAMERA:' form.center_radius.label = 'CENTER RADIUS:' form.show_center_circle.label = 'SHOW CENTER CIRCLE:' form.enable_photo.label = 'ENABLE PHOTO:' form.enable_video.label = 'ENABLE VIDEO:' form.record_seconds.label = 'RECORD SECONDS:' form.threshold.label = 'THRESHOLD:' form.resolution.label = 'RESOLUTION:' form.framerate.label = 'FRAMERATE:' form.sensor_mode.label = 'SENSOR_MODE:' form.shutter_speed.label = 'SHUTTER_SPEED:' form.iso.label = 'ISO:' return render_template("config.html", form=form)
def settings(): form = ConfigForm() if request.method == 'POST': form.update_db() form.load() return render_template("settings.html", title="Alert Config", form=form)