Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,10 +9,10 @@ st.set_page_config(page_title="نظام إدارة الشكاوى", layout="cent
|
|
| 9 |
# تحميل أو إنشاء ملف CSV
|
| 10 |
file_path = "complaints.csv"
|
| 11 |
if os.path.exists(file_path):
|
| 12 |
-
df = pd.read_csv(file_path)
|
| 13 |
else:
|
| 14 |
df = pd.DataFrame(columns=["complaint_id", "username", "complaint_text", "status", "response", "timestamp"])
|
| 15 |
-
df.to_csv(file_path, index=False)
|
| 16 |
|
| 17 |
# -----------------------------------------
|
| 18 |
# تهيئة session state
|
|
@@ -56,7 +56,7 @@ if not st.session_state.is_logged_in:
|
|
| 56 |
st.warning("❌ اسم المستخدم غير موجود.")
|
| 57 |
|
| 58 |
# -----------------------------------------
|
| 59 |
-
#
|
| 60 |
elif st.session_state.user_type == "sender":
|
| 61 |
st.title("📨 تقديم شكوى")
|
| 62 |
complaint_text = st.text_area("وصف الشكوى")
|
|
@@ -68,20 +68,26 @@ elif st.session_state.user_type == "sender":
|
|
| 68 |
complaint_id = f"{prefix}_{next_id:06}"
|
| 69 |
|
| 70 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 71 |
-
new_complaint = {
|
| 72 |
-
"complaint_id": complaint_id,
|
| 73 |
-
"username": st.session_state.username,
|
| 74 |
-
"complaint_text": complaint_text,
|
| 75 |
-
"status": "Pending",
|
| 76 |
-
"response": "",
|
| 77 |
-
"timestamp": timestamp
|
| 78 |
-
}
|
| 79 |
-
df = pd.concat([df, pd.DataFrame([new_complaint])], ignore_index=True)
|
| 80 |
-
df.to_csv(file_path, index=False)
|
| 81 |
-
st.success("✅ تم تقديم الشكوى بنجاح")
|
| 82 |
-
st.rerun()
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
user_complaints = df[df["username"] == st.session_state.username]
|
| 86 |
if not user_complaints.empty:
|
| 87 |
last_complaint = user_complaints.iloc[-1]
|
|
@@ -96,16 +102,15 @@ elif st.session_state.user_type == "sender":
|
|
| 96 |
if st.button("🚪 تسجيل الخروج"):
|
| 97 |
st.session_state.is_logged_in = False
|
| 98 |
st.session_state.user_type = None
|
| 99 |
-
st.session_state.username = ""
|
| 100 |
st.rerun()
|
| 101 |
|
| 102 |
# -----------------------------------------
|
| 103 |
-
#
|
| 104 |
elif st.session_state.user_type == "receiver":
|
| 105 |
st.title("📬 إدارة الشكاوى")
|
| 106 |
|
| 107 |
if df.empty:
|
| 108 |
-
st.info("
|
| 109 |
else:
|
| 110 |
current_count = len(df)
|
| 111 |
new_complaints = current_count - st.session_state.last_seen_count
|
|
@@ -114,15 +119,11 @@ elif st.session_state.user_type == "receiver":
|
|
| 114 |
st.session_state.last_seen_count = current_count
|
| 115 |
|
| 116 |
st.subheader("📋 جميع الشكاوى")
|
| 117 |
-
selected_index = st.selectbox(
|
| 118 |
-
"اختر شكوى للتعامل معها",
|
| 119 |
-
df.index,
|
| 120 |
-
format_func=lambda i: f"{df.loc[i, 'complaint_id']} - {df.loc[i, 'username']}"
|
| 121 |
-
)
|
| 122 |
selected_row = df.loc[selected_index]
|
| 123 |
|
| 124 |
st.write(f"### ✉️ شكوى: {selected_row['complaint_id']}")
|
| 125 |
-
st.write(f"
|
| 126 |
st.write(f"**الوصف:** {selected_row['complaint_text']}")
|
| 127 |
|
| 128 |
new_status = st.selectbox("🔄 تحديث الحالة", ["Pending", "In Progress", "Resolved"], index=["Pending", "In Progress", "Resolved"].index(selected_row["status"]))
|
|
@@ -131,7 +132,7 @@ elif st.session_state.user_type == "receiver":
|
|
| 131 |
if st.button("💾 حفظ التعديلات"):
|
| 132 |
df.at[selected_index, "status"] = new_status
|
| 133 |
df.at[selected_index, "response"] = new_response
|
| 134 |
-
df.to_csv(file_path, index=False)
|
| 135 |
st.success("✅ تم حفظ التع��يلات")
|
| 136 |
st.rerun()
|
| 137 |
|
|
|
|
| 9 |
# تحميل أو إنشاء ملف CSV
|
| 10 |
file_path = "complaints.csv"
|
| 11 |
if os.path.exists(file_path):
|
| 12 |
+
df = pd.read_csv(file_path, encoding='utf-8-sig')
|
| 13 |
else:
|
| 14 |
df = pd.DataFrame(columns=["complaint_id", "username", "complaint_text", "status", "response", "timestamp"])
|
| 15 |
+
df.to_csv(file_path, index=False, encoding='utf-8-sig')
|
| 16 |
|
| 17 |
# -----------------------------------------
|
| 18 |
# تهيئة session state
|
|
|
|
| 56 |
st.warning("❌ اسم المستخدم غير موجود.")
|
| 57 |
|
| 58 |
# -----------------------------------------
|
| 59 |
+
# مقدم الشكوى
|
| 60 |
elif st.session_state.user_type == "sender":
|
| 61 |
st.title("📨 تقديم شكوى")
|
| 62 |
complaint_text = st.text_area("وصف الشكوى")
|
|
|
|
| 68 |
complaint_id = f"{prefix}_{next_id:06}"
|
| 69 |
|
| 70 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
# التحقق من التكرار
|
| 73 |
+
if not ((df["username"] == st.session_state.username) & (df["complaint_text"] == complaint_text)).any():
|
| 74 |
+
new_complaint = {
|
| 75 |
+
"complaint_id": complaint_id,
|
| 76 |
+
"username": st.session_state.username,
|
| 77 |
+
"complaint_text": complaint_text,
|
| 78 |
+
"status": "Pending",
|
| 79 |
+
"response": "",
|
| 80 |
+
"timestamp": timestamp
|
| 81 |
+
}
|
| 82 |
+
df = pd.concat([df, pd.DataFrame([new_complaint])], ignore_index=True)
|
| 83 |
+
df.to_csv(file_path, index=False, encoding='utf-8-sig')
|
| 84 |
+
st.success("✅ تم تقديم الشكوى بنجاح")
|
| 85 |
+
st.experimental_set_query_params(clear=True)
|
| 86 |
+
st.rerun()
|
| 87 |
+
else:
|
| 88 |
+
st.warning("⚠️ تم إرسال هذه الشكوى بالفعل من قبل.")
|
| 89 |
+
|
| 90 |
+
# إشعار بتحديث حالة الشكوى أو الرد
|
| 91 |
user_complaints = df[df["username"] == st.session_state.username]
|
| 92 |
if not user_complaints.empty:
|
| 93 |
last_complaint = user_complaints.iloc[-1]
|
|
|
|
| 102 |
if st.button("🚪 تسجيل الخروج"):
|
| 103 |
st.session_state.is_logged_in = False
|
| 104 |
st.session_state.user_type = None
|
|
|
|
| 105 |
st.rerun()
|
| 106 |
|
| 107 |
# -----------------------------------------
|
| 108 |
+
# مستقبل الشكوى
|
| 109 |
elif st.session_state.user_type == "receiver":
|
| 110 |
st.title("📬 إدارة الشكاوى")
|
| 111 |
|
| 112 |
if df.empty:
|
| 113 |
+
st.info("لا توجد شكاوى حالياً للتعامل معها.")
|
| 114 |
else:
|
| 115 |
current_count = len(df)
|
| 116 |
new_complaints = current_count - st.session_state.last_seen_count
|
|
|
|
| 119 |
st.session_state.last_seen_count = current_count
|
| 120 |
|
| 121 |
st.subheader("📋 جميع الشكاوى")
|
| 122 |
+
selected_index = st.selectbox("اختر شكوى للتعامل معها", df.index, format_func=lambda i: f"{df.loc[i, 'complaint_id']} - {df.loc[i, 'username']}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
selected_row = df.loc[selected_index]
|
| 124 |
|
| 125 |
st.write(f"### ✉️ شكوى: {selected_row['complaint_id']}")
|
| 126 |
+
st.write(f"**مقدم الشكوى:** {selected_row['username']}")
|
| 127 |
st.write(f"**الوصف:** {selected_row['complaint_text']}")
|
| 128 |
|
| 129 |
new_status = st.selectbox("🔄 تحديث الحالة", ["Pending", "In Progress", "Resolved"], index=["Pending", "In Progress", "Resolved"].index(selected_row["status"]))
|
|
|
|
| 132 |
if st.button("💾 حفظ التعديلات"):
|
| 133 |
df.at[selected_index, "status"] = new_status
|
| 134 |
df.at[selected_index, "response"] = new_response
|
| 135 |
+
df.to_csv(file_path, index=False, encoding='utf-8-sig')
|
| 136 |
st.success("✅ تم حفظ التع��يلات")
|
| 137 |
st.rerun()
|
| 138 |
|