If you do not need the file selection box above, set
use_upload_structure_block: false
in the config.yaml
file.
Otherwise, to use it, define a blueprint
in your compute
module, using the following code:
import flask blueprint = flask.Blueprint('compute', __name__, url_prefix='/compute')
Then, you should define at least the following route:
import io from tools_barebone.structure_importers import get_structure_tuple, UnknownFormatError @blueprint.route('/process_structure/', methods=['GET', 'POST']) def process_structure(): if flask.request.method == 'POST': # check if the post request has the file part if 'structurefile' not in flask.request.files: return flask.redirect(flask.url_for('input_data')) structurefile = flask.request.files['structurefile'] fileformat = flask.request.form.get('fileformat', 'unknown') filecontent = structurefile.read().decode('utf-8') fileobject = io.StringIO(str(filecontent)) form_data = dict(flask.request.form) try: structure_tuple = get_structure_tuple(fileobject, fileformat, extra_data=form_data) except UnknownFormatError: flask.flash("Unknown format '{}'".format(fileformat)) return flask.redirect(flask.url_for('input_data')) except Exception: flask.flash("I tried my best, but I wasn't able to load your " "file in format '{}'...".format(fileformat)) return flask.redirect(flask.url_for('input_data')) data_for_template = { # Generate data here based on the structure_tuple and what # you want to do in your application } # Create first a HTML template using the Jinja2 syntax return flask.render_template('user_templates/MYTEMPLATE.html', **data_for_template)
You need to add HTML forms to select_content
to replace this empty placeholder.
In the config file, create a templates
dictionary,
if not yet there, and set the variable select_content
to point
to you custom template:
templates:
- select_content: "custom_select_content.html"
You can also add the following if you want to add at the top the standard structure loader:
use_upload_structure_block: true