From 107e38d39e1b18098f21c30a1be848c9d5b609c7 Mon Sep 17 00:00:00 2001 From: Thomas Hanke Date: Fri, 25 Nov 2022 11:22:18 +0100 Subject: [PATCH] added CORS and fixed a bug converting floats with , as decimal sepaator --- annotator.py | 3 ++- app.py | 10 +++++++--- requirements.txt | 1 + templates/index.html | 9 +-------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/annotator.py b/annotator.py index 3d0ce94..411e549 100644 --- a/annotator.py +++ b/annotator.py @@ -302,6 +302,7 @@ def get_unit(self, string): string = string.replace(k, self.superscripts_replace[k]) string=string.replace('N/mm\u00b2','N.m.m-2') string=string.replace('Nm','N.m') + string=string.replace('sec','s') found = get_entities_with_property_with_value( units_graph, QUDT.Symbol, Literal(string)) \ @@ -358,7 +359,7 @@ def describe_value(self, value_string): elif self.get_value_type(value_string) == 'BOOL': return {"@type": "qudt:Quantity",'qudt:value': {'@value': bool(value_string), '@type': 'xsd:boolean'}} elif self.get_value_type(value_string) == 'FLOAT': - return {"@type": "qudt:Quantity",'qudt:value': {'@value': float(value_string), '@type': 'xsd:decimal'}} + return {"@type": "qudt:Quantity",'qudt:value': {'@value': float(value_string.replace(',','.')), '@type': 'xsd:decimal'}} elif self.get_value_type(value_string) == 'DATE': return {"@type": "qudt:Quantity",'qudt:value': {'@value': str(parse(value_string).isoformat()), '@type': 'xsd:dateTime'}} else: diff --git a/app.py b/app.py index 695054c..31a887a 100644 --- a/app.py +++ b/app.py @@ -7,6 +7,7 @@ from flask_swagger_ui import get_swaggerui_blueprint from flask_wtf import FlaskForm from flask_bootstrap import Bootstrap +from flask_cors import CORS, cross_origin from wtforms import URLField, SelectField from wtforms.validators import DataRequired @@ -20,6 +21,8 @@ app = Flask(__name__) app.config.from_object(config[config_name]) +CORS(app) +app.config['CORS_HEADERS'] = 'Content-Type' bootstrap = Bootstrap(app) @@ -70,6 +73,7 @@ class StartForm(FlaskForm): @app.route('/', methods=['GET', 'POST']) +@cross_origin() def index(): logo = './static/resources/MatOLab-Logo.svg' start_form = StartForm() @@ -84,7 +88,7 @@ def index(): ) -@app.route('/create_annotator', methods=['POST']) +@app.route('/annotate', methods=['GET','POST']) def create_annotator(): logo = './static/resources/MatOLab-Logo.svg' start_form = StartForm() @@ -98,9 +102,8 @@ def create_annotator(): encoding=start_form.encoding_sel.data ) if not start_form.data_url.data: - start_form.data_url.data='https://github.com/Mat-O-Lab/CSVToCSVW/raw/main/examples/example.csv' + start_form.data_url.data=start_form.data_url.render_kw['placeholder'] flash('URL Data File empty: using placeholder value for demonstration') - try: meta_file_name, result = annotator.process( start_form.data_url.data) @@ -129,6 +132,7 @@ def create_annotator(): @app.route("/api", methods=["GET", "POST"]) +@cross_origin() def api(): if request.method == "POST": content = request.get_json() diff --git a/requirements.txt b/requirements.txt index 96f5733..d080adf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ flask flask-bootstrap flask_wtf flask_swagger_ui +flask_cors wtforms pandas html5lib diff --git a/templates/index.html b/templates/index.html index 343d89d..83fb263 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,13 +5,6 @@ {{ super() }} - {% endblock %} {% block html_attribs %} lang="en"{% endblock %} @@ -56,7 +49,7 @@

CSVtoCSVW

{{ start_form.encoding_sel.description }}
- +