Spaces:
Running
Running
axeronis
Implement Admin Dashboard 2.0: Analytics, Partner Management, Impersonation, and Announcements
1b99aeb Download backend/app/api/system.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/api/system.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/app/api/system.py
-
curl -L -o system.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/api/system.py
1.11 kB
| from fastapi import APIRouter, Depends | |
| from sqlmodel import select | |
| from sqlmodel.ext.asyncio.session import AsyncSession | |
| from typing import List | |
| from datetime import datetime | |
| from app.core.database import get_async_session | |
| from app.models.system import SystemAnnouncement | |
| router = APIRouter(prefix="/system", tags=["System"]) | |
| async def get_active_announcements( | |
| session: AsyncSession = Depends(get_async_session) | |
| ): | |
| """ | |
| Get active system announcements for all users. | |
| """ | |
| now = datetime.utcnow() | |
| # Explicitly check is_active AND (expires_at is null OR expires_at > now) | |
| statement = select(SystemAnnouncement).where( | |
| SystemAnnouncement.is_active == True | |
| ) | |
| result = await session.execute(statement) | |
| announcements = result.scalars().all() | |
| # Filter by expiration in python if complex OR condition is annoying in SQLModel | |
| active = [] | |
| for a in announcements: | |
| if a.expires_at is None or a.expires_at > now: | |
| active.append(a) | |
| return active | |