feat: Refactor notes functionality into blueprint
- Moved notes-related routes (viewing/editing workout notes) from `app.py` into a new blueprint at `routes/notes.py`. - Integrated notes-specific database logic (fetching and updating notes) directly into `routes/notes.py` helper functions, removing the corresponding methods from `db.py` for better encapsulation. - Registered the new `notes_bp` blueprint in `app.py`. - Removed the original notes route definitions from `app.py`. - Updated `url_for` calls in `templates/partials/workout_note.html` to reference the new blueprint endpoints (e.g., `notes.get_person_notes`). - Updated `templates/changelog/changelog.html` to document this refactoring in its own entry.
This commit is contained in:
33
app.py
33
app.py
@@ -8,6 +8,7 @@ from decorators import validate_person, validate_topset, validate_workout
|
||||
from routes.auth import auth, get_person_by_id
|
||||
from routes.changelog import changelog_bp
|
||||
from routes.calendar import calendar_bp # Import the new calendar blueprint
|
||||
from routes.notes import notes_bp # Import the new notes blueprint
|
||||
from extensions import db
|
||||
from utils import convert_str_to_date, generate_plot
|
||||
from flask_htmx import HTMX
|
||||
@@ -36,6 +37,7 @@ def load_user(person_id):
|
||||
app.register_blueprint(auth, url_prefix='/auth')
|
||||
app.register_blueprint(changelog_bp, url_prefix='/changelog')
|
||||
app.register_blueprint(calendar_bp) # Register the calendar blueprint
|
||||
app.register_blueprint(notes_bp) # Register the notes blueprint
|
||||
|
||||
@app.after_request
|
||||
def response_minify(response):
|
||||
@@ -130,13 +132,8 @@ def person_overview(person_id):
|
||||
return render_template('person_overview.html', **render_args), 200, {"HX-Push-Url": url_for('person_overview', person_id=person_id, min_date=min_date, max_date=max_date, exercise_id=selected_exercise_ids), "HX-Trigger": "refreshStats"}
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>/notes", methods=['GET'])
|
||||
@ validate_person
|
||||
def get_person_notes(person_id):
|
||||
(person_name, workout_notes) = db.get_workout_notes_for_person(person_id)
|
||||
if htmx:
|
||||
return render_block(app.jinja_env, 'notes.html', 'content', person_id=person_id, person_name=person_name, workout_notes=workout_notes)
|
||||
return render_template('notes.html', person_id=person_id, person_name=person_name, workout_notes=workout_notes)
|
||||
# Route moved to routes/notes.py
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>/workout", methods=['POST'])
|
||||
def create_workout(person_id):
|
||||
@@ -331,27 +328,7 @@ def delete_tag(tag_id):
|
||||
db.delete_tag_for_dashboard(tag_id)
|
||||
return redirect(url_for('dashboard') + tag_filter)
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/note/edit", methods=['GET'])
|
||||
@ validate_workout
|
||||
def get_workout_note_edit_form(person_id, workout_id):
|
||||
workout = db.get_workout(person_id, workout_id)
|
||||
return render_template('partials/workout_note.html', person_id=person_id, workout_id=workout_id, note=workout['note'], is_edit=True)
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/note", methods=['PUT'])
|
||||
@ validate_workout
|
||||
def update_workout_note(person_id, workout_id):
|
||||
note = request.form.get('note')
|
||||
db.update_workout_note_for_person(person_id, workout_id, note)
|
||||
return render_template('partials/workout_note.html', person_id=person_id, workout_id=workout_id, note=note)
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/note", methods=['GET'])
|
||||
@ validate_workout
|
||||
def get_workout_note(person_id, workout_id):
|
||||
workout = db.get_workout(person_id, workout_id)
|
||||
return render_template('partials/workout_note.html', person_id=person_id, workout_id=workout_id, note=workout['note'])
|
||||
# Routes moved to routes/notes.py
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/tag/add", methods=['POST'])
|
||||
|
||||
Reference in New Issue
Block a user