From ad95102ae97c41fe3bffa17e61c894bb10e746de Mon Sep 17 00:00:00 2001 From: Khaled Mahfouz Date: Thu, 12 Jun 2025 15:58:27 +0300 Subject: [PATCH] - version : 1.2 - description : adding a delete route and the corresponding button in the html file . --- app.py | 19 ++++++++++++ templates/index.html | 71 +++++++++++++++++++++++++++----------------- 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/app.py b/app.py index 1b723ed..7755bb2 100644 --- a/app.py +++ b/app.py @@ -214,6 +214,25 @@ def modify_student(student_id): return redirect(url_for('index')) +@app.route('/delete_student/', methods=['POST']) +def delete_student(student_id): + try: + with get_db_connection() as conn: + # First, check if the student exists + student = conn.execute('SELECT id FROM students WHERE id = ?', (student_id,)).fetchone() + if student is None: + flash('الطالب غير موجود.', 'danger') + return redirect(url_for('index')) + + conn.execute('DELETE FROM students WHERE id = ?', (student_id,)) + conn.commit() + flash('تم حذف الطالب بنجاح!', 'success') + except sqlite3.Error as e: + flash(f'خطأ في قاعدة البيانات أثناء الحذف: {str(e)}', 'danger') + except Exception as e: + flash(f'خطأ غير متوقع أثناء الحذف: {str(e)}', 'danger') + + return redirect(url_for('index')) @app.route('/import_csv', methods=['POST']) def import_csv(): diff --git a/templates/index.html b/templates/index.html index 4e72174..54ea812 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,7 +5,7 @@ {% block content %}
{# Removed mb-8 from header, now handled by h1 and nav #}

نظام إدارة الطلاب

{# Added mb-6 for spacing below title #} - + {# Navigation Bar - More Eye-Attractive Styling #}