Jon Solow commited on
Commit
991e6b5
·
1 Parent(s): 70e2402

Add league selector to admin page

Browse files
Files changed (1) hide show
  1. src/pages/99_Admin_Simulation.py +12 -4
src/pages/99_Admin_Simulation.py CHANGED
@@ -1,11 +1,16 @@
1
  import streamlit as st
2
 
3
- from config import DEFAULT_ICON
4
  from shared_page import common_page_config
5
 
6
  from login_component import is_token_in_session
7
 
8
 
 
 
 
 
 
9
  def get_page():
10
  page_title = "Yahoo FF League Simulation - ADMIN"
11
  st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
@@ -14,11 +19,14 @@ def get_page():
14
 
15
  if not is_token_in_session():
16
  st.write("You must be a site admin in order to use this feature." " Please click Login button above.")
17
- elif not st.session_state.user_admin:
18
  st.write("You must be a site admin in order to use this feature.")
19
-
20
  else:
21
- st.write("Logged in. Feature to go here")
 
 
 
 
22
 
23
 
24
  if __name__ == "__main__":
 
1
  import streamlit as st
2
 
3
+ from config import DEFAULT_ICON, SEASON
4
  from shared_page import common_page_config
5
 
6
  from login_component import is_token_in_session
7
 
8
 
9
+ @st.cache_resource(ttl=60 * 60 * 24)
10
+ def get_all_league_settings_with_cache(season: int):
11
+ return st.session_state.yahoo_client.get_all_logged_in_user_league_settings(season=season)
12
+
13
+
14
  def get_page():
15
  page_title = "Yahoo FF League Simulation - ADMIN"
16
  st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON, layout="wide")
 
19
 
20
  if not is_token_in_session():
21
  st.write("You must be a site admin in order to use this feature." " Please click Login button above.")
22
+ elif st.session_state.user_admin is not True:
23
  st.write("You must be a site admin in order to use this feature.")
 
24
  else:
25
+
26
+ selected_season = st.selectbox("Select Season", list(range(SEASON, 2012, -1)))
27
+ user_leagues = get_all_league_settings_with_cache(season=selected_season)
28
+ selected_league = st.selectbox("Select league", user_leagues, format_func=lambda x: x.name)
29
+ st.header(f"{selected_league.name} - {selected_league.season}")
30
 
31
 
32
  if __name__ == "__main__":