Spaces:
Sleeping
Sleeping
Download app.py from fuerr18/job-admin-panel: direct link, hf CLI and curl.
- Browser
- Download file 7.74 kB
-
https://huggingface.co/spaces/fuerr18/job-admin-panel/resolve/main/app.py
- Command line
-
hf download hf://spaces/fuerr18/job-admin-panel/app.py
-
curl -L -o app.py https://huggingface.co/spaces/fuerr18/job-admin-panel/resolve/main/app.py
7.74 kB
| import streamlit as st | |
| import firebase_admin | |
| from firebase_admin import credentials, firestore | |
| from datetime import datetime | |
| import os | |
| import json | |
| # 1. تنسيق الواجهة | |
| st.set_page_config(page_title="لوحة الناشرين - فرصة عمل", layout="centered") | |
| st.markdown(""" | |
| <style> | |
| .stApp { direction: rtl; text-align: right; } | |
| [data-testid="stHeader"], [data-testid="stToolbar"] { display: none !important; } | |
| #MainMenu, footer { visibility: hidden; } | |
| input, select, textarea { text-align: right !important; direction: rtl !important; } | |
| .stButton>button { width: 100%; border-radius: 10px; background-color: #28B463; color: white; font-weight: bold; } | |
| .link-box { | |
| background-color: #f0f2f6; | |
| padding: 20px; | |
| border-radius: 10px; | |
| border: 1px solid #d1d3d8; | |
| text-align: center; | |
| margin-bottom: 30px; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # 2. تهيئة Firebase | |
| if not firebase_admin._apps: | |
| try: | |
| firebase_json = os.environ.get("FIREBASE") | |
| if firebase_json: | |
| cred_dict = json.loads(firebase_json) | |
| cred = credentials.Certificate(cred_dict) | |
| firebase_admin.initialize_app(cred) | |
| else: | |
| st.error("خطأ في إعدادات FIREBASE.") | |
| st.stop() | |
| except Exception as e: | |
| st.error(f"خطأ في الربط: {e}") | |
| st.stop() | |
| db = firestore.client() | |
| # session state للتنقل بين الصفحات | |
| if "page" not in st.session_state: | |
| st.session_state.page = "login" | |
| # session state لحفظ اختيار الفئة خارج الفورم | |
| if "category_choice" not in st.session_state: | |
| st.session_state.category_choice = "خريج" | |
| # ========================================== | |
| # الصفحة الأولى: تسجيل الدخول | |
| # ========================================== | |
| def show_login_page(): | |
| st.markdown("<h1 style='text-align: center; color: #1D8348;'>لوحة نشر الإعلانات</h1>", unsafe_allow_html=True) | |
| st.markdown(f""" | |
| <div class="link-box"> | |
| <p style="font-size: 18px; font-weight: bold;">ليس لديك حساب؟ قم بملء الإستمارة أولاً:</p> | |
| <a href="https://docs.google.com/forms/d/e/1FAIpQLSe8diAuMlAHSuYQWsXvFov7EGygF8ZLf_Ojf3prF0sZvrFG0A/viewform?usp=publish-editor" | |
| target="_blank" | |
| style="background-color: #1D8348; color: white; padding: 12px 25px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block; margin-top: 10px;"> | |
| اضغط هنا لتسجيل الدخول وملء الإستمارة | |
| </a> | |
| </div> | |
| """, unsafe_allow_html=True) | |
| st.markdown("---") | |
| if st.button("المتابعة لنشر إعلان"): | |
| st.session_state.page = "publish" | |
| st.rerun() | |
| # ========================================== | |
| # الصفحة الثانية: نشر الإعلان (مع إصلاح مشكلة الفئة) | |
| # ========================================== | |
| def show_publish_page(): | |
| st.markdown("<h1 style='text-align: center; color: #1D8348;'>تفاصيل الوظيفة المطلوبة</h1>", unsafe_allow_html=True) | |
| # اختيار الفئة خارج الفورم عشان يتغير فوراً | |
| st.session_state.category_choice = st.radio( | |
| "فئة الوظيفة", | |
| ["خريج", "عامل"], | |
| horizontal=True, | |
| index=0 if st.session_state.category_choice == "خريج" else 1 | |
| ) | |
| # selectbox يتغير بناءً على الاختيار فوراً | |
| if st.session_state.category_choice == "خريج": | |
| spec = st.selectbox("التخصص الأكاديمي المطلوب", ["إدارة وأقتصاد", "هندسة", "تقنية معلومات", "تربية", "قانون", "لغات", "أخرى"]) | |
| else: | |
| spec = st.selectbox("المهنة المطلوبة", ["عامل", "كاشير", "حلاق", "خباز", "سائق", "توصيل", "أخرى"]) | |
| # باقي الحقول في فورم | |
| with st.form("admin_publish_form", clear_on_submit=True): | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| shop_name = st.text_input("اسم المحل / الشركة") | |
| job_title = st.text_input("المسمى الوظيفي (مثلاً: كاشير، مهندس)") | |
| req_gender = st.selectbox("الجنس المطلوب", ["ذكر", "أنثى", "كلاهما"]) | |
| with col2: | |
| req_age = st.text_input("العمر المطلوب (مثلاً: 20-30)") | |
| location = st.text_input("موقع العمل (المحافظة/المنطقة)") | |
| salary = st.text_input("الراتب المتوقع") | |
| phone = st.text_input("رقم هاتف صاحب العمل (للتواصل المباشر)") | |
| secret_key = st.text_input("كلمة سر خاصة بك (لتعديل أو حذف اعلانك لاحقاً") | |
| details = st.text_area("وصف الوظيفة وشروط إضافية") | |
| if st.form_submit_button("نشر الإعلان الآن"): | |
| if shop_name and job_title and phone: | |
| db.collection("vacancies").add({ | |
| "shop": shop_name, | |
| "job": job_title, | |
| "gender": req_gender, | |
| "age": req_age, | |
| "category": st.session_state.category_choice, | |
| "spec": spec, | |
| "location": location, | |
| "salary": salary, | |
| "phone": phone, | |
| "secret_key" : secret_key, | |
| "details": details, | |
| "timestamp": datetime.now() | |
| }) | |
| st.balloons() | |
| st.success("تم النشر بنجاح!") | |
| else: | |
| st.warning("يرجى ملء الحقول الأساسية (الاسم، الوظيفة، الهاتف)") | |
| st.markdown("---") | |
| st.subheader("الإعلانات المنشورة حديثاً") | |
| st.subheader("إدارة إعلاناتي") | |
| mgmt_phone = st.text_input("رقم هاتفك", key="mgmt_phone") | |
| mgmt_key = st.text_input("كلمة السر", type="password", key="mgmt_key") | |
| if st.button("بحث عن إعلاناتي"): | |
| results = db.collection("vacancies")\ | |
| .where("phone", "==", mgmt_phone)\ | |
| .where("secret_key", "==", mgmt_key).stream() | |
| for doc in results: | |
| data = doc.to_dict() | |
| st.write(f" {data.get('job')} في {data.get('shop')}") | |
| if st.button("حذف", key=f"del_{doc.id}"): | |
| db.collection("vacancies").document(doc.id).delete() | |
| st.rerun() | |
| if st.button("تعديل", key=f"edit_{doc.id}"): | |
| st.session_state["edit_id"] = doc.id | |
| st.session_state["edit_data"] = data | |
| st.rerun() | |
| if st.button("تحديث القائمة"): | |
| ads = db.collection("vacancies").order_by("timestamp", direction=firestore.Query.DESCENDING).limit(10).stream() | |
| for ad in ads: | |
| data = ad.to_dict() | |
| with st.expander(f" {data.get('job')} في {data.get('shop')}"): | |
| st.write(f"المكان: {data.get('location')}") | |
| if st.button(f"حذف الإعلان", key=ad.id): | |
| db.collection("vacancies").document(ad.id).delete() | |
| st.rerun() | |
| if st.button("رجوع"): | |
| st.session_state.page = "login" | |
| st.rerun() | |
| # ========================================== | |
| # التوجيه بين الصفحات | |
| # ========================================== | |
| if st.session_state.page == "login": | |
| show_login_page() | |
| else: | |
| show_publish_page() |