Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,10 +23,6 @@ def load_user_details():
|
|
23 |
user_details = pd.DataFrame(columns=['username', 'password'])
|
24 |
return user_details
|
25 |
|
26 |
-
# Save user details to CSV
|
27 |
-
def save_user_details(user_details):
|
28 |
-
user_details.to_csv('details.csv', index=False)
|
29 |
-
|
30 |
# Check for system availability
|
31 |
def has_system_availability(schedule_data, class_selected, day_selected, start_time_selected, system_selected):
|
32 |
bookings = schedule_data[
|
@@ -76,28 +72,8 @@ if 'is_admin' not in st.session_state:
|
|
76 |
st.session_state.is_admin = False
|
77 |
if 'page' not in st.session_state:
|
78 |
st.session_state.page = "login"
|
79 |
-
|
80 |
-
|
81 |
-
def register_page():
|
82 |
-
st.title("ثبت نام")
|
83 |
-
|
84 |
-
new_username = st.text_input("نام کاربری جدید")
|
85 |
-
new_password = st.text_input("رمز عبور جدید", type='password')
|
86 |
-
|
87 |
-
if st.button("ثبت نام"):
|
88 |
-
if new_username and new_password:
|
89 |
-
user_details = load_user_details()
|
90 |
-
|
91 |
-
if new_username in user_details['username'].values:
|
92 |
-
st.error("این نام کاربری قبلاً ثبت شده است.")
|
93 |
-
else:
|
94 |
-
new_user = pd.DataFrame([[new_username, new_password]], columns=['username', 'password'])
|
95 |
-
user_details = pd.concat([user_details, new_user], ignore_index=True)
|
96 |
-
save_user_details(user_details)
|
97 |
-
st.success("ثبت نام با موفقیت انجام شد! اکنون میتوانید وارد شوید.")
|
98 |
-
st.session_state.page = "login"
|
99 |
-
else:
|
100 |
-
st.error("لطفاً نام کاربری و رمز عبور را وارد کنید.")
|
101 |
|
102 |
# Login Page
|
103 |
def login_page():
|
@@ -114,16 +90,23 @@ def login_page():
|
|
114 |
) or (st.session_state.username == "armin" and st.session_state.password == "12345679"):
|
115 |
st.session_state.authenticated = True
|
116 |
st.session_state.is_admin = (st.session_state.username == "armin")
|
117 |
-
|
118 |
-
st.session_state.schedule_data = load_schedule()
|
119 |
-
st.session_state.page = "schedule"
|
120 |
st.experimental_rerun()
|
121 |
else:
|
122 |
st.error("نام کاربری یا رمز عبور اشتباه است. لطفا دوباره تلاش کنید.")
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
# Class Schedule Page
|
129 |
def schedule_page():
|
@@ -147,12 +130,12 @@ def schedule_page():
|
|
147 |
|
148 |
if st.button("اضافه کردن کلاس"):
|
149 |
class_datetime = get_class_datetime(day_selected, start_time_selected)
|
150 |
-
if class_datetime - datetime.now() < timedelta(hours=
|
151 |
st.error("کلاسها باید حداقل ۳۰ ساعت قبل رزرو شوند.")
|
152 |
elif not has_system_availability(st.session_state.schedule_data, class_selected, day_selected, start_time_selected, system_selected):
|
153 |
st.error(f"سیستم '{system_selected}' در زمان '{start_time_selected}' در روز '{day_selected}' برای '{class_selected}' موجود نیست.")
|
154 |
else:
|
155 |
-
new_row = pd.DataFrame([[class_selected, day_selected, start_time_selected, st.session_state.
|
156 |
st.session_state.schedule_data = pd.concat([st.session_state.schedule_data, new_row], ignore_index=True)
|
157 |
save_schedule(st.session_state.schedule_data)
|
158 |
st.success(f"کلاس {class_selected} با موفقیت اضافه شد به {system_selected}.")
|
@@ -161,7 +144,7 @@ def schedule_page():
|
|
161 |
st.subheader("حذف کلاس")
|
162 |
if not st.session_state.schedule_data.empty and 'Username' in st.session_state.schedule_data.columns:
|
163 |
user_classes = st.session_state.schedule_data[
|
164 |
-
(st.session_state.schedule_data['Username'] == st.session_state.
|
165 |
st.session_state.is_admin
|
166 |
]
|
167 |
if not user_classes.empty:
|
@@ -183,7 +166,7 @@ def schedule_page():
|
|
183 |
(st.session_state.schedule_data['Day'] == day_to_remove) &
|
184 |
(st.session_state.schedule_data['Start Time'] == time_to_remove) &
|
185 |
(st.session_state.schedule_data['System'] == system_to_remove) &
|
186 |
-
((st.session_state.is_admin) or (st.session_state.schedule_data['Username'] == st.session_state.
|
187 |
)]
|
188 |
save_schedule(st.session_state.schedule_data)
|
189 |
st.success(f"کلاس {class_to_remove} در روز {day_to_remove} ساعت {time_to_remove} با موفقیت حذف شد.")
|
@@ -200,14 +183,15 @@ def schedule_page():
|
|
200 |
st.session_state['username'] = ""
|
201 |
st.session_state['password'] = ""
|
202 |
st.session_state['is_admin'] = False
|
|
|
203 |
st.session_state.page = "login"
|
204 |
st.experimental_rerun()
|
205 |
|
206 |
# Page navigation
|
207 |
if st.session_state.page == "login":
|
208 |
login_page()
|
209 |
-
elif st.session_state.page == "
|
210 |
-
|
211 |
elif st.session_state.page == "schedule":
|
212 |
if st.session_state['authenticated']:
|
213 |
schedule_page()
|
|
|
23 |
user_details = pd.DataFrame(columns=['username', 'password'])
|
24 |
return user_details
|
25 |
|
|
|
|
|
|
|
|
|
26 |
# Check for system availability
|
27 |
def has_system_availability(schedule_data, class_selected, day_selected, start_time_selected, system_selected):
|
28 |
bookings = schedule_data[
|
|
|
72 |
st.session_state.is_admin = False
|
73 |
if 'page' not in st.session_state:
|
74 |
st.session_state.page = "login"
|
75 |
+
if 'user_display_name' not in st.session_state:
|
76 |
+
st.session_state.user_display_name = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
# Login Page
|
79 |
def login_page():
|
|
|
90 |
) or (st.session_state.username == "armin" and st.session_state.password == "12345679"):
|
91 |
st.session_state.authenticated = True
|
92 |
st.session_state.is_admin = (st.session_state.username == "armin")
|
93 |
+
st.session_state.page = "enter_name"
|
|
|
|
|
94 |
st.experimental_rerun()
|
95 |
else:
|
96 |
st.error("نام کاربری یا رمز عبور اشتباه است. لطفا دوباره تلاش کنید.")
|
97 |
+
|
98 |
+
# Name Entry Page
|
99 |
+
def name_entry_page():
|
100 |
+
st.title("ورود نام کاربر")
|
101 |
+
|
102 |
+
st.session_state.user_display_name = st.text_input("لطفاً نام خود را وارد کنید")
|
103 |
+
|
104 |
+
if st.button("تایید"):
|
105 |
+
if st.session_state.user_display_name:
|
106 |
+
st.session_state.page = "schedule"
|
107 |
+
st.experimental_rerun()
|
108 |
+
else:
|
109 |
+
st.error("لطفاً نام خود را وارد کنید.")
|
110 |
|
111 |
# Class Schedule Page
|
112 |
def schedule_page():
|
|
|
130 |
|
131 |
if st.button("اضافه کردن کلاس"):
|
132 |
class_datetime = get_class_datetime(day_selected, start_time_selected)
|
133 |
+
if class_datetime - datetime.now() < timedelta(hours=24):
|
134 |
st.error("کلاسها باید حداقل ۳۰ ساعت قبل رزرو شوند.")
|
135 |
elif not has_system_availability(st.session_state.schedule_data, class_selected, day_selected, start_time_selected, system_selected):
|
136 |
st.error(f"سیستم '{system_selected}' در زمان '{start_time_selected}' در روز '{day_selected}' برای '{class_selected}' موجود نیست.")
|
137 |
else:
|
138 |
+
new_row = pd.DataFrame([[class_selected, day_selected, start_time_selected, st.session_state.user_display_name, system_selected]], columns=['Class', 'Day', 'Start Time', 'Username', 'System'])
|
139 |
st.session_state.schedule_data = pd.concat([st.session_state.schedule_data, new_row], ignore_index=True)
|
140 |
save_schedule(st.session_state.schedule_data)
|
141 |
st.success(f"کلاس {class_selected} با موفقیت اضافه شد به {system_selected}.")
|
|
|
144 |
st.subheader("حذف کلاس")
|
145 |
if not st.session_state.schedule_data.empty and 'Username' in st.session_state.schedule_data.columns:
|
146 |
user_classes = st.session_state.schedule_data[
|
147 |
+
(st.session_state.schedule_data['Username'] == st.session_state.user_display_name) |
|
148 |
st.session_state.is_admin
|
149 |
]
|
150 |
if not user_classes.empty:
|
|
|
166 |
(st.session_state.schedule_data['Day'] == day_to_remove) &
|
167 |
(st.session_state.schedule_data['Start Time'] == time_to_remove) &
|
168 |
(st.session_state.schedule_data['System'] == system_to_remove) &
|
169 |
+
((st.session_state.is_admin) or (st.session_state.schedule_data['Username'] == st.session_state.user_display_name))
|
170 |
)]
|
171 |
save_schedule(st.session_state.schedule_data)
|
172 |
st.success(f"کلاس {class_to_remove} در روز {day_to_remove} ساعت {time_to_remove} با موفقیت حذف شد.")
|
|
|
183 |
st.session_state['username'] = ""
|
184 |
st.session_state['password'] = ""
|
185 |
st.session_state['is_admin'] = False
|
186 |
+
st.session_state['user_display_name'] = ""
|
187 |
st.session_state.page = "login"
|
188 |
st.experimental_rerun()
|
189 |
|
190 |
# Page navigation
|
191 |
if st.session_state.page == "login":
|
192 |
login_page()
|
193 |
+
elif st.session_state.page == "enter_name":
|
194 |
+
name_entry_page()
|
195 |
elif st.session_state.page == "schedule":
|
196 |
if st.session_state['authenticated']:
|
197 |
schedule_page()
|