Project 30: Admin Dashboard
Python Challenge
Builds on these lessons
Step 1 of 2
Project
Assembling the Dashboard Module
This is the capstone: combine the month's patterns into one real module. A dataclass for a metric (Day 8), a custom exception hierarchy for dashboard errors (Day 21), logging instead of print (Day 19), and secrets read from the environment (Day 29) — all in one admin_dashboard.py.
🎯 Your Task
Please add the exact code shown in the light gray box below to your editor.Do not delete your previous code, just insert these new lines in the correct place!
import os
import logging
from dataclasses import dataclass
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class DashboardError(Exception):
pass
@dataclass
class Metric:
label: str
value: float
def load_metrics():
db_url = os.environ.get("DATABASE_URL")
if not db_url:
raise DashboardError("DATABASE_URL is not configured")
logger.info("Loading dashboard metrics")
return [Metric("Total Users", 4210), Metric("Revenue", 52600)]
try:
metrics = load_metrics()
for m in metrics:
print(f"{m.label}: {m.value}")
except DashboardError as e:
logger.error(f"Dashboard failed to load: {e}")← Previous
Next →