-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
179 lines (153 loc) · 7.09 KB
/
app.py
File metadata and controls
179 lines (153 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
from dotenv import load_dotenv
import streamlit as st
import streamlit_authenticator as stauth
from pages.analytics_dashboard.analytics_home import analytics_home
from pages.analytics_dashboard.individual_applicants import applicants_page
from pages.interview_statuses_pages.interview_status import view_interview_status
from pages.session_management.hr import hr_page
from pages.session_management.update_data import update_page
from pages.home.Home import intro_page, home_page
from controllers.home import download_and_update_latest_data
from utilities.mongo_db.streamlit_mongo_wrapper import get_all_session_names, get_session_data
import os
load_dotenv()
credentials = {
'usernames': {
'admin': {
'email': st.secrets['credentials']['usernames']['admin']['email'],
'name': st.secrets['credentials']['usernames']['admin']['name'],
'password': st.secrets['credentials']['usernames']['admin']['password']
}
}
}
authenticator = stauth.Authenticate(
credentials,
st.secrets['cookie']['name'],
st.secrets['cookie']['key'],
st.secrets['cookie']['expiry_days'],
st.secrets['preauthorized']
)
def auth_page():
name, st.session_state["authentication_status"], username = authenticator.login('main')
if st.session_state["authentication_status"]:
st.rerun()
elif st.session_state["authentication_status"] == False:
st.error('Username/password is incorrect')
if st.session_state["authentication_status"]:
logout_button = st.sidebar.button("Logout")
if logout_button:
st.session_state["on_page"] = None
st.session_state["authentication_status"] = None
st.rerun()
if "on_page" not in st.session_state.keys():
st.session_state["on_page"] = None
intro_page()
header_1, header_2 = st.sidebar.columns(2)
header_1.write("**دادرس**")
header_2.caption("Daadras ATS")
# Get a list of all sessions from mongo_store
session_names = get_all_session_names()
if "current_page" not in st.session_state.keys():
st.session_state["current_page"] = "Intro"
# Update sessions list
session_selector = st.sidebar.selectbox(
"Select Session",
session_names,
index=None,
key='selection',
)
access_button = st.sidebar.button("Access", type="primary")
if access_button:
st.session_state["current_page"] = "access_project"
st.session_state["project_sessions"] = session_names
if session_selector is not None and st.session_state["current_page"] == "access_project":
st.session_state["current_session_name"] = session_selector
st.session_state["current_session_data"] = {
"session_information": get_session_data(session_selector),
"category_data": download_and_update_latest_data()
}
st.sidebar.divider()
home_button = st.sidebar.button(label="Home", use_container_width=True)
if home_button:
st.session_state["on_page"] = "Home"
home_page()
# Create columns dynamically based on number of categories
num_categories = len(st.session_state["current_session_data"]["category_data"])
cols = st.sidebar.columns(num_categories, gap="small")
# Dictionary to store expanders and buttons
expanders = {}
buttons = {}
# Create expanders and buttons for each category
for i, (category, data) in enumerate(st.session_state["current_session_data"]["category_data"].items()):
category_upper = category.upper()
expanders[category] = cols[i].popover(category_upper, use_container_width=True)
with expanders[category]:
# Create home and applicant buttons for this category
buttons[f"{category}_home"] = st.button(
label="Home",
use_container_width=True,
key=f"{category}_button"
)
buttons[f"{category}_applicant"] = st.button(
label="Individual Applicants",
use_container_width=True,
key=f"{category}_applicant"
)
st.sidebar.caption("Interviews")
int_sch, int_app = st.sidebar.columns(2)
interview_scheduled = int_sch.button("Scheduled", use_container_width=True)
interview_approved = int_app.button("Approved", use_container_width=True)
st.sidebar.caption("Applicants")
acc, rej = st.sidebar.columns(2)
accepted = acc.button("Accepted", use_container_width=True)
rejected = rej.button("Rejected", use_container_width=True)
##################################################### Named Categories #####################################################
# Handle button clicks
for category, data in st.session_state["current_session_data"]["category_data"].items():
if buttons[f"{category}_home"]:
st.session_state["on_page"] = f"{category.upper()}_home"
break
elif buttons[f"{category}_applicant"]:
st.session_state["on_page"] = category.upper()
break
else:
if accepted:
st.session_state["on_page"] = "Accepted"
elif rejected:
st.session_state["on_page"] = "Rejected"
elif interview_scheduled:
st.session_state["on_page"] = "Scheduled"
elif interview_approved:
st.session_state["on_page"] = "Approved"
st.sidebar.divider()
st.sidebar.caption("HR")
if st.sidebar.button(label="Session Management"):
st.session_state["on_page"] = "HR"
if st.sidebar.button(label="Update Data"):
st.session_state["on_page"] = "Updater"
##################################################### Named Categories #####################################################
# Handle page navigation dynamically
if st.session_state["on_page"] is not None:
if st.session_state["on_page"].endswith("_home"):
# Handle analytics home pages
analytics_home(category=st.session_state["on_page"][:-5].lower())
elif "current_session_data" in st.session_state and st.session_state["on_page"].lower() in [cat for cat in st.session_state["current_session_data"]["category_data"].keys()]:
# Handle individual applicant pages
applicants_page(category=st.session_state["on_page"].lower())
else:
# Handle other pages
match st.session_state["on_page"]:
case "Accepted":
view_interview_status(status="Accepted")
case "Rejected":
view_interview_status(status="Rejected")
case "Scheduled":
view_interview_status(status="Interview_Scheduled")
case "Approved":
view_interview_status(status="Interview_Approved")
case "HR":
hr_page()
case "Updater":
update_page()
else:
auth_page()