From 5a16046eddc753b752c5ab1fdb91595adf588a6b Mon Sep 17 00:00:00 2001 From: Mitsuo Tokumori Date: Mon, 13 Nov 2023 10:55:39 -0500 Subject: Add sample file upload for "load_data" blueprint Also add a success page that redirects to the Dashboard --- ustayml/__init__.py | 9 ++-- ustayml/db.py | 15 ++++++- ustayml/static/style.css | 37 ++++++++++++++++- ustayml/templates/base.html | 4 +- ustayml/templates/load_data/index.html | 71 ++++++++++++++++++++++++++++++++ ustayml/templates/load_data/success.html | 16 +++++++ ustayml/templates/students/details.html | 1 - ustayml/views/load_data.py | 50 ++++++++++++++++++++++ ustayml/views/students.py | 3 ++ 9 files changed, 195 insertions(+), 11 deletions(-) create mode 100644 ustayml/templates/load_data/index.html create mode 100644 ustayml/templates/load_data/success.html create mode 100644 ustayml/views/load_data.py diff --git a/ustayml/__init__.py b/ustayml/__init__.py index 135ef57..fbe1b3a 100644 --- a/ustayml/__init__.py +++ b/ustayml/__init__.py @@ -11,6 +11,8 @@ def create_app(test_config=None): app.config.from_mapping( SECRET_KEY='dev', DATABASE=os.path.join(app.instance_path, 'ustayml.sqlite'), + DATASET_PATH=os.path.join(app.instance_path, 'dataset'), + STUDENT_DATA_PATH=os.path.join(app.instance_path, 'student'), ) if test_config is None: @@ -32,14 +34,13 @@ def create_app(test_config=None): from . import db db.init_app(app) - from .views import auth - app.register_blueprint(auth.bp) - # from .views import blog # app.register_blueprint(blog.bp) - from .views import students + from .views import auth, students, load_data + app.register_blueprint(auth.bp) app.register_blueprint(students.bp) + app.register_blueprint(load_data.bp) # Extra app.add_url_rule('/', endpoint='index') diff --git a/ustayml/db.py b/ustayml/db.py index 04587cc..5fb5ea8 100644 --- a/ustayml/db.py +++ b/ustayml/db.py @@ -35,6 +35,16 @@ def close_db(e=None): # CLI: # https://flask.palletsprojects.com/en/3.0.x/cli/ +def init_fs(): + """Init file system directories""" + import os + dirs = [ + current_app.config['DATASET_PATH'], + current_app.config['STUDENT_DATA_PATH'] + ] + for d in dirs: + os.makedirs(d, exist_ok=True) + def init_db(): db = get_db() @@ -45,8 +55,9 @@ def init_db(): @click.command('init-db') def init_db_command(): """Clear the existing data and create new tables.""" - init_db() - click.echo('Initialized the database.') + init_fs() + # init_db() + # click.echo('Initialized the database.') # Register function with application diff --git a/ustayml/static/style.css b/ustayml/static/style.css index 0357f46..3d52059 100644 --- a/ustayml/static/style.css +++ b/ustayml/static/style.css @@ -117,7 +117,7 @@ header .action { .flex-container-horizontal { display: flex; - align-items: flex-end; + align-items: center; } /* tooltip */ @@ -257,6 +257,39 @@ header .action { flex: auto; } +/* load_data */ + +ul.data-validation-list { + list-style: none; + margin-left: 2em; + padding-left: 0; +} + +ul.data-validation-list li:before { + content: '☑️'; + padding-right: 1em; +} + +ul.data-validation-list li { + /* padding-left: 0.5em; */ + text-indent: -2em; +} + +.load-data-step { + margin-top: 1em; + padding: 0 .5em; + border: 1px solid black; +} + +.load-data-step .left { + /* background-color: aqua; */ + padding-right: 1em; +} + +.load-data-step .right { + width: 40%; +} + /* post */ .post > header { @@ -314,7 +347,7 @@ input.danger { input[type="submit"] { align-self: start; - min-width: 10em; + /* min-width: 10em; */ } /* text status styles */ diff --git a/ustayml/templates/base.html b/ustayml/templates/base.html index b8d243c..eefbc06 100644 --- a/ustayml/templates/base.html +++ b/ustayml/templates/base.html @@ -5,10 +5,10 @@