Hadeeratef91 commited on
Commit
af89786
·
verified ·
1 Parent(s): 120f885

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -39
app.py CHANGED
@@ -60,45 +60,18 @@ if not st.session_state.is_logged_in:
60
  elif st.session_state.user_type == "sender":
61
  complaint_text = st.text_area("📝 وصف الشكوى", key="complaint_input")
62
 
63
- if st.button("📤 إرسال الشكوى"):
64
- existing_user_complaints = df[df["username"] == st.session_state.username]
65
- if st.session_state["complaint_input"].strip() in existing_user_complaints["complaint_text"].values:
66
- st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا!")
67
- elif st.session_state["complaint_input"].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": st.session_state["complaint_input"].strip(),
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
- # إعادة تعيين القيمة عبر طريقة rerun الآمنة:
86
- st.session_state["complaint_input"] = ""
87
- st.rerun()
88
-
89
-
90
 
91
- complaint_text = st.text_area("📝 وصف الشكوى", key="complaint_input")
92
- if st.button("📤 إرسال الشكوى"):
93
- existing_user_complaints = df[df["username"] == st.session_state.username]
94
- if complaint_text.strip() in existing_user_complaints["complaint_text"].values:
95
- st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا!")
96
  elif complaint_text.strip() == "":
97
  st.warning("⚠️ الرجاء إدخال نص الشكوى.")
98
  else:
99
- prefix = st.session_state.username[:4].lower()
100
- next_id = len(existing_user_complaints) + 1
101
- complaint_id = f"{prefix}_{next_id:06}"
102
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
103
  new_complaint = {
104
  "complaint_id": complaint_id,
@@ -119,13 +92,15 @@ if st.button("📤 إرسال الشكوى"):
119
  st.subheader("📋 الشكاوى السابقة")
120
  for i, row in user_complaints[::-1].iterrows():
121
  with st.expander(f"📨 {row['complaint_id']} | {row['status']}"):
122
- new_text = st.text_area("📝 تعديل الشكوى", value=row['complaint_text'], key=f"edit_{i}")
123
- if st.button("💾 حفظ التعديل", key=f"save_{i}"):
124
- df.at[i, "complaint_text"] = new_text.strip()
125
- df.to_csv(file_path, index=False, encoding='utf-8-sig')
126
- st.success(" تم تعديل الشكوى بنجاح")
127
- st.rerun()
128
- if row["status"].lower() != "pending" or (pd.notna(row["response"]) and row["response"].strip() != ""):
 
 
129
  st.info(f"📢 تم تحديث حالة الشكوى إلى: {row['status']}")
130
  if row["response"].strip():
131
  st.success(f"💬 الرد: {row['response']}")
 
60
  elif st.session_state.user_type == "sender":
61
  complaint_text = st.text_area("📝 وصف الشكوى", key="complaint_input")
62
 
63
+ if st.button("📤 إرسال الشكوى"):
64
+ existing_user_complaints = df[df["username"] == st.session_state.username]
 
 
 
 
 
65
  prefix = st.session_state.username[:4].lower()
66
  next_id = len(existing_user_complaints) + 1
67
  complaint_id = f"{prefix}_{next_id:06}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ # التحقق من تكرار معرف الشكوى فقط
70
+ if complaint_id in df["complaint_id"].values:
71
+ st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا بناءً على المعرف!")
 
 
72
  elif complaint_text.strip() == "":
73
  st.warning("⚠️ الرجاء إدخال نص الشكوى.")
74
  else:
 
 
 
75
  timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
76
  new_complaint = {
77
  "complaint_id": complaint_id,
 
92
  st.subheader("📋 الشكاوى السابقة")
93
  for i, row in user_complaints[::-1].iterrows():
94
  with st.expander(f"📨 {row['complaint_id']} | {row['status']}"):
95
+ # السماح بالتعديل فقط إذا كانت الشكوى لم يتم الرد عليها
96
+ if row["status"].lower() == "pending" and (pd.isna(row["response"]) or row["response"].strip() == ""):
97
+ new_text = st.text_area("📝 تعديل الشكوى", value=row['complaint_text'], key=f"edit_{i}")
98
+ if st.button("💾 حفظ التعديل", key=f"save_{i}"):
99
+ df.at[i, "complaint_text"] = new_text.strip()
100
+ df.to_csv(file_path, index=False, encoding='utf-8-sig')
101
+ st.success(" تم تعديل الشكوى بنجاح")
102
+ st.rerun()
103
+ else:
104
  st.info(f"📢 تم تحديث حالة الشكوى إلى: {row['status']}")
105
  if row["response"].strip():
106
  st.success(f"💬 الرد: {row['response']}")