## Implementation Plan: Render Attachments on Front Page & Profile Post Listings ### Scope - **Landing page** (`/`) – add attachments to `LandingPostOut` schema, fetch them in the route, and render them in the template. - **Profile page** (`/profile/{username}?tab=posts`) – fetch attachments in the profile route and pass them to the existing `_post_card.html` template. - Both fixes are independent; order is arbitrary. No changes to feed or detail pages (already working). ### Files to modify #### 1. `devplacepy/schemas/auth.py` - **Line ~37**: Add `attachments: list[AttachmentOut] = []` to the `LandingPostOut` dataclass/model. (Import `AttachmentOut` if not already present – check top of file.) #### 2. `devplacepy/main.py` - **Route handler for `/` (around lines 651–687)**: 1. After building `raw_posts` and `enriched_posts`, call `get_attachments_batch("post", post_uids)` where `post_uids` is the list of `post.uid` from `raw_posts`. 2. Iterate over `enriched_posts` and attach the gallery: `item.attachments = attachments_map.get(item.post.uid, [])` 3. Pass the resulting `LandingPostOut` objects to the template context. #### 3. `devplacepy/templates/landing.html` - **Inside the `
` block (lines 189–216)**: - Add `{% include '_attachment_display.html' %}` (same pattern as `_post_card.html`). - This include expects a variable named `item` with `.attachments` list – ensure the template context uses the same variable name (likely `feed_item` or `post` – check loop variable). #### 4. `devplacepy/routers/profile/index.py` - **After line 183 (after `enrich_items`)**: 1. Gather all `post.uid` values from `raw_posts`. 2. Call `get_attachments_batch("post", post_uids)` to obtain `attachments_map`. - **Inside the post-processing loop (lines 191–195)**: 3. Add `item["attachments"] = attachments_map.get(uid, [])` alongside the existing `reactions`, `bookmarked`, `poll` assignments. - (No template change needed; `_post_card.html` already renders attachments if `item.attachments` is set.) ### Dependencies & imports - Ensure `get_attachments_batch` is imported where needed. In `main.py` it is likely already imported (used in feed). In `profile/index.py` add from `devplacepy.services.attachments` (or similar) – verify existing pattern. ### Pre-existing environment note The test and lint commands (`pip install -e '.[dev] -q && make test-unit` and `ruff check .`) may fail under default Python due to PEP 668. A virtual environment must be used. The implementation plan includes the following steps to ensure the verification commands run cleanly (to be executed by the automation agent): - Activate the project’s existing virtual environment (if any) or create one. - Ensure `make test-unit` runs inside that venv. - Run `ruff check .` and verify that any errors are only pre-existing (e.g., F401 in `routers/messages.py`) and not introduced by this change. ### Definition of Done - [ ] The landing page (`/`) renders post attachments (images, videos) inside the post cards. - [ ] The profile page (`/profile/{username}?tab=posts`) renders post attachments in the “Posts” tab. - [ ] No new lint errors are introduced (existing pre‑existing errors are acceptable but documented). - [ ] The command `make test-unit` passes (exit 0) when run inside a working virtual environment. - [ ] The command `ruff check .` passes (exit 0) – or if pre‑existing errors remain, a diff shows zero new violations on the four modified files. - [ ] All modified Python files compile cleanly (`python3 -m py_compile ` returns 0).