diff --git a/app.py b/app.py index 97477d7..c26f145 100755 --- a/app.py +++ b/app.py @@ -60,7 +60,7 @@ def get_locale(): def create_app(): - app = Flask(__name__) + app = Flask(__name__, static_url_path='/stark/static') @@ -108,24 +108,11 @@ def create_app(): return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS - - @app.route('/upload') - def upload_file2(): - return render_template('upload.html') - - - @app.route('/uploader', methods=['GET', 'POST']) - def upload_file(): - if request.method == 'POST': - f = request.files['file'] - f.save(secure_filename(f.filename)) - return 'file uploaded successfully' - - @app.route('/about', methods=['GET']) + @app.route('/stark/about', methods=['GET']) def about(): return render_template('about.html') - @app.route('/result/', methods=['GET', 'POST']) + @app.route('/stark/result/', methods=['GET', 'POST']) def result(result_id): if request.method == 'POST': @@ -167,7 +154,7 @@ def create_app(): displayed_content_dict[TABLE_COLUMNS2DISPLAYED_TABLE_COLUMNS[column]] = v return render_template('result.html', head_row=displayed_head, content=displayed_content_dict) - @app.route('/', methods=['GET', 'POST']) + @app.route('/stark/', methods=['GET', 'POST']) # @headers({'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'}) def index(): translations = _translations[get_locale()] @@ -274,27 +261,30 @@ def create_app(): else: configs['query'] = None - # handling input - if 'compare_file' in request.files and request.files['compare_file']: - # store file - f = request.files['compare_file'] - input_path = os.path.join('media', secure_filename(f.filename)) - f.save(input_path) + # handling input + if 'compare_file' in request.files and request.files['compare_file']: + # store file + f = request.files['compare_file'] + input_path = os.path.join('media', secure_filename(f.filename)) + f.save(input_path) + configs['compare'] = input_path + if 'compare_url' in form and form['compare_url']: + validation['compare_file'] = gettext('Please insert either compare url or file, not both of them.') + validation['compare_url'] = gettext('Please insert either compare url or file, not both of them.') + + elif 'compare_url' in form and form['compare_url']: + try: + name = form['compare_url'].split('/')[-1] + input_path = os.path.join('media', name) + response = requests.get(form['compare_url']) + open(input_path, "wb").write(response.content) configs['compare'] = input_path - if 'compare_url' in form and form['compare_url']: - validation['compare_file'] = gettext('Please insert either compare url or file, not both of them.') - validation['compare_url'] = gettext('Please insert either compare url or file, not both of them.') - - elif 'compare_url' in form and form['compare_url']: - try: - name = form['compare_url'].split('/')[-1] - input_path = os.path.join('media', name) - response = requests.get(form['compare_url']) - open(input_path, "wb").write(response.content) - configs['compare'] = input_path - except: - validation['compare_url'] = gettext('Incorrect URL!') + except: + configs['compare'] = None + validation['compare_url'] = gettext('Incorrect URL!') + else: + configs['compare'] = None configs['sentence_count_file'] = None configs['detailed_results_file'] = None diff --git a/static/js/init.js b/static/js/init.js index 4c36e8c..cd74aff 100644 --- a/static/js/init.js +++ b/static/js/init.js @@ -1,6 +1,6 @@ // Global array to store input names var globalInputList = ['tree_size_min', 'tree_size_max', 'file', 'association_measures', 'labeled_trees', 'node_type_upos', 'fixed_order', 'input_url', 'node_type_lemma', 'root_restriction', 'node_type_form', 'frequency_threshold']; -//const URLSearchParams = window.URLSearchParams; + // Function to store values to local storage function storeValuesToLocalstorage() { globalInputList.forEach(function(inputName) { @@ -75,24 +75,6 @@ document.addEventListener("DOMContentLoaded", function(event) { }, format: format }); - /* - // OLD VERSION - var perfEntries = performance.getEntriesByType("navigation"); - - for (var i = 0; i < perfEntries.length; i++) { - if (perfEntries[i].type === 'back_forward') { - window.location.href = '?noreload=true' - return; - } - } - var urlParams = new URLSearchParams(window.location.search); - if (!urlParams.has('noreload')) { - if (Object.keys(localStorage).length > 1) { - localStorage.clear(); - window.location.href = '?noreload=true' - } - - }*/ var urlParams = new URLSearchParams(window.location.search); var lang='en' @@ -103,17 +85,15 @@ document.addEventListener("DOMContentLoaded", function(event) { var perfEntries = performance.getEntriesByType("navigation"); for (var i = 0; i < perfEntries.length; i++) { if (perfEntries[i].type === 'back_forward') { - window.location.href = '/?lang='+lang; + window.location.href = '/stark/?lang='+lang; return; } } if (urlParams.has('reload')) { -// if (Object.keys(localStorage).length > 1) { localStorage.clear(); - window.location.href = '/?lang='+lang; -// } + window.location.href = '/stark/?lang='+lang; } }); @@ -123,11 +103,9 @@ document.addEventListener("DOMContentLoaded", function(event) { $('.sidenav').sidenav(); - }); // end of document ready + }); $(document).ready(function(){ $('.modal').modal(); -// var instance = M.Modal.getInstance(elem); -// instance.open(); $('.input-field input[type="checkbox"]').on('change', function() { var isChecked = $('.input-field input[type="checkbox"]:checked').length > 0; @@ -186,5 +164,5 @@ document.addEventListener("DOMContentLoaded", function(event) { storeValuesToLocalstorage(); return true; }); -})(jQuery); // end of jQuery name space +})(jQuery); diff --git a/templates/about.html b/templates/about.html index 4dc298c..1c47b99 100644 --- a/templates/about.html +++ b/templates/about.html @@ -15,9 +15,9 @@