You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
from flask import Blueprint, redirect, render_template, request, url_for
|
|
|
|
from datetime import datetime
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
|
|
|
|
bp = Blueprint('module', __name__, url_prefix="/")
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/', methods=['GET', 'POST'])
|
|
|
|
def module():
|
|
|
|
if request.method == 'POST':
|
|
|
|
preset = {}
|
|
|
|
for key in request.form.keys():
|
|
|
|
preset[key] = request.form.get(key)
|
|
|
|
name = preset.get('name', 'preset')
|
|
|
|
date = datetime.now().strftime('%Y%m%d%H%M%S')
|
|
|
|
filename = f"{name}~{date}.json"
|
|
|
|
|
|
|
|
with open(os.path.join(os.environ.get('MODULES'), filename), 'w') as f:
|
|
|
|
f.write(json.dumps(preset))
|
|
|
|
|
|
|
|
return redirect(url_for('module.module'))
|
|
|
|
|
|
|
|
modules = [os.path.splitext(filename)[0]
|
|
|
|
for filename in os.listdir(os.environ.get('MODULES'))]
|
|
|
|
|
|
|
|
return render_template('module.html', modules=modules)
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/cables')
|
|
|
|
def cables():
|
|
|
|
return render_template('cables.html')
|