Adds Underwriter's carousel and admin features
This commit is contained in:
+52
-1
@@ -15,7 +15,7 @@ from sqlalchemy import select
|
||||
|
||||
from app.database import async_session
|
||||
from app.models import Show, ShowSchedule, Event, StationConfig
|
||||
from app.models import HistoryEntry, TeamMember, CommunityHighlight
|
||||
from app.models import HistoryEntry, TeamMember, CommunityHighlight, Underwriter
|
||||
|
||||
# ── Seed data ──────────────────────────────────────────────
|
||||
|
||||
@@ -300,6 +300,38 @@ COMMUNITY_HIGHLIGHTS: list[dict] = [
|
||||
]
|
||||
|
||||
|
||||
UNDERWRITERS: list[dict] = [
|
||||
{
|
||||
"name": "Mountain View Credit Union",
|
||||
"description": "Proudly serving the mountain communities since 1952. Your local financial partner for savings, loans, and community investment.",
|
||||
"logo_url": None,
|
||||
"website_url": "https://example-mvcu.org",
|
||||
"display_order": 1,
|
||||
},
|
||||
{
|
||||
"name": "Highland Medical Center",
|
||||
"description": "Compassionate healthcare for every ridge and valley. From urgent care to wellness programs, we keep our community healthy.",
|
||||
"logo_url": None,
|
||||
"website_url": "https://example-highlandmedical.org",
|
||||
"display_order": 2,
|
||||
},
|
||||
{
|
||||
"name": "Pine Street Hardware",
|
||||
"description": "Family-owned since 1978. Everything you need for home improvement, outdoor living, and mountain-ready repairs.",
|
||||
"logo_url": None,
|
||||
"website_url": "https://example-pinestreet.com",
|
||||
"display_order": 3,
|
||||
},
|
||||
{
|
||||
"name": "Summit Valley Farm",
|
||||
"description": "Organic produce, fresh eggs, and seasonal CSA shares. Bringing farm-to-table flavor to the mountain towns since 2005.",
|
||||
"logo_url": None,
|
||||
"website_url": "https://example-summitvalley.com",
|
||||
"display_order": 4,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# ── Helpers ────────────────────────────────────────────────
|
||||
|
||||
async def _upsert_event(session, data: dict) -> None:
|
||||
@@ -399,6 +431,19 @@ async def _upsert_community_highlight(session, data: dict) -> None:
|
||||
session.add(CommunityHighlight(**data, active=True))
|
||||
|
||||
|
||||
async def _upsert_underwriter(session, data: dict) -> None:
|
||||
"""Get-or-create an underwriter matched on name."""
|
||||
existing = await session.execute(
|
||||
select(Underwriter).where(Underwriter.name == data["name"])
|
||||
)
|
||||
uw = existing.scalar_one_or_none()
|
||||
if uw:
|
||||
for key, value in data.items():
|
||||
setattr(uw, key, value)
|
||||
else:
|
||||
session.add(Underwriter(**data, active=True))
|
||||
|
||||
|
||||
# ── Main ──────────────────────────────────────────────────
|
||||
|
||||
async def seed() -> None:
|
||||
@@ -428,6 +473,11 @@ async def seed() -> None:
|
||||
await session.commit()
|
||||
print(f" ✓ Seeded {len(COMMUNITY_HIGHLIGHTS)} community highlights")
|
||||
|
||||
for data in UNDERWRITERS:
|
||||
await _upsert_underwriter(session, data)
|
||||
await session.commit()
|
||||
print(f" ✓ Seeded {len(UNDERWRITERS)} underwriters")
|
||||
|
||||
# Make a copy since _upsert_show mutates the dict (pops 'schedules')
|
||||
import copy
|
||||
for data in copy.deepcopy(SHOWS):
|
||||
@@ -447,6 +497,7 @@ async def truncate_all() -> None:
|
||||
await session.execute(HistoryEntry.__table__.delete())
|
||||
await session.execute(TeamMember.__table__.delete())
|
||||
await session.execute(CommunityHighlight.__table__.delete())
|
||||
await session.execute(Underwriter.__table__.delete())
|
||||
await session.commit()
|
||||
print(" ✓ Truncated all tables")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user