- version : 0.9

- description : adding an option to modify any student's info with
  seperate modify_info.html file and seperate route .
هذا الالتزام موجود في:
2025-06-11 19:22:28 +03:00
الأصل 731e45f75c
التزام 92f3222e1b
4 ملفات معدلة مع 184 إضافات و4 حذوفات

84
app.py
عرض الملف

@@ -7,7 +7,7 @@ from flask import Flask, render_template, request, redirect, url_for, flash, sen
# --- App Setup ---
app = Flask(__name__)
app.secret_key = 'your_super_secret_key_12345'
app.config['PHONE_REGEX'] = re.compile(r'^09\d{8}$') # Syrian phone format
app.config['PHONE_REGEX'] = re.compile(r'^09\d{8}$') # Syrian phone format
# --- Database Functions ---
def get_db_connection():
@@ -138,6 +138,83 @@ def add_student():
return redirect(url_for('index'))
@app.route('/modify_student/<int:student_id>', methods=['GET', 'POST'])
def modify_student(student_id):
if request.method == 'GET':
# Display the modification form
try:
with get_db_connection() as conn:
student = conn.execute('SELECT * FROM students WHERE id = ?', (student_id,)).fetchone()
if student is None:
flash('الطالب غير موجود.', 'danger')
return redirect(url_for('index'))
return render_template('modify_info.html', student=student)
except sqlite3.Error as e:
flash(f'خطأ في قاعدة البيانات: {str(e)}', 'danger')
return redirect(url_for('index'))
elif request.method == 'POST':
# Process the modification form submission
form_data = request.form
validation_errors = validate_student_data(form_data)
if validation_errors:
for error in validation_errors:
flash(error, 'danger')
# Fetch student again to re-render form with current data and errors
try:
with get_db_connection() as conn:
student = conn.execute('SELECT * FROM students WHERE id = ?', (student_id,)).fetchone()
return render_template('modify_info.html', student=student)
except sqlite3.Error as e:
flash(f'خطأ في قاعدة البيانات: {str(e)}', 'danger')
return redirect(url_for('index'))
try:
student_data = (
form_data['student_name'],
int(form_data['age']),
form_data['parent_name'],
form_data['parent_phone_1'],
form_data.get('parent_phone_2') or None,
form_data.get('student_phone') or None,
form_data['grade'],
form_data['school_name'],
form_data['address'],
form_data['memorizing'],
student_id # The ID is the last parameter for the WHERE clause
)
with get_db_connection() as conn:
conn.execute('''
UPDATE students SET
student_name = ?,
age = ?,
parent_name = ?,
parent_phone_1 = ?,
parent_phone_2 = ?,
student_phone = ?,
grade = ?,
school_name = ?,
address = ?,
memorizing = ?
WHERE id = ?
''', student_data)
conn.commit()
flash('تم تحديث بيانات الطالب بنجاح!', 'success')
return redirect(url_for('index'))
except sqlite3.IntegrityError 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():
if 'file' not in request.files:
@@ -202,11 +279,11 @@ def import_csv():
# Process validation results
if row_errors:
flash(f'تم العثور على أخطاء في {len(row_errors)} سطراً', 'warning')
for error in row_errors[:5]: # Show first 5 errors
for error in row_errors[:5]: # Show first 5 errors
flash(error, 'danger')
if len(row_errors) > 5:
flash(f'...و {len(row_errors)-5} أخطاء إضافية', 'danger')
if valid_rows:
with get_db_connection() as conn:
conn.executemany('''
@@ -248,3 +325,4 @@ def points():
if __name__ == '__main__':
app.run(debug=True)

عرض الملف

@@ -139,6 +139,7 @@
<th class="px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider">المدرسة</th>
<th class="px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider">العنوان</th>
<th class="px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider">المحفوظات</th>
<th class="px-6 py-3 text-xs font-medium text-gray-500 uppercase tracking-wider">الإجراءات</th> {# New header for actions #}
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-200" id="students-table-body">
@@ -159,6 +160,13 @@
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-600">{{ student['school_name'] }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-600">{{ student['address'] }}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-600">{{ student['memorizing'] }}</td>
{# New column for actions #}
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<a href="{{ url_for('modify_student', student_id=student['id']) }}" class="text-indigo-600 hover:text-indigo-900">
<i class="fas fa-pen"></i> {# Pen icon #}
</a>
{# You can add a delete button here later if needed #}
</td>
</tr>
{% else %}
<tr id="no-students-row">
@@ -183,7 +191,6 @@
const addManuallyButton = document.getElementById('add-manually-button');
const addStudentSection = document.getElementById('add-student-section');
const addStudentForm = document.getElementById('add-student-form');
const importForm = document.getElementById('import-form');
const submitAddButton = document.getElementById('submit-add-button');
// New elements for search functionality

عرض الملف

@@ -0,0 +1,93 @@
{% extends 'template.html' %}
{% block title %}تعديل معلومات الطالب{% endblock %}
{% block content %}
<header class="text-center">
<h1 class="text-3xl sm:text-4xl font-bold text-gray-900 mb-6">تعديل معلومات الطالب</h1>
{# Navigation Bar #}
<nav class="mb-8">
<ul class="flex justify-center space-x-4 space-x-reverse bg-white p-2 rounded-full shadow-lg inline-flex">
<li>
<a href="{{ url_for('index') }}" class="text-gray-700 hover:text-blue-700 hover:bg-blue-50 font-medium px-6 py-3 rounded-full transition-all duration-300 ease-in-out hover:shadow-sm transform hover:scale-105">الصفحة الرئيسية</a>
</li>
<li>
<a href="{{ url_for('record') }}" class="text-gray-700 hover:text-blue-700 hover:bg-blue-50 font-medium px-6 py-3 rounded-full transition-all duration-300 ease-in-out hover:shadow-sm transform hover:scale-105">تسجيل حضور أو حفظ</a>
</li>
<li>
<a href="{{ url_for('points') }}" class="text-gray-700 hover:text-blue-700 hover:bg-blue-50 font-medium px-6 py-3 rounded-full transition-all duration-300 ease-in-out hover:shadow-sm transform hover:scale-105">النقاط</a>
</li>
</ul>
</nav>
</header>
<div class="bg-white p-8 rounded-xl shadow-lg mb-8">
<h2 class="text-2xl font-semibold mb-6 text-gray-800 border-b pb-4">تعديل معلومات الطالب: {{ student.student_name }}</h2>
<form id="modify-student-form" action="{{ url_for('modify_student', student_id=student.id) }}" method="POST">
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-6">
<div>
<label for="student_name" class="block text-sm font-medium text-gray-700 mb-1">اسم الطالب</label>
<input type="text" name="student_name" id="student_name" value="{{ student.student_name }}" required class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="age" class="block text-sm font-medium text-gray-700 mb-1">العمر</label>
<input type="number" name="age" id="age" value="{{ student.age }}" required class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="parent_name" class="block text-sm font-medium text-gray-700 mb-1">اسم ولي الأمر</label>
<input type="text" name="parent_name" id="parent_name" value="{{ student.parent_name }}" required class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="parent_phone_1" class="block text-sm font-medium text-gray-700 mb-1">هاتف ولي الأمر 1 (مطلوب)</label>
<input type="tel" name="parent_phone_1" id="parent_phone_1" value="{{ student.parent_phone_1 }}" required class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="parent_phone_2" class="block text-sm font-medium text-gray-700 mb-1">هاتف ولي الأمر 2 (اختياري)</label>
<input type="tel" name="parent_phone_2" id="parent_phone_2" value="{{ student.parent_phone_2 or '' }}" class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="student_phone" class="block text-sm font-medium text-gray-700 mb-1">هاتف الطالب (اختياري)</label>
<input type="tel" name="student_phone" id="student_phone" value="{{ student.student_phone or '' }}" class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="grade" class="block text-sm font-medium text-gray-700 mb-1">الصف</label>
<input type="text" name="grade" id="grade" value="{{ student.grade }}" required class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label for="school_name" class="block text-sm font-medium text-gray-700 mb-1">اسم المدرسة</label>
<input type="text" name="school_name" id="school_name" value="{{ student.school_name }}" required class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div class="md:col-span-2">
<label for="address" class="block text-sm font-medium text-gray-700 mb-1">العنوان</label>
<input type="text" name="address" id="address" value="{{ student.address }}" required class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div class="md:col-span-2">
<label for="memorizing" class="block text-sm font-medium text-gray-700 mb-1">المحفوظات</label>
<input type="text" name="memorizing" id="memorizing" value="{{ student.memorizing }}" required class="w-full px-4 py-2 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
</div>
<div class="mt-8 text-left flex space-x-4 space-x-reverse">
<button type="submit" id="submit-modify-button" class="px-8 py-3 bg-blue-600 text-white font-semibold rounded-lg shadow-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-all">
حفظ التعديلات
</button>
<a href="{{ url_for('index') }}" class="px-8 py-3 bg-gray-300 text-gray-800 font-semibold rounded-lg shadow-md hover:bg-gray-400 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 transition-all">
إلغاء
</a>
</div>
</form>
</div>
<script>
// Prevent double submission for the modify form
const modifyStudentForm = document.getElementById('modify-student-form');
const submitModifyButton = document.getElementById('submit-modify-button');
if (modifyStudentForm && submitModifyButton) {
modifyStudentForm.addEventListener('submit', () => {
submitModifyButton.disabled = true;
submitModifyButton.textContent = 'جاري الحفظ...'; // "Saving..."
});
}
</script>
{% endblock %}

عرض الملف

@@ -9,6 +9,8 @@
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700&display=swap" rel="stylesheet">
{# Font Awesome for icons #}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body { font-family: 'Cairo', sans-serif; }
/* Style for disabled buttons to provide visual feedback */