Here is a conventional commit message summarizing the refactoring work:
``` feat: Refactor calendar feature into blueprint - Moved calendar logic from `features/calendar.py` and `app.py` into a new blueprint at `routes/calendar.py`. - Removed the `Calendar` class and refactored logic into helper functions within the blueprint module for better organization and readability. - Eliminated the `pandas` dependency for date range generation, using standard `datetime` operations instead. - Resolved circular import issues between `db.py`, `extensions.py`, and `routes/calendar.py` by adjusting import locations. - Corrected `url_for` calls in templates (`calendar.html`, `partials/people_link.html`) to reference the new blueprint endpoint (`calendar.get_calendar`). - Fixed an `AttributeError` related to HTMX request checking in the calendar route. - Corrected `AttributeError` related to `.date()` calls on `datetime.date` objects in view processing functions. - Updated `templates/changelog/changelog.html` to document the refactoring and associated fixes. ```
This commit is contained in:
22
app.py
22
app.py
@@ -7,6 +7,7 @@ from jinja2_fragments import render_block
|
||||
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 extensions import db
|
||||
from utils import convert_str_to_date, generate_plot
|
||||
from flask_htmx import HTMX
|
||||
@@ -34,6 +35,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.after_request
|
||||
def response_minify(response):
|
||||
@@ -127,22 +129,6 @@ 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>/calendar")
|
||||
def get_calendar(person_id):
|
||||
selected_date = convert_str_to_date(request.args.get(
|
||||
'date'), '%Y-%m-%d') or date.today()
|
||||
selected_view = request.args.get('view') or 'month'
|
||||
|
||||
if selected_view == 'overview':
|
||||
return redirect(url_for('person_overview', person_id=person_id))
|
||||
elif selected_view == 'notes':
|
||||
return redirect(url_for('get_person_notes', person_id=person_id))
|
||||
|
||||
calendar_view = db.calendar.fetch_workouts_for_person(person_id, selected_date, selected_view)
|
||||
|
||||
if htmx:
|
||||
return render_block(app.jinja_env, 'calendar.html', 'content', **calendar_view), 200, {"HX-Push-Url": url_for('get_calendar', person_id=person_id, view=selected_view, date=selected_date), "HX-Trigger": "refreshStats"}
|
||||
return render_template('calendar.html', **calendar_view), 200, {"HX-Push-Url": url_for('get_calendar', person_id=person_id, view=selected_view, date=selected_date), "HX-Trigger": "refreshStats"}
|
||||
|
||||
@ app.route("/person/<int:person_id>/notes", methods=['GET'])
|
||||
@ validate_person
|
||||
@@ -166,8 +152,8 @@ def create_workout(person_id):
|
||||
@ validate_workout
|
||||
def delete_workout(person_id, workout_id):
|
||||
db.delete_workout(workout_id)
|
||||
return redirect(url_for('get_calendar', person_id=person_id))
|
||||
#return "", 200, {"HX-Trigger": "updatedPeople", "HX-Push-Url": url_for('get_calendar', person_id=person_id)}
|
||||
return redirect(url_for('calendar.get_calendar', person_id=person_id))
|
||||
#return "", 200, {"HX-Trigger": "updatedPeople", "HX-Push-Url": url_for('calendar.get_calendar', person_id=person_id)}
|
||||
|
||||
|
||||
@ app.route("/person/<int:person_id>/workout/<int:workout_id>/start_date_edit_form", methods=['GET'])
|
||||
|
||||
Reference in New Issue
Block a user