YFDashboard / src /pages /99_Admin_Simulation.py
Jon Solow
Add league selector to admin page
991e6b5
raw
history blame
1.22 kB
import streamlit as st
from config import DEFAULT_ICON, SEASON
from shared_page import common_page_config
from login_component import is_token_in_session
@st.cache_resource(ttl=60 * 60 * 24)
def get_all_league_settings_with_cache(season: int):
return st.session_state.yahoo_client.get_all_logged_in_user_league_settings(season=season)
def get_page():
page_title = "Yahoo FF League Simulation - ADMIN"
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
common_page_config()
st.title(page_title)
if not is_token_in_session():
st.write("You must be a site admin in order to use this feature." " Please click Login button above.")
elif st.session_state.user_admin is not True:
st.write("You must be a site admin in order to use this feature.")
else:
selected_season = st.selectbox("Select Season", list(range(SEASON, 2012, -1)))
user_leagues = get_all_league_settings_with_cache(season=selected_season)
selected_league = st.selectbox("Select league", user_leagues, format_func=lambda x: x.name)
st.header(f"{selected_league.name} - {selected_league.season}")
if __name__ == "__main__":
get_page()