def config(): if g.user is not None and g.user.is_authenticated(): return redirect(url_for('index')) form = ConfigForm(request.form) if request.method == 'POST' and form.validate(): config = ConfigData(form.bucket.data, form.region.data,form.s3key.data, form.s3user.data, form.avldb.data,form.avluserid.data,form.avlpasswd.data,form.ec2pubkey.data) db_session.add(config) db_session.commit() flash('Config Data has been Saved') return redirect(url_for('index')) fo = open("/home/pythonautomate/Automate/automate.cfg", "w") cnx = MySQLdb.connect(**CONFIG.DATABASE) cur=cnx.cursor(MySQLdb.cursors.DictCursor) cur.execute("SELECT bucket,region,s3key,avldb,avluserid,avlpasswd,ec2pubkey from configdata") for row in cur.fetchall(): form.bucket.data=row['bucket'] form.region.data=row['region'] form.s3key.data=row['s3key'] form.s3user.data=row['avluserid'] form.avldb.data=row['avldb'] form.avluserid.data=row['avluserid'] form.avlpasswd.data=row['avlpasswd'] form.ec2pubkey.data=row['ec2pubkey'] # form.bucket.data = str[1].translate(None, "'")+ str[2].translate(None, "'") return render_template('config.html', form=form)
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 configuration(): form = ConfigForm() db = get_db() if request.method == 'POST': if form.validate_on_submit(): db.execute('UPDATE configuration SET width=?, height=?, area=?, hinge=?, angle=?, draftthreshold=?, enginepower=? WHERE window_id=?',[ form.window_width.data, form.window_height.data, form.area.data, form.window_hinge.data, form.window_direction.data, form.draft.data, form.enginepower.data, ACTIVE_WINDOW]) db.commit() flash('Configuration updated', 'success') else: flash('Invalid input', 'danger') config = query_db('SELECT * FROM configuration WHERE window_id=?', [ACTIVE_WINDOW], one=True) if config is None: flash('No configuration set', 'danger') return render_template('configuration.html', form=form) form = ConfigForm( window_width=config['width'], window_height=config['height'], area=config['area'], window_direction=config['angle'], draft=config['draftthreshold'], window_hinge=config['hinge'], enginepower=config['enginepower']) return render_template('configuration.html', form = 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 config_submit(request): if request.method == 'POST': config_form = ConfigForm(request.POST, instance=Config()) if config_form.is_valid(): try: with transaction.atomic(): new_config = config_form.save(commit=False) new_config.created_by = request.user new_config.save() num_lanes = request.POST.get('lane_count') for lane in range(1, int(num_lanes) + 1): new_lane = Lane( number=lane, config=new_config ) new_lane.save() num_libraries = request.POST.get('num_libraries__lane_' + str(lane)) for library in range(1, int(num_libraries) + 1): library_tag = '__lane_{}__lib_{}'.format(lane, library) # If no Barcode is provided, make NULL in database barcode_id = request.POST.get('barcode' + library_tag) if barcode_id != '': barcode = Barcode.objects.get(pk=barcode_id) else: barcode = None # If no cluster_station_concentration is provided, store 0.0 in database cluster_station_concentration = request.POST.get('cluster_station_concentration' + library_tag) if cluster_station_concentration == '': cluster_station_concentration = 0.0 # Create the new library model, hooked up to the newly created lane_model new_library = Library( lane=new_lane, bionimbus_id=request.POST.get('bionimbus_id' + library_tag), submitter=request.POST.get('submitter' + library_tag), barcode=barcode, cluster_station_concentration=cluster_station_concentration ) new_library.save() messages.info(request, 'Successfully added configuration for run {}'. format(new_config.run_name)) except Exception, e: messages.warning(request, 'Adding configuration failed', 'warning') else: messages.warning(request, 'Configuration was not properly filled out', 'thumbs-o-down') return HttpResponseRedirect('/seq-config/config/manage/')
def post(self, *args, **kwargs): print self.request.arguments form = ConfigForm(self.request.arguments) if form.validate(): print 'here' data = create_yaml(self.request.arguments) data.seek(0) self.set_header('Content-Type', 'text/yaml') self.set_header('Content-Disposition', 'attachment; filename=config.yml') self.write(data.read()) self.finish() else: return self.render('form.html', context={'form': form})
def config_edit(request, config_id): config = Config.objects.get(pk=config_id) if request.method == 'POST': updated_config_form = ConfigForm(request.POST, instance=config) if updated_config_form.is_valid(): try: with transaction.atomic(): updated_config = updated_config_form.save() Library.objects.filter(lane__config=updated_config).delete() updated_config.lane_set.all().delete() num_lanes = request.POST.get('lane_count') for lane in range(1, int(num_lanes) + 1): new_lane = Lane( number=lane, config=updated_config ) new_lane.save() num_libraries = request.POST.get('num_libraries__lane_' + str(lane)) for library in range(1, int(num_libraries) + 1): library_tag = '__lane_{}__lib_{}'.format(lane, library) # If no Barcode is provided, make NULL in database barcode_id = request.POST.get('barcode' + library_tag) if barcode_id != '': barcode = Barcode.objects.get(pk=barcode_id) else: barcode = None # If no cluster_station_concentration is provided, store 0.0 in database cluster_station_concentration = request.POST.get('cluster_station_concentration' + library_tag) if cluster_station_concentration == '': cluster_station_concentration = 0.0 new_library = Library( lane=new_lane, bionimbus_id=request.POST.get('bionimbus_id' + library_tag), submitter=request.POST.get('submitter' + library_tag), barcode=barcode, cluster_station_concentration=cluster_station_concentration ) new_library.save() messages.info(request, 'Successfully edited configuration for run {}'.format(updated_config.run_name)) except Exception, e: messages.warning(request, 'Editing configuration failed', 'warning') else: messages.warning(request, 'Configuration was not properly edited', 'thumbs-o-down') return HttpResponseRedirect('/seq-config/config/manage/')
def config(): form = ConfigForm() if form.validate_on_submit(): # flash("" + str(form.temp_set.data) + " " + str(form.temp_delta.data) + " " + str(form.valve_work.data) + " " + str(form.valve_delta.data)) app.cfg['temp_set'] = float(form.temp_set.data) app.cfg['temp_delta'] = float(form.temp_delta.data) app.cfg['valve_work'] = float(form.valve_work.data) app.cfg['valve_delta'] = float(form.valve_delta.data) f=open('/home/pi/reletherm.cfg', 'w') yaml.dump(app.cfg,f) f.close() os.system('/home/pi/reletherm.py restart') return render_template('config.html', form = form, cfg = app.cfg, success = True) return render_template('config.html', form = form, cfg = app.cfg)
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 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 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 settings(): form = ConfigForm() if request.method == 'POST': form.update_db() form.load() return render_template("settings.html", title="Alert Config", 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 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)