data driven about us screen
This commit is contained in:
+149
@@ -15,6 +15,7 @@ from sqlalchemy import select
|
||||
|
||||
from app.database import async_session
|
||||
from app.models import Program, Event, DonationTier, StationConfig
|
||||
from app.models import HistoryEntry, TeamMember, CommunityHighlight
|
||||
|
||||
# ── Seed data ──────────────────────────────────────────────
|
||||
|
||||
@@ -113,6 +114,91 @@ STATION_CONFIG: dict = {
|
||||
"website": "kmountainflower.org",
|
||||
}
|
||||
|
||||
HISTORY_ENTRIES: list[dict] = [
|
||||
{
|
||||
"year": 1987,
|
||||
"title": "The Idea Takes Root",
|
||||
"body": "A small group of mountain residents gathered around a kitchen table with a shared dream: a radio station owned by the community, for the community. With nothing but conviction and a stack of handwritten letters to the FCC, they began the long road toward bringing independent radio to the high country.",
|
||||
"display_order": 1,
|
||||
},
|
||||
{
|
||||
"year": 1991,
|
||||
"title": "FCC License Granted",
|
||||
"body": "After years of paperwork, public hearings, and grassroots fundraising, the Federal Communications Commission approved the construction permit. The call sign KMTN was chosen — a nod to the mountain terrain that defines the region and the people who call it home.",
|
||||
"display_order": 2,
|
||||
},
|
||||
{
|
||||
"year": 1995,
|
||||
"title": "First Broadcast",
|
||||
"body": "On a crisp September morning, KMTN signed on the air for the first time. The opening broadcast featured a live bluegrass set from the studio, followed by interviews with local farmers, teachers, and business owners. The signal reached every valley and ridge within a 40-mile radius.",
|
||||
"display_order": 3,
|
||||
},
|
||||
{
|
||||
"year": 2008,
|
||||
"title": "Studio Expansion",
|
||||
"body": "A generous community-driven capital campaign funded the construction of a new broadcast studio — doubling production space and adding a dedicated live-performance room. The expansion also brought upgraded transmission equipment, extending the station's reach to surrounding counties.",
|
||||
"display_order": 4,
|
||||
},
|
||||
]
|
||||
|
||||
TEAM_MEMBERS: list[dict] = [
|
||||
{
|
||||
"name": "Margaret Ellis",
|
||||
"title": "Board Chair",
|
||||
"bio": "Margaret has served on the KMTN board for over fifteen years. A retired schoolteacher, she believes community radio is the backbone of civic engagement.",
|
||||
"photo_url": None,
|
||||
"display_order": 1,
|
||||
},
|
||||
{
|
||||
"name": "James Whitfield",
|
||||
"title": "General Manager",
|
||||
"bio": "James joined KMTN as a volunteer DJ in 2002 and has been steering the station's operations ever since. He oversees programming, finance, and community outreach.",
|
||||
"photo_url": None,
|
||||
"display_order": 2,
|
||||
},
|
||||
{
|
||||
"name": "Dr. Priya Nair",
|
||||
"title": "Program Director",
|
||||
"bio": "Dr. Nair brings two decades of media experience to KMTN. She curates the station's diverse lineup and mentors the next generation of local broadcasters.",
|
||||
"photo_url": None,
|
||||
"display_order": 3,
|
||||
},
|
||||
{
|
||||
"name": "Carlos Mendez",
|
||||
"title": "Community Outreach Coordinator",
|
||||
"bio": "Carlos organizes station events, volunteer drives, and school partnerships. His Evening Echoes show is one of the station's most-listened-to programs.",
|
||||
"photo_url": None,
|
||||
"display_order": 4,
|
||||
},
|
||||
]
|
||||
|
||||
COMMUNITY_HIGHLIGHTS: list[dict] = [
|
||||
{
|
||||
"icon": "🎵",
|
||||
"title": "Our Music",
|
||||
"description": "From bluegrass and folk to jazz and classical, our playlists reflect the rich cultural tapestry of the high country and its neighbors. We feature local artists alongside the world's best voices.",
|
||||
"display_order": 1,
|
||||
},
|
||||
{
|
||||
"icon": "🤝",
|
||||
"title": "Our Community",
|
||||
"description": "Every show is staffed by volunteers who live and work in these mountains. From high school DJs to retired teachers, our team is your community — passionate about sharing what they love.",
|
||||
"display_order": 2,
|
||||
},
|
||||
{
|
||||
"icon": "📡",
|
||||
"title": "Our Reach",
|
||||
"description": "Over the air on 98.7 FM and streaming live worldwide. Whether you're hiking the ridgeline or on the other side of the planet, our signal — and our welcome — goes everywhere.",
|
||||
"display_order": 3,
|
||||
},
|
||||
{
|
||||
"icon": "🌱",
|
||||
"title": "Our Mission",
|
||||
"description": "To keep public radio free, independent, and deeply rooted in place. No corporate advertising, no spin — just music, conversation, and community served with care.",
|
||||
"display_order": 4,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
# ── Helpers ────────────────────────────────────────────────
|
||||
|
||||
@@ -174,6 +260,51 @@ async def _upsert_station_config(session, data: dict) -> None:
|
||||
session.add(StationConfig(**data))
|
||||
|
||||
|
||||
async def _upsert_history_entry(session, data: dict) -> None:
|
||||
"""Get-or-create a history entry matched on (year, title)."""
|
||||
existing = await session.execute(
|
||||
select(HistoryEntry).where(
|
||||
HistoryEntry.year == data["year"],
|
||||
HistoryEntry.title == data["title"],
|
||||
)
|
||||
)
|
||||
entry = existing.scalar_one_or_none()
|
||||
if entry:
|
||||
for key, value in data.items():
|
||||
setattr(entry, key, value)
|
||||
else:
|
||||
session.add(HistoryEntry(**data, active=True))
|
||||
|
||||
|
||||
async def _upsert_team_member(session, data: dict) -> None:
|
||||
"""Get-or-create a team member matched on name."""
|
||||
existing = await session.execute(
|
||||
select(TeamMember).where(TeamMember.name == data["name"])
|
||||
)
|
||||
member = existing.scalar_one_or_none()
|
||||
if member:
|
||||
for key, value in data.items():
|
||||
setattr(member, key, value)
|
||||
else:
|
||||
session.add(TeamMember(**data, active=True))
|
||||
|
||||
|
||||
async def _upsert_community_highlight(session, data: dict) -> None:
|
||||
"""Get-or-create a community highlight matched on (icon, title)."""
|
||||
existing = await session.execute(
|
||||
select(CommunityHighlight).where(
|
||||
CommunityHighlight.icon == data["icon"],
|
||||
CommunityHighlight.title == data["title"],
|
||||
)
|
||||
)
|
||||
highlight = existing.scalar_one_or_none()
|
||||
if highlight:
|
||||
for key, value in data.items():
|
||||
setattr(highlight, key, value)
|
||||
else:
|
||||
session.add(CommunityHighlight(**data, active=True))
|
||||
|
||||
|
||||
# ── Main ──────────────────────────────────────────────────
|
||||
|
||||
async def seed() -> None:
|
||||
@@ -198,6 +329,21 @@ async def seed() -> None:
|
||||
await session.commit()
|
||||
print(" ✓ Seeded station config")
|
||||
|
||||
for data in HISTORY_ENTRIES:
|
||||
await _upsert_history_entry(session, data)
|
||||
await session.commit()
|
||||
print(f" ✓ Seeded {len(HISTORY_ENTRIES)} history entries")
|
||||
|
||||
for data in TEAM_MEMBERS:
|
||||
await _upsert_team_member(session, data)
|
||||
await session.commit()
|
||||
print(f" ✓ Seeded {len(TEAM_MEMBERS)} team members")
|
||||
|
||||
for data in COMMUNITY_HIGHLIGHTS:
|
||||
await _upsert_community_highlight(session, data)
|
||||
await session.commit()
|
||||
print(f" ✓ Seeded {len(COMMUNITY_HIGHLIGHTS)} community highlights")
|
||||
|
||||
|
||||
async def truncate_all() -> None:
|
||||
"""Remove all seed data from the database."""
|
||||
@@ -206,6 +352,9 @@ async def truncate_all() -> None:
|
||||
await session.execute(Event.__table__.delete())
|
||||
await session.execute(DonationTier.__table__.delete())
|
||||
await session.execute(StationConfig.__table__.delete())
|
||||
await session.execute(HistoryEntry.__table__.delete())
|
||||
await session.execute(TeamMember.__table__.delete())
|
||||
await session.execute(CommunityHighlight.__table__.delete())
|
||||
await session.commit()
|
||||
print(" ✓ Truncated all tables")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user