From c5d5c1408c4c6847c2924ffb7661c59b9258a119 Mon Sep 17 00:00:00 2001 From: Khaled Mahfouz Date: Wed, 11 Jun 2025 18:19:44 +0300 Subject: [PATCH] - version : 0.7 - description : adding download template option and move (template.csv -> templates/template.csv). --- app.py | 17 ++++++--- templates/index.html | 51 +++++++++++++++----------- template.csv => templates/template.csv | 0 3 files changed, 41 insertions(+), 27 deletions(-) rename template.csv => templates/template.csv (100%) diff --git a/app.py b/app.py index 89aaa5f..32fe7db 100644 --- a/app.py +++ b/app.py @@ -2,7 +2,7 @@ import sqlite3 import csv import io import re -from flask import Flask, render_template, request, redirect, url_for, flash +from flask import Flask, render_template, request, redirect, url_for, flash, send_from_directory # --- App Setup --- app = Flask(__name__) @@ -50,8 +50,8 @@ def validate_phone(phone): def validate_student_data(form_data, is_csv=False): errors = [] required_fields = ['student_name', 'age', 'parent_name', - 'parent_phone_1', 'grade', 'school_name', - 'address', 'memorizing'] + 'parent_phone_1', 'grade', 'school_name', + 'address', 'memorizing'] # Check required fields for field in required_fields: @@ -197,7 +197,7 @@ def import_csv(): student_data['address'], student_data['memorizing'] )) - + # Process validation results if row_errors: flash(f'تم العثور على أخطاء في {len(row_errors)} سطراً', 'warning') @@ -228,5 +228,12 @@ def import_csv(): return redirect(url_for('index')) +# New route to download the CSV template +@app.route('/download_csv_template') +def download_csv_template(): + # The directory where the template.csv is located (your templates folder) + # The second argument is the filename to be sent + return send_from_directory(app.template_folder, 'template.csv', as_attachment=True) + if __name__ == '__main__': - app.run(debug=True) \ No newline at end of file + app.run(debug=True) diff --git a/templates/index.html b/templates/index.html index f125098..2eae81d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -62,33 +62,40 @@
-

استيراد من ملف CSV

-
-

هام: تنسيق ملف CSV

-

يجب أن يكون الملف بصيغة CSV ومرمّزاً بترميز UTF-8.

-

يجب **ألا يحتوي** الملف على صف للعناوين، ويجب أن تكون الأعمدة بالترتيب الدقيق التالي:

-

- اسم الطالب, العمر, اسم ولي الأمر, هاتف ولي الأمر 1, هاتف ولي الأمر 2, هاتف الطالب, الصف, اسم المدرسة, العنوان, المحفوظات -

-

إذا كانت الحقول الاختيارية (هاتف ولي الأمر 2، هاتف الطالب) فارغة، اتركها كذلك.

-
-
-
- +

استيراد من ملف CSV

+
+

هام: تنسيق ملف CSV

+

يجب أن يكون الملف بصيغة CSV ومرمّزاً بترميز UTF-8.

+

يجب **ألا يحتوي** الملف على صف للعناوين، ويجب أن تكون الأعمدة بالترتيب الدقيق التالي:

+

+ اسم الطالب, العمر, اسم ولي الأمر, هاتف ولي الأمر 1, هاتف ولي الأمر 2, هاتف الطالب, الصف, اسم المدرسة, العنوان, المحفوظات +

+

إذا كانت الحقول الاختيارية (هاتف ولي الأمر 2، هاتف الطالب) فارغة، اتركها كذلك.

+ {# Added link to download CSV template #} +

+ + تنزيل قالب CSV + +

+
+
+ + - + - + - - -
+ + +
+

الطلاب المسجلون

diff --git a/template.csv b/templates/template.csv similarity index 100% rename from template.csv rename to templates/template.csv