working basic site admin
This commit is contained in:
+39
-1
@@ -14,7 +14,7 @@ from datetime import date
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.database import async_session
|
||||
from app.models import Program, Event, DonationTier
|
||||
from app.models import Program, Event, DonationTier, StationConfig
|
||||
|
||||
# ── Seed data ──────────────────────────────────────────────
|
||||
|
||||
@@ -93,6 +93,26 @@ TIERS: list[dict] = [
|
||||
},
|
||||
]
|
||||
|
||||
STATION_CONFIG: dict = {
|
||||
"key": "default",
|
||||
"callsign": "KMTN",
|
||||
"name_primary": "KMountain",
|
||||
"name_secondary": "Flower Radio",
|
||||
"tagline": "Community Radio — Est. 1987",
|
||||
"frequency": "98.7 FM",
|
||||
"founded_year": 1987,
|
||||
"nonprofit_type": "501(c)(3)",
|
||||
"ein": "84-XXXXXXX",
|
||||
"logo_url": "svg/small-flower.svg",
|
||||
"hero_background_url": "svg/mountain-landscape.svg",
|
||||
"hero_icon_url": "svg/orange-flower.svg",
|
||||
"hero_divider_url": "svg/mountain-divider.svg",
|
||||
"address": "42 Pine Street\nMountain View, CO 80424",
|
||||
"phone": "(970) 555-0198",
|
||||
"email": "hello@kmountainflower.org",
|
||||
"website": "kmountainflower.org",
|
||||
}
|
||||
|
||||
|
||||
# ── Helpers ────────────────────────────────────────────────
|
||||
|
||||
@@ -141,6 +161,19 @@ async def _upsert_tier(session, data: dict) -> None:
|
||||
session.add(DonationTier(**data))
|
||||
|
||||
|
||||
async def _upsert_station_config(session, data: dict) -> None:
|
||||
"""Get-or-create the singleton station config (key='default')."""
|
||||
existing = await session.execute(
|
||||
select(StationConfig).where(StationConfig.key == "default")
|
||||
)
|
||||
config = existing.scalar_one_or_none()
|
||||
if config:
|
||||
for key, value in data.items():
|
||||
setattr(config, key, value)
|
||||
else:
|
||||
session.add(StationConfig(**data))
|
||||
|
||||
|
||||
# ── Main ──────────────────────────────────────────────────
|
||||
|
||||
async def seed() -> None:
|
||||
@@ -161,6 +194,10 @@ async def seed() -> None:
|
||||
await session.commit()
|
||||
print(f" ✓ Seeded {len(TIERS)} donation tiers")
|
||||
|
||||
await _upsert_station_config(session, STATION_CONFIG)
|
||||
await session.commit()
|
||||
print(" ✓ Seeded station config")
|
||||
|
||||
|
||||
async def truncate_all() -> None:
|
||||
"""Remove all seed data from the database."""
|
||||
@@ -168,6 +205,7 @@ async def truncate_all() -> None:
|
||||
await session.execute(Program.__table__.delete())
|
||||
await session.execute(Event.__table__.delete())
|
||||
await session.execute(DonationTier.__table__.delete())
|
||||
await session.execute(StationConfig.__table__.delete())
|
||||
await session.commit()
|
||||
print(" ✓ Truncated all tables")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user