Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import traceback | |
| from lib.common.database_support import add_user_to_excel, get_user_by_id, update_user_in_excel | |
| def render_user_profile(): | |
| try: | |
| excel_file = st.session_state.get("excel_file", "Error Not Found") | |
| if excel_file == "Error Not Found": | |
| raise Exception("Error Not Found") | |
| st.title("User Profile") | |
| user_id = st.session_state.get("user_id") | |
| if not user_id: | |
| st.warning("Please fill in your profile information to continue.") | |
| user_data = {'name': '', 'email': '', 'company': '', 'role': ''} | |
| else: | |
| user_data = get_user_by_id(excel_file, user_id) | |
| with st.form("user_form"): | |
| name = st.text_input("Name", value=user_data['name']) | |
| email = st.text_input("Email", value=user_data['email']) | |
| company = st.text_input("Company", value=user_data['company']) | |
| role = st.text_input("Role", value=user_data['role']) | |
| submitted = st.form_submit_button("Save Profile") | |
| if submitted: | |
| updated_user_data = {'name': name, 'email': email, 'company': company, 'role': role} | |
| if user_id: | |
| update_user_in_excel(excel_file, user_id, updated_user_data) | |
| st.success("Profile updated successfully!") | |
| else: | |
| user_id = add_user_to_excel(excel_file, updated_user_data) | |
| st.session_state['user_id'] = user_id | |
| st.success("Profile saved! You can now access other features.") | |
| st.session_state['user_email'] = email | |
| st.rerun() | |
| except Exception as err: | |
| traceback.print_exc() | |
| print(err) | |