Spaces:
Sleeping
Sleeping
Update app.py
Browse files59 unmodified lines6061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310414 unmodified lines11912012112212312412512612712812913013159 unmodified lineselif st.session_state.user_type == "sender":complaint_text = st.text_area("📝 وصف الشكوى", key="complaint_input")if st.button("📤 إرسال الشكوى"):existing_user_complaints = df[df["username"] == st.session_state.username]if st.session_state["complaint_input"].strip() in existing_user_complaints["complaint_text"].values:st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا!")elif st.session_state["complaint_input"].strip() == "":st.warning("⚠️ الرجاء إدخال نص الشكوى.")else:prefix = st.session_state.username[:4].lower()next_id = len(existing_user_complaints) + 1complaint_id = f"{prefix}_{next_id:06}"timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")new_complaint = {"complaint_id": complaint_id,"username": st.session_state.username,"complaint_text": st.session_state["complaint_input"].strip(),"status": "Pending","response": "","timestamp": timestamp}df = pd.concat([df, pd.DataFrame([new_complaint])], ignore_index=True)df.to_csv(file_path, index=False, encoding='utf-8-sig')st.success("✅ تم تقديم الشكوى بنجاح")# إعادة تعيين القيمة عبر طريقة rerun الآمنة:st.session_state["complaint_input"] = ""st.rerun()complaint_text = st.text_area("📝 وصف الشكوى", key="complaint_input")if st.button("📤 إرسال الشكوى"):existing_user_complaints = df[df["username"] == st.session_state.username]if complaint_text.strip() in existing_user_complaints["complaint_text"].values:st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا!")elif complaint_text.strip() == "":st.warning("⚠️ الرجاء إدخال نص الشكوى.")else:prefix = st.session_state.username[:4].lower()next_id = len(existing_user_complaints) + 1complaint_id = f"{prefix}_{next_id:06}"timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")new_complaint = {"complaint_id": complaint_id,14 unmodified linesst.subheader("📋 الشكاوى السابقة")for i, row in user_complaints[::-1].iterrows():with st.expander(f"📨 {row['complaint_id']} | {row['status']}"):new_text = st.text_area("📝 تعديل الشكوى", value=row['complaint_text'], key=f"edit_{i}")if st.button("💾 حفظ التعديل", key=f"save_{i}"):df.at[i, "complaint_text"] = new_text.strip()df.to_csv(file_path, index=False, encoding='utf-8-sig')st.success("✅ تم تعديل الشكوى بنجاح")st.rerun()if row["status"].lower() != "pending" or (pd.notna(row["response"]) and row["response"].strip() != ""):st.info(f"📢 تم تحديث حالة الشكوى إلى: {row['status']}")if row["response"].strip():st.success(f"💬 الرد: {row['response']}")59 unmodified lines60616263646566676869707172737475767714 unmodified lines929394959697989910010110210310410510659 unmodified lineselif st.session_state.user_type == "sender":complaint_text = st.text_area("📝 وصف الشكوى", key="complaint_input")if st.button("📤 إرسال الشكوى"):existing_user_complaints = df[df["username"] == st.session_state.username]prefix = st.session_state.username[:4].lower()next_id = len(existing_user_complaints) + 1complaint_id = f"{prefix}_{next_id:06}"# التحقق من تكرار معرف الشكوى فقطif complaint_id in df["complaint_id"].values:st.warning("⚠️ تم إرسال هذه الشكوى مسبقًا بناءً على المعرف!")elif complaint_text.strip() == "":st.warning("⚠️ الرجاء إدخال نص الشكوى.")else:timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")new_complaint = {"complaint_id": complaint_id,14 unmodified linesst.subheader("📋 الشكاوى السابقة")for i, row in user_complaints[::-1].iterrows():with st.expander(f"📨 {row['complaint_id']} | {row['status']}"):# السماح بالتعديل فقط إذا كانت الشكوى لم يتم الرد عليهاif row["status"].lower() == "pending" and (pd.isna(row["response"]) or row["response"].strip() == ""):new_text = st.text_area("📝 تعديل الشكوى", value=row['complaint_text'], key=f"edit_{i}")if st.button("💾 حفظ التعديل", key=f"save_{i}"):df.at[i, "complaint_text"] = new_text.strip()df.to_csv(file_path, index=False, encoding='utf-8-sig')st.success("✅ تم تعديل الشكوى بنجاح")st.rerun()else:st.info(f"📢 تم تحديث حالة الشكوى إلى: {row['status']}")if row["response"].strip():st.success(f"💬 الرد: {row['response']}")
app.py+14-39