Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +24 -10
- config_manager.py +73 -1
app.py
CHANGED
|
@@ -857,7 +857,11 @@ def create_new_user_and_wedding():
|
|
| 857 |
'wedding_events': events
|
| 858 |
}
|
| 859 |
|
| 860 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 861 |
initial_data_files = {
|
| 862 |
'guest_list_data.json': {},
|
| 863 |
'rsvp_data.json': {},
|
|
@@ -866,14 +870,18 @@ def create_new_user_and_wedding():
|
|
| 866 |
'wedding_party.json': []
|
| 867 |
}
|
| 868 |
|
| 869 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 870 |
if config_manager.google_drive_enabled:
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
|
| 878 |
# Update session state auth config
|
| 879 |
st.session_state.auth_config = auth_config
|
|
@@ -1120,8 +1128,14 @@ def show_main_app(authenticator):
|
|
| 1120 |
st.session_state.app_initialized = True
|
| 1121 |
st.session_state.last_user_folder = user_folder
|
| 1122 |
else:
|
| 1123 |
-
|
| 1124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1125 |
|
| 1126 |
# Load config
|
| 1127 |
config = st.session_state.config_manager.load_config()
|
|
|
|
| 857 |
'wedding_events': events
|
| 858 |
}
|
| 859 |
|
| 860 |
+
# Store wedding config in session state for immediate use
|
| 861 |
+
# The files will be created on-demand when the user first accesses the app
|
| 862 |
+
st.session_state[f'wedding_config_{account_info["username"]}'] = wedding_config
|
| 863 |
+
|
| 864 |
+
# Create initial data files structure (will be created on first use)
|
| 865 |
initial_data_files = {
|
| 866 |
'guest_list_data.json': {},
|
| 867 |
'rsvp_data.json': {},
|
|
|
|
| 870 |
'wedding_party.json': []
|
| 871 |
}
|
| 872 |
|
| 873 |
+
# Store initial data in session state
|
| 874 |
+
for filename, data in initial_data_files.items():
|
| 875 |
+
st.session_state[f'{filename}_{account_info["username"]}'] = data
|
| 876 |
+
|
| 877 |
+
# Try to upload wedding config to Google Drive (this is the most important file)
|
| 878 |
if config_manager.google_drive_enabled:
|
| 879 |
+
if config_manager.drive_manager.upload_file(f'{wedding_folder}/wedding_config.json', wedding_config):
|
| 880 |
+
st.success("✅ Wedding configuration saved to Google Drive!")
|
| 881 |
+
else:
|
| 882 |
+
st.warning("⚠️ Could not upload wedding config to Google Drive due to storage quota limitations. Your data is saved locally and will sync when you first use the app.")
|
| 883 |
+
|
| 884 |
+
st.info("💡 **Note**: Your wedding data files will be created automatically when you first add guests, tasks, or vendors. This approach works better with Google Drive storage limitations.")
|
| 885 |
|
| 886 |
# Update session state auth config
|
| 887 |
st.session_state.auth_config = auth_config
|
|
|
|
| 1128 |
st.session_state.app_initialized = True
|
| 1129 |
st.session_state.last_user_folder = user_folder
|
| 1130 |
else:
|
| 1131 |
+
# Check if this is a new user who just signed up
|
| 1132 |
+
if 'wedding_config_' + username in st.session_state:
|
| 1133 |
+
st.info("🎉 Welcome! Your wedding planner is ready. Your data will be saved to Google Drive when you first add content or manually sync.")
|
| 1134 |
+
st.session_state.app_initialized = True
|
| 1135 |
+
st.session_state.last_user_folder = user_folder
|
| 1136 |
+
else:
|
| 1137 |
+
st.error("Failed to load wedding data. Please try logging in again or contact support.")
|
| 1138 |
+
return
|
| 1139 |
|
| 1140 |
# Load config
|
| 1141 |
config = st.session_state.config_manager.load_config()
|
config_manager.py
CHANGED
|
@@ -573,13 +573,85 @@ class ConfigManager:
|
|
| 573 |
|
| 574 |
self.data_loaded_from_drive = True
|
| 575 |
return True
|
| 576 |
-
|
|
|
|
|
|
|
|
|
|
| 577 |
except Exception as e:
|
| 578 |
print(f"Error loading existing data from Google Drive: {e}")
|
| 579 |
# This is a common issue on Hugging Face Spaces due to network/SSL issues
|
| 580 |
# The error is expected and the user can retry manually
|
| 581 |
return False
|
| 582 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
def load_demo_data_from_drive(self):
|
| 584 |
"""Load demo wedding data from Google Drive and enable demo mode"""
|
| 585 |
if not self.google_drive_enabled:
|
|
|
|
| 573 |
|
| 574 |
self.data_loaded_from_drive = True
|
| 575 |
return True
|
| 576 |
+
|
| 577 |
+
# If no config found in Google Drive, check if this is a new user with data in session state
|
| 578 |
+
return self.load_new_user_data_from_session()
|
| 579 |
+
|
| 580 |
except Exception as e:
|
| 581 |
print(f"Error loading existing data from Google Drive: {e}")
|
| 582 |
# This is a common issue on Hugging Face Spaces due to network/SSL issues
|
| 583 |
# The error is expected and the user can retry manually
|
| 584 |
return False
|
| 585 |
|
| 586 |
+
def load_new_user_data_from_session(self):
|
| 587 |
+
"""Load new user data from session state (for users who just signed up)"""
|
| 588 |
+
try:
|
| 589 |
+
# Get current username from session state
|
| 590 |
+
username = st.session_state.get('username')
|
| 591 |
+
if not username:
|
| 592 |
+
return False
|
| 593 |
+
|
| 594 |
+
# Check if we have wedding config for this user in session state
|
| 595 |
+
config_key = f'wedding_config_{username}'
|
| 596 |
+
if config_key in st.session_state:
|
| 597 |
+
config_content = st.session_state[config_key]
|
| 598 |
+
|
| 599 |
+
# Save config locally (in memory or file)
|
| 600 |
+
if self.use_memory_storage:
|
| 601 |
+
self.memory_data['wedding_config.json'] = config_content
|
| 602 |
+
# Update cache in session state
|
| 603 |
+
st.session_state['cached_wedding_config'] = config_content
|
| 604 |
+
print("Stored new user wedding_config.json in memory")
|
| 605 |
+
else:
|
| 606 |
+
config_path = self.get_config_file_path()
|
| 607 |
+
config_dir = os.path.dirname(config_path)
|
| 608 |
+
if config_dir:
|
| 609 |
+
os.makedirs(config_dir, exist_ok=True)
|
| 610 |
+
with open(config_path, 'w') as f:
|
| 611 |
+
json.dump(config_content, f, indent=2)
|
| 612 |
+
# Update cache in session state
|
| 613 |
+
st.session_state['cached_wedding_config'] = config_content
|
| 614 |
+
print(f"Stored new user wedding_config.json in file: {config_path}")
|
| 615 |
+
|
| 616 |
+
# Load data files from session state
|
| 617 |
+
data_files = [
|
| 618 |
+
'guest_list_data.json',
|
| 619 |
+
'rsvp_data.json',
|
| 620 |
+
'tasks.json',
|
| 621 |
+
'vendors.json',
|
| 622 |
+
'wedding_party.json'
|
| 623 |
+
]
|
| 624 |
+
|
| 625 |
+
for file_name in data_files:
|
| 626 |
+
data_key = f'{file_name}_{username}'
|
| 627 |
+
if data_key in st.session_state:
|
| 628 |
+
content = st.session_state[data_key]
|
| 629 |
+
if self.use_memory_storage:
|
| 630 |
+
self.memory_data[file_name] = content
|
| 631 |
+
# Update cache in session state
|
| 632 |
+
cache_key = f"cached_{file_name}"
|
| 633 |
+
st.session_state[cache_key] = content
|
| 634 |
+
print(f"Stored new user {file_name} in memory")
|
| 635 |
+
else:
|
| 636 |
+
file_path = self.get_data_file_path(file_name)
|
| 637 |
+
file_dir = os.path.dirname(file_path)
|
| 638 |
+
if file_dir:
|
| 639 |
+
os.makedirs(file_dir, exist_ok=True)
|
| 640 |
+
with open(file_path, 'w') as f:
|
| 641 |
+
json.dump(content, f, indent=2)
|
| 642 |
+
# Update cache in session state
|
| 643 |
+
cache_key = f"cached_{file_name}"
|
| 644 |
+
st.session_state[cache_key] = content
|
| 645 |
+
print(f"Stored new user {file_name} in file: {file_path}")
|
| 646 |
+
|
| 647 |
+
self.data_loaded_from_drive = True
|
| 648 |
+
return True
|
| 649 |
+
|
| 650 |
+
return False
|
| 651 |
+
except Exception as e:
|
| 652 |
+
print(f"Error loading new user data from session: {e}")
|
| 653 |
+
return False
|
| 654 |
+
|
| 655 |
def load_demo_data_from_drive(self):
|
| 656 |
"""Load demo wedding data from Google Drive and enable demo mode"""
|
| 657 |
if not self.google_drive_enabled:
|