mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-09-30 19:21:33 +02:00
Add a chronological, table-based print log as a 4th view mode in the Archives page. Log entries are stored in a separate print_log_entries table — clearing the log never touches archives or queue items. Backend: - New PrintLogEntry model with independent table - GET /print-log/ endpoint with search, printer, user, status, date filters - DELETE /print-log/ clears only log entries - Thumbnail serving endpoint for log entries - write_log_entry() service called on print completion - Auth: ARCHIVES_READ for viewing, ARCHIVES_DELETE_ALL for clearing Frontend: - New 'log' ViewMode with ClipboardList icon toggle - Filterable/searchable table with pagination (10/25/50/100 rows) - Colored status badges, duration formatting, filament color swatches - Clear button with confirmation modal - All filter state persisted to localStorage - i18n: EN, DE, JA, FR, IT translations
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
"""Service for writing independent print log entries.
|
|
|
|
Log entries are written to a separate table and never touch archives or queue items.
|
|
"""
|
|
|
|
import logging
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from backend.app.models.print_log import PrintLogEntry
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def write_log_entry(
|
|
db: AsyncSession,
|
|
*,
|
|
status: str,
|
|
print_name: str | None = None,
|
|
printer_name: str | None = None,
|
|
printer_id: int | None = None,
|
|
started_at: datetime | None = None,
|
|
completed_at: datetime | None = None,
|
|
filament_type: str | None = None,
|
|
filament_color: str | None = None,
|
|
filament_used_grams: float | None = None,
|
|
thumbnail_path: str | None = None,
|
|
created_by_username: str | None = None,
|
|
) -> PrintLogEntry:
|
|
"""Write a print log entry."""
|
|
duration = None
|
|
if started_at and completed_at:
|
|
duration = int((completed_at - started_at).total_seconds())
|
|
|
|
entry = PrintLogEntry(
|
|
print_name=print_name,
|
|
printer_name=printer_name,
|
|
printer_id=printer_id,
|
|
status=status,
|
|
started_at=started_at,
|
|
completed_at=completed_at,
|
|
duration_seconds=duration,
|
|
filament_type=filament_type,
|
|
filament_color=filament_color,
|
|
filament_used_grams=filament_used_grams,
|
|
thumbnail_path=thumbnail_path,
|
|
created_by_username=created_by_username,
|
|
)
|
|
db.add(entry)
|
|
await db.flush()
|
|
return entry
|