Hadeeratef91 commited on
Commit
cc943af
·
verified ·
1 Parent(s): f706a69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -28
app.py CHANGED
@@ -59,22 +59,22 @@ if not st.session_state.is_logged_in:
59
  # مقدم الشكوى
60
  elif st.session_state.user_type == "sender":
61
  st.title("📨 تقديم شكوى")
62
- complaint_text = st.text_area("وصف الشكوى")
63
- if st.button("إرسال الشكوى"):
64
- user_id = st.session_state.username.split("_")[-1].upper()
65
- existing_ids = df[df["username"] == st.session_state.username]["complaint_id"]
66
- next_id = len(existing_ids) + 1
67
- prefix = st.session_state.username[:4].lower()
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
@@ -82,33 +82,35 @@ elif st.session_state.user_type == "sender":
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]
94
- if last_complaint["status"].lower() != "pending" or pd.notna(last_complaint["response"]):
95
- st.info(f"✅ تم تحديث حالة شكواك ({last_complaint['complaint_id']}) إلى: {last_complaint['status']}")
96
- if pd.notna(last_complaint["response"]) and last_complaint["response"].strip() != "":
97
- st.success(f"💬 تم الرد على شكواك: {last_complaint['response']}")
98
-
99
  st.subheader("📋 الشكاوى السابقة")
100
- st.dataframe(user_complaints[["complaint_id", "complaint_text", "status", "response", "timestamp"]], use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
101
 
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:
@@ -119,7 +121,12 @@ elif st.session_state.user_type == "receiver":
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']}")
@@ -131,7 +138,7 @@ elif st.session_state.user_type == "receiver":
131
 
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()
 
59
  # مقدم الشكوى
60
  elif st.session_state.user_type == "sender":
61
  st.title("📨 تقديم شكوى")
62
+ complaint_text = st.text_area("📝 وصف الشكوى", key="complaint_input")
63
+ if st.button("📤 إرسال الشكوى"):
64
+ existing_user_complaints = df[df["username"] == st.session_state.username]
65
+ if complaint_text.strip() in existing_user_complaints["complaint_text"].values:
66
+ st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا!")
67
+ elif complaint_text.strip() == "":
68
+ st.warning("⚠️ الرجاء إدخال نص الشكوى.")
69
+ else:
70
+ prefix = st.session_state.username[:4].lower()
71
+ next_id = len(existing_user_complaints) + 1
72
+ complaint_id = f"{prefix}_{next_id:06}"
73
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
74
  new_complaint = {
75
  "complaint_id": complaint_id,
76
  "username": st.session_state.username,
77
+ "complaint_text": complaint_text.strip(),
78
  "status": "Pending",
79
  "response": "",
80
  "timestamp": timestamp
 
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.session_state.complaint_input = ""
86
  st.rerun()
 
 
87
 
88
+ # عرض الشكاوى الخاصة بالمستخدم
89
  user_complaints = df[df["username"] == st.session_state.username]
 
 
 
 
 
 
 
90
  st.subheader("📋 الشكاوى السابقة")
91
+ for i, row in user_complaints[::-1].iterrows():
92
+ with st.expander(f"📨 {row['complaint_id']} | {row['status']}"):
93
+ new_text = st.text_area("📝 تعديل الشكوى", value=row['complaint_text'], key=f"edit_{i}")
94
+ if st.button("💾 حفظ التعديل", key=f"save_{i}"):
95
+ df.at[i, "complaint_text"] = new_text.strip()
96
+ df.to_csv(file_path, index=False, encoding='utf-8-sig')
97
+ st.success("✅ تم تعديل الشكوى بنجاح")
98
+ st.rerun()
99
+ if row["status"].lower() != "pending" or (pd.notna(row["response"]) and row["response"].strip() != ""):
100
+ st.info(f"📢 تم تحديث حالة الشكوى إلى: {row['status']}")
101
+ if row["response"].strip():
102
+ st.success(f"💬 الرد: {row['response']}")
103
 
104
  if st.button("🚪 تسجيل الخروج"):
105
  st.session_state.is_logged_in = False
106
  st.session_state.user_type = None
107
+ st.session_state.username = ""
108
  st.rerun()
109
 
110
  # -----------------------------------------
111
  # مستقبل الشكوى
112
  elif st.session_state.user_type == "receiver":
113
  st.title("📬 إدارة الشكاوى")
 
114
  if df.empty:
115
  st.info("لا توجد شكاوى حالياً للتعامل معها.")
116
  else:
 
121
  st.session_state.last_seen_count = current_count
122
 
123
  st.subheader("📋 جميع الشكاوى")
124
+ selected_index = st.selectbox(
125
+ "اختر شكوى للتعامل معها",
126
+ df.index,
127
+ format_func=lambda i: f"{df.loc[i, 'complaint_id']} - {df.loc[i, 'username']}",
128
+ key="select_complaint"
129
+ )
130
  selected_row = df.loc[selected_index]
131
 
132
  st.write(f"### ✉️ شكوى: {selected_row['complaint_id']}")
 
138
 
139
  if st.button("💾 حفظ التعديلات"):
140
  df.at[selected_index, "status"] = new_status
141
+ df.at[selected_index, "response"] = new_response.strip()
142
  df.to_csv(file_path, index=False, encoding='utf-8-sig')
143
  st.success("✅ تم حفظ التعديلات")
144
  st.rerun()