Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes #153

Merged
merged 8 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions simple_app/app_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

# website pathing
@app_simple.route('/')
@app_simple.route('/index', methods=['GET', 'POST'])
@app_simple.route('/index', methods=['GET'])
def index_page():
"""
The main splash/home page
"""
# basic searchbar and source count
source_count = len(all_results)
form = BasicSearchForm()
form = BasicSearchForm(request.args)
return render_template('index_simple.html', source_count=source_count, form=form, version_str=version_str)


Expand All @@ -33,13 +33,13 @@ def about():
return render_template('about.html')


@app_simple.route('/search', methods=['GET', 'POST'])
@app_simple.route('/search', methods=['GET'])
def search():
"""
The searchbar page
"""
# initialisation, check contents of searchbars
form = SearchForm() # main searchbar
form = SearchForm(request.args) # main searchbar
if (ref_query := form.ref_search.data) is None: # content in references searchbar
ref_query = ''
if (query := form.search.data) is None: # content in main searchbar
Expand Down Expand Up @@ -114,12 +114,12 @@ def coordinate_query():
return render_template('coordinate_query.html', form=form, results=None, query='', version_str=version_str)


@app_simple.route('/full_text_search', methods=['GET', 'POST'])
@app_simple.route('/full_text_search', methods=['GET'])
def full_text_search():
"""
Wrapping the search string function to search through all tables and return them
"""
form = LooseSearchForm()
form = LooseSearchForm(request.args)
limmaxrows = False

if (query := form.search.data) is None:
Expand Down Expand Up @@ -249,10 +249,23 @@ def bad_request(e):
e
The HTTP status code
"""
return render_template('bad_request.html', e=e), 500
# handling 404 file not found errors
if e.code == 404:
# all different website routes and requested route
all_routes = ['about', 'search', 'full_text_search', 'load_full_text', 'coordinate_query', 'raw_query',
'multi_plot', 'load_multi_plot']
requested_route = request.path.strip('/')

# get best match of path and redirect
best_match = get_close_matches(requested_route, all_routes, 1)
if best_match:
return redirect(url_for(best_match[0]))

@app_simple.route('/write/<key>.csv', methods=['GET', 'POST'])
# any other error codes or no good match found
return render_template('bad_request.html', e=e), e.code


@app_simple.route('/write/<key>.csv', methods=['GET'])
def create_file_for_download(key: str):
"""
Creates and downloads the shown dataframe from solo results
Expand All @@ -279,7 +292,7 @@ def create_file_for_download(key: str):
abort(400, 'Could not write table')


@app_simple.route('/write_solo_all', methods=['GET', 'POST'])
@app_simple.route('/write_solo_all', methods=['GET'])
def create_files_for_solo_download():
"""
Creates and downloads all dataframes from solo results
Expand All @@ -302,7 +315,7 @@ def create_files_for_solo_download():
return response


@app_simple.route('/write_spectra', methods=['GET', 'POST'])
@app_simple.route('/write_spectra', methods=['GET'])
def create_spectra_files_for_download():
"""
Downloads the spectra files and zips together
Expand All @@ -325,7 +338,7 @@ def create_spectra_files_for_download():
abort(400, 'Could not download fits')


@app_simple.route('/write_filt', methods=['GET', 'POST'])
@app_simple.route('/write_filt', methods=['GET'])
def create_file_for_filtered_download():
"""
Creates and downloads the shown dataframe when in filtered search
Expand Down Expand Up @@ -370,7 +383,7 @@ def create_file_for_coordinate_download():
return response


@app_simple.route('/write_full/<key>', methods=['GET', 'POST'])
@app_simple.route('/write_full/<key>', methods=['GET'])
def create_file_for_full_download(key: str):
"""
Creates and downloads the shown dataframe when in unrestrained search
Expand All @@ -396,7 +409,7 @@ def create_file_for_full_download(key: str):
abort(400, 'Could not write table')


@app_simple.route('/write_all', methods=['GET', 'POST'])
@app_simple.route('/write_all', methods=['GET'])
def create_files_for_multi_download():
"""
Creates and downloads all dataframes from full results
Expand Down Expand Up @@ -430,7 +443,7 @@ def create_file_for_sql_download():
return response


args, db_file, photometric_filters, all_results, all_results_full, version_str,\
args, db_file, photometric_filters, all_results, all_results_full, version_str, \
all_photometry, all_bands, all_parallaxes, all_spectral_types = main_utils()
night_sky_theme, js_callbacks = main_plots()

Expand Down
4 changes: 3 additions & 1 deletion simple_app/simports.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from bokeh.resources import CDN # resources for webpage
from bokeh.themes import built_in_themes, Theme # appearance of bokeh glyphs
from bokeh.transform import linear_cmap # making colour maps
from flask import Flask, render_template, jsonify, send_from_directory, redirect, url_for, Response, abort # website
from flask import (Flask, render_template, jsonify, send_from_directory, redirect, url_for,
Response, abort, request) # website
from flask_cors import CORS # cross origin fix (aladin mostly)
from flask_wtf import FlaskForm # web forms
from markdown2 import markdown # using markdown formatting
Expand All @@ -33,6 +34,7 @@
# internal packages
import argparse # parsing the arguments given with file
from copy import deepcopy # memory control
from difflib import get_close_matches # for redirecting bad file paths
from io import StringIO, BytesIO, BufferedIOBase # writing files without saving to disk
import multiprocessing as mp # multiprocessing for efficiency
import os # operating system
Expand Down
1 change: 1 addition & 0 deletions simple_app/static/css/responsive.bootstrap.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified simple_app/static/favicon.ico
Binary file not shown.
Loading
Loading