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:
Peter Stockings
2025-03-30 22:20:48 +11:00
parent 4a822ea2ba
commit 6095e76f10
12 changed files with 244 additions and 175 deletions

View File

@@ -6,7 +6,7 @@
<div class="flex items-center justify-between pt-2 pb-2">
<div class="flex">
<div class="flex ml-1 md:ml-6">
<button hx-get="{{ url_for('get_calendar', person_id=person_id) }}" hx-target="#container"
<button hx-get="{{ url_for('calendar.get_calendar', person_id=person_id) }}" hx-target="#container"
hx-vals='{"date": "{{ prev_date }}"}' hx-include="[name='view']" hx-push-url="true"
hx-swap="innerHTML swap:0.5s">
<svg class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
@@ -16,7 +16,7 @@
</path>
</svg>
</button>
<button hx-get="{{ url_for('get_calendar', person_id=person_id) }}" hx-target="#container"
<button hx-get="{{ url_for('calendar.get_calendar', person_id=person_id) }}" hx-target="#container"
hx-vals='{"date": "{{ next_date }}"}' hx-include="[name='view']" hx-push-url="true"
hx-swap="innerHTML swap:0.5s">
<svg class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
@@ -40,9 +40,9 @@
</div>
<div class="mr-4">
<select name="view" hx-get="{{ url_for('get_calendar', person_id=person_id) }}" hx-target="#container"
hx-vals='{"date": "{{ date }}"}' hx-push-url="true" _="init js(me) tail.select(me, {}) end"
class="h-10 invisible">
<select name="view" hx-get="{{ url_for('calendar.get_calendar', person_id=person_id) }}"
hx-target="#container" hx-vals='{"date": "{{ date }}"}' hx-push-url="true"
_="init js(me) tail.select(me, {}) end" class="h-10 invisible">
<option value="month" {% if view=='month' %}selected{% endif %}>Month</option>
<option value="year" {% if view=='year' %}selected{% endif %}>Year</option>
<option value="notes">Notes</option>
@@ -121,7 +121,7 @@
{% for month in months %}
<div>
<div class="bg-grey-lighter font-semibold text-center cursor-pointer"
hx-get="{{ url_for('get_calendar', person_id=person_id) }}" hx-target="#container"
hx-get="{{ url_for('calendar.get_calendar', person_id=person_id) }}" hx-target="#container"
hx-vals='{"date": "{{ month.first_day_of_month }}", "view": "month"}' hx-push-url="true"
_="on click go to the top of the body">
{{ month.first_day_of_month | strftime('%B') }}

View File

@@ -10,6 +10,16 @@
<div class="prose max-w-none">
<p>Updates and changes to the site will be documented here, with the most recent changes listed first.</p>
<!-- New Entry for Refactoring -->
<hr class="my-6">
<h2 class="text-xl font-semibold mb-2">March 30, 2025</h2>
<ul class="list-disc pl-5 space-y-1">
<li>Refactored the calendar view and logic into its own blueprint (`routes/calendar.py`).</li>
<li>Cleaned up calendar code, removing the `Calendar` class and `pandas` dependency.</li>
<li>Fixed various bugs related to the calendar refactoring (circular imports, HTMX checks, `url_for`
build errors, date comparisons).</li>
</ul>
<!-- Example Entry Structure -->
<hr class="my-6"> {# Increased margin for HR #}
<h2 class="text-xl font-semibold mb-2">March 30, 2025</h2> {# Reduced margin-bottom for H2 #}
@@ -17,6 +27,7 @@
<li>Added the initial changelog page.</li>
<li>Fixed a minor styling issue on the dashboard.</li>
<li>Improved visual styling of the changelog page itself.</li> {# Added an entry for this change #}
<li>Refactored the calendar view and logic into its own blueprint (`routes/calendar.py`).</li>
</ul>
{# Add more entries below, following the pattern above #}

View File

@@ -117,7 +117,8 @@
<span class="text-base font-normal text-gray-500">Current rep maxes</span>
</div>
<div class="flex-shrink-0">
<a hx-get="{{ url_for('get_calendar', person_id=person.id) }}" hx-push-url="true" hx-target="#container"
<a hx-get="{{ url_for('calendar.get_calendar', person_id=person.id) }}" hx-push-url="true"
hx-target="#container"
class="text-sm font-medium text-cyan-600 hover:bg-gray-100 rounded-lg p-2 cursor-pointer">View
workouts</a>
</div>

View File

@@ -12,8 +12,8 @@
</div>
<div class="mr-4">
<select name="view" hx-get="{{ url_for('get_calendar', person_id=person_id) }}" hx-target="#container"
x-push-url="true" _="init js(me) tail.select(me, {}) end" class="h-10 invisible">
<select name="view" hx-get="{{ url_for('calendar.get_calendar', person_id=person_id) }}"
hx-target="#container" x-push-url="true" _="init js(me) tail.select(me, {}) end" class="h-10 invisible">
<option value="month">Month</option>
<option value="year">Year</option>
<option value="notes" selected>Notes</option>

View File

@@ -1,6 +1,7 @@
{% for p in people %}
<li>
<a hx-get="{{ url_for('get_calendar' ,person_id=p['PersonId']) }}" hx-push-url="true" hx-target="#container"
<a hx-get="{{ url_for('calendar.get_calendar' ,person_id=p['PersonId']) }}" hx-push-url="true"
hx-target="#container"
class="text-base text-gray-900 font-normal rounded-lg hover:bg-gray-100 flex items-center p-2 group cursor-pointer page-link"
_="on click add .hidden to #sidebar then remove .ml-64 from #main
on htmx:afterRequest go to the top of the body">

View File

@@ -12,7 +12,7 @@
</div>
<div>
<div>
<select name="view" hx-get="{{ url_for('get_calendar', person_id=person_id) }}"
<select name="view" hx-get="{{ url_for('calendar.get_calendar', person_id=person_id) }}"
hx-target="#container" hx-push-url="true" _="init js(me) tail.select(me, {}) end"
class="h-10 invisible">
<option value="month">Month</option>

View File

@@ -24,7 +24,7 @@
d="m1 9 4-4-4-4" />
</svg>
{% set hx_current_url = request.headers.get('HX-Current-URL') %}
<a hx-get="{{ hx_current_url if hx_current_url else url_for('get_calendar', person_id=person_id) }}"
<a hx-get="{{ hx_current_url if hx_current_url else url_for('calendar.get_calendar', person_id=person_id) }}"
hx-push-url="true" hx-target="#container"
class="ms-1 text-sm font-medium text-gray-700 hover:text-blue-600 md:ms-2 dark:text-gray-400 dark:hover:text-white cursor-pointer">{{person_name}}</a>
</div>