Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b9adf63
form update
May 28, 2024
17b8e8e
wWWW
May 29, 2024
7240748
q form
May 29, 2024
32e5a79
Yuh
atipre May 29, 2024
fb77eae
multiple choice
May 29, 2024
eb7feb8
login fixed
atipre May 29, 2024
6da3b6d
button
May 29, 2024
603eaef
w
May 29, 2024
44944db
w
May 29, 2024
59bc0da
w
May 29, 2024
cbe00e2
tracker
May 30, 2024
bb9b97a
w
May 30, 2024
dc5ba0a
multi
May 30, 2024
4de0fcd
Weight Tracker + graph+
atipre May 30, 2024
5f23649
dynamic
May 30, 2024
5e9e4a5
w
May 30, 2024
2f9388f
multiselect
May 30, 2024
15251db
Weight Tracker + how to update weight
atipre May 30, 2024
8980b98
Weight update
atipre May 30, 2024
db66c7a
Fixed update weight button
atipre May 30, 2024
622b15a
Fixed undo weight
atipre May 30, 2024
2e4236a
q1 changes
May 30, 2024
24fd354
Trying to get weight to store
atipre May 30, 2024
08b8864
dynamic m
May 30, 2024
b3ef1ee
trackerstorage
May 30, 2024
50ce2b9
styles
May 31, 2024
e642e94
updated
May 31, 2024
753774b
Aesthetics
atipre May 31, 2024
2c71344
w
May 31, 2024
6252e6e
w
May 31, 2024
18e9a52
newest
May 31, 2024
58976d6
new ui
dkardhashi Jul 7, 2024
0500700
Cool stuff
atipre Jul 9, 2024
c4bdcc1
bus
dkardhashi Jul 9, 2024
030e45f
WWW
dkardhashi Jul 9, 2024
eaf9958
w
dkardhashi Jul 9, 2024
117559c
Editted boxes spacing
atipre Jul 9, 2024
ce1816a
w
atipre Jul 9, 2024
5bc2224
w
dkardhashi Jul 9, 2024
1ed95af
Changed Dashboard to home and logout to profile
atipre Jul 9, 2024
9d8ffc0
w
dkardhashi Jul 9, 2024
c2904ec
W
dkardhashi Jul 9, 2024
1bfc2ae
Colors and shi
atipre Jul 9, 2024
4771cc6
deez
dkardhashi Jul 9, 2024
2e62a25
W
dkardhashi Jul 10, 2024
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
Binary file added .DS_Store
Binary file not shown.
Binary file added instance/database.db
Binary file not shown.
1 change: 1 addition & 0 deletions migrations/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Single-database configuration for Flask.
Binary file added migrations/__pycache__/env.cpython-312.pyc
Binary file not shown.
50 changes: 50 additions & 0 deletions migrations/alembic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# A generic, single database configuration.

[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s

# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false


# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic,flask_migrate

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = WARN
handlers = console
qualname =

[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine

[logger_alembic]
level = INFO
handlers =
qualname = alembic

[logger_flask_migrate]
level = INFO
handlers =
qualname = flask_migrate

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
113 changes: 113 additions & 0 deletions migrations/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import logging
from logging.config import fileConfig

from flask import current_app

from alembic import context

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')


def get_engine():
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
return current_app.extensions['migrate'].db.get_engine()
except (TypeError, AttributeError):
# this works with Flask-SQLAlchemy>=3
return current_app.extensions['migrate'].db.engine


def get_engine_url():
try:
return get_engine().url.render_as_string(hide_password=False).replace(
'%', '%%')
except AttributeError:
return str(get_engine().url).replace('%', '%%')


# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
config.set_main_option('sqlalchemy.url', get_engine_url())
target_db = current_app.extensions['migrate'].db

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def get_metadata():
if hasattr(target_db, 'metadatas'):
return target_db.metadatas[None]
return target_db.metadata


def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=get_metadata(), literal_binds=True
)

with context.begin_transaction():
context.run_migrations()


def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""

# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')

conf_args = current_app.extensions['migrate'].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives

connectable = get_engine()

with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=get_metadata(),
**conf_args
)

with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
24 changes: 24 additions & 0 deletions migrations/script.py.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""${message}

Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}

"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}

# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}


def upgrade():
${upgrades if upgrades else "pass"}


def downgrade():
${downgrades if downgrades else "pass"}
Binary file not shown.
70 changes: 70 additions & 0 deletions migrations/versions/d19dd2c3e751_initial_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Initial migration.

Revision ID: d19dd2c3e751
Revises:
Create Date: 2024-07-09 18:29:09.592453

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'd19dd2c3e751'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('questionnaire_response', schema=None) as batch_op:
batch_op.add_column(sa.Column('question_id', sa.String(length=50), nullable=True))
batch_op.add_column(sa.Column('response', sa.String(length=1000), nullable=True))
batch_op.alter_column('user_id',
existing_type=sa.INTEGER(),
nullable=True)
batch_op.drop_column('question3')
batch_op.drop_column('question2')
batch_op.drop_column('question1')

with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.add_column(sa.Column('has_completed_questionnaire', sa.Boolean(), nullable=True))

with op.batch_alter_table('weight', schema=None) as batch_op:
batch_op.alter_column('user_id',
existing_type=sa.INTEGER(),
nullable=True)

with op.batch_alter_table('weight_entry', schema=None) as batch_op:
batch_op.add_column(sa.Column('date', sa.DateTime(), nullable=True))
batch_op.drop_column('date_added')

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('weight_entry', schema=None) as batch_op:
batch_op.add_column(sa.Column('date_added', sa.DATETIME(), nullable=True))
batch_op.drop_column('date')

with op.batch_alter_table('weight', schema=None) as batch_op:
batch_op.alter_column('user_id',
existing_type=sa.INTEGER(),
nullable=False)

with op.batch_alter_table('user', schema=None) as batch_op:
batch_op.drop_column('has_completed_questionnaire')

with op.batch_alter_table('questionnaire_response', schema=None) as batch_op:
batch_op.add_column(sa.Column('question1', sa.VARCHAR(length=200), nullable=False))
batch_op.add_column(sa.Column('question2', sa.VARCHAR(length=200), nullable=False))
batch_op.add_column(sa.Column('question3', sa.VARCHAR(length=200), nullable=False))
batch_op.alter_column('user_id',
existing_type=sa.INTEGER(),
nullable=False)
batch_op.drop_column('response')
batch_op.drop_column('question_id')

# ### end Alembic commands ###
22 changes: 22 additions & 0 deletions questionnaire_tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Questionnaire Tree
digraph {
1 [label="Are there any muscle groups you DO NOT want to exercise?"]
1.1 [label="Select all muscle groups you DO NOT want to exercise"]
2 [label="How many days a week do you want to workout?"]
2.1 [label="Do you want to workout on back to back days?"]
1 -> 1.1 [label=1]
condition1 [label=condition1 shape=box]
1 -> condition1 [label=2]
1.1 -> 2 [label=A]
1.1 -> 2 [label=B]
1.1 -> 2 [label=C]
1.1 -> 2 [label=D]
1.1 -> 2 [label=E]
2 -> 2.1 [label=1]
condition3 [label=condition3 shape=box]
2 -> condition3 [label=2]
condition3 [label=condition3 shape=box]
2.1 -> condition3 [label=1]
condition3 [label=condition3 shape=box]
2.1 -> condition3 [label=2]
}
Binary file added questionnaire_tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/.DS_Store
Binary file not shown.
26 changes: 23 additions & 3 deletions website/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,60 @@
from flask_sqlalchemy import SQLAlchemy
from os import path
from flask_login import LoginManager
from flask_migrate import Migrate

# Create SQLAlchemy instance
db = SQLAlchemy()
DB_NAME = "database.db"
migrate = Migrate()


def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hjshjhdjah kjshkjdhjs'
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}'

# Initialize SQLAlchemy with the Flask app
db.init_app(app)
migrate.init_app(app, db)

# Import blueprints
from .views import views
from .auth import auth
from .weight_tracker import weight_tracker_bp # Import the weight tracker blueprint

# Register blueprints
app.register_blueprint(views, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')
app.register_blueprint(auth, url_prefix='/auth')
app.register_blueprint(weight_tracker_bp, url_prefix='/weight') # Register the weight tracker blueprint

from .models import User, Note
# Import models
from .models import User, Note, QuestionnaireResponse, WeightEntry

with app.app_context():
# Create database tables if they don't exist
db.create_all()

# Initialize LoginManager
login_manager = LoginManager()
login_manager.login_view = 'auth.login'
login_manager.init_app(app)

# Define the user loader function
@login_manager.user_loader
def load_user(id):
return User.query.get(int(id))

# Inject current_user into templates
@app.context_processor
def inject_user():
from flask_login import current_user
return dict(user=current_user)

return app


def create_database(app):
if not path.exists('website/' + DB_NAME):
db.create_all(app=app)
print('Created Database!')

Loading