diff --git a/Web/app.py b/Web/app.py index c064d90..291b0b6 100755 --- a/Web/app.py +++ b/Web/app.py @@ -153,7 +153,7 @@ def print(*args, **kwargs): app.logger.info(message) -STUDENT_CARD_ENCRYPTED_FIELDS = ('SchülerName', 'Klasse', 'Notizen') +STUDENT_CARD_ENCRYPTED_FIELDS = ('ausweis_ident', 'SchülerName', 'Klasse', 'Notizen') def _decrypt_student_card_doc(card_doc): @@ -2191,13 +2191,12 @@ def _upload_student_cards_excel(): synonyms = { 'ausweis_id': ['ausweis_id', 'ausweisid', 'ausweis-id', 'karte', 'kartennummer', 'card_id', 'id'], - # NEU: Erkennung für lokales Differenzierungsmerkmal / Ausweis Ident - 'ausweis_ident': ['lokales differenzierungsmerkmal', 'lokales_differenzierungsmerkmal', 'ausweis_ident', 'differenzierungsmerkmal'], - 'first_name': ['vorname', 'first_name', 'firstname', 'rufname'], - 'last_name': ['nachname', 'last_name', 'lastname'], - 'class_name': ['klasse', 'class', 'class_name', 'jahrgang', 'jahrgangsstufe', 'stufe', 'gruppe', 'asv_klasse'], - 'notes': ['notizen', 'notes', 'bemerkungen', 'bemerkung', 'hinweis', 'hinweise'], - 'default_borrow_days': ['standard_ausleihdauer', 'ausleihdauer', 'borrow_days', 'tage', 'leihtage', 'max_borrow_days'], + 'ausweis_ident': ['lokales Differenzierungsmerkmal', 'lokales differenzierungsmerkmal', 'lokales_differenzierungsmerkmal', 'ausweis_ident', 'differenzierungsmerkmal'], + 'first_name': ['vorname', 'first_name', 'firstname', 'rufname', 'Vorname'], + 'last_name': ['nachname', 'last_name', 'lastname', 'Nachname'], + 'class_name': ['klasse', 'class', 'class_name', 'jahrgang', 'jahrgangsstufe', 'stufe', 'gruppe', 'asv_klasse', 'Jahrgang', 'Klasse'], + 'notes': ['notizen', 'notes', 'bemerkungen', 'bemerkung', 'hinweis', 'hinweise', 'Notizen', 'Bemerkung', 'Hinweis', 'Hinweise'], + 'default_borrow_days': ['standard_ausleihdauer', 'ausleihdauer', 'borrow_days', 'tage', 'leihtage', 'max_borrow_days', 'Ausleihdauer'], } def col_index(key): @@ -2209,7 +2208,7 @@ def _upload_student_cards_excel(): mapped_indices = { 'ausweis_id': col_index('ausweis_id'), - 'ausweis_ident': col_index('ausweis_ident'), # NEU + 'ausweis_ident': col_index('ausweis_ident'), 'first_name': col_index('first_name'), 'last_name': col_index('last_name'), 'class_name': col_index('class_name'), @@ -2218,7 +2217,7 @@ def _upload_student_cards_excel(): } validation_only = (request.form.get('excel_action') or '').strip().lower() == 'validate' - max_rows = 15000 + max_rows = 1500 planned_rows = [] validation_errors = [] @@ -2250,7 +2249,7 @@ def _upload_student_cards_excel(): return row_values[idx] ausweis_id = sanitize_form_value(val('ausweis_id')) - ausweis_ident = sanitize_form_value(val('ausweis_ident')) # NEU gelesen + ausweis_ident = sanitize_form_value(val('ausweis_ident')) class_name = sanitize_form_value(val('class_name')) notes = sanitize_form_value(val('notes')) @@ -2273,12 +2272,6 @@ def _upload_student_cards_excel(): if not student_name: row_errors.append('Vorname und Nachname fehlen') - # NEU: Generierung des Ausweis Ident, falls nicht in Excel vorhanden - if not ausweis_ident: - # Erstellt einen Bezeichner wie z.B. LD-A83F9 - random_chars = "".join(random.choices(string.ascii_uppercase + string.digits, k=5)) - ausweis_ident = f"LD-{random_chars}" - # Logik für die Haupt-AusweisID if not ausweis_id and student_name: ausweis_id = generate_ausweis_id(existing_ids) @@ -2291,6 +2284,9 @@ def _upload_student_cards_excel(): else: existing_ids.add(ausweis_id) + if not ausweis_ident: + ausweis_ident = ausweis_id + if row_errors: validation_errors.append((row_number, '; '.join(row_errors))) continue @@ -2329,6 +2325,7 @@ def _upload_student_cards_excel(): for row in planned_rows: encrypted_payload = encrypt_document_fields( { + 'ausweis_ident': row['ausweis_ident'], 'SchülerName': row['student_name'], 'Klasse': row['class_name'], 'Notizen': row['notes'], @@ -2337,7 +2334,6 @@ def _upload_student_cards_excel(): ) student_cards.insert_one({ 'AusweisId': row['ausweis_id'], - 'AusweisIdent': encrypt_text(row['ausweis_ident']), 'StandardAusleihdauer': int(row['default_borrow_days']), 'Erstellt': datetime.datetime.now(), **encrypted_payload, @@ -4101,6 +4097,7 @@ def student_cards_admin(): edit_mode = True form_data = { 'card_id': str(card['_id']), + 'ausweis_ident': card.get('ausweis_ident', ''), 'ausweis_id': card.get('AusweisId', ''), 'student_name': card.get('SchülerName', ''), 'default_borrow_days': card.get('StandardAusleihdauer', 14), @@ -4115,6 +4112,7 @@ def student_cards_admin(): if request.method == 'POST': action = request.form.get('action', 'add') ausweis_id = request.form.get('ausweis_id', '').strip().upper() + ausweis_ident = request.form.get('ausweis_ident', '').strip() student_name = request.form.get('student_name', '').strip() student_name_alias = student_name default_borrow_days = request.form.get('default_borrow_days', 14) @@ -4140,9 +4138,12 @@ def student_cards_admin(): existing = student_cards.find_one({'AusweisId': ausweis_id, '_id': {'$ne': ObjectId(card_id)}}) if existing: flash('Diese Ausweis-ID existiert bereits.', 'error') + if not ausweis_ident: + ausweis_ident = ausweis_id else: encrypted_payload = encrypt_document_fields( { + 'ausweis_ident': ausweis_ident, 'SchülerName': student_name_alias, 'Klasse': class_name, 'Notizen': notes, @@ -4174,6 +4175,8 @@ def student_cards_admin(): else: ausweis_id = generate_ausweis_id() existing = False + if not ausweis_ident: + ausweis_ident = ausweis_id if existing: flash('Diese ID existiert bereits.', 'error') @@ -4181,6 +4184,7 @@ def student_cards_admin(): try: encrypted_payload = encrypt_document_fields( { + 'ausweis_ident': ausweis_ident, 'SchülerName': student_name_alias, 'Klasse': class_name, 'Notizen': notes, diff --git a/Web/templates/student_cards_admin.html b/Web/templates/student_cards_admin.html index e9ed30a..586f8fc 100644 --- a/Web/templates/student_cards_admin.html +++ b/Web/templates/student_cards_admin.html @@ -249,7 +249,7 @@

Excel-Import Bibliotheksausweise

-

Laden Sie eine .xlsx- oder .csv-Datei hoch, zum Beispiel aus ASV (Amtliche Schuldaten). Erkannt werden automatisch Spalten wie Name, NachnameKlasse, Ausweis-ID (optional), Notizen (optional) und Standard-Ausleihdauer (optional).

+

Laden Sie eine .xlsx- oder .csv-Datei hoch, zum Beispiel aus ASV (Amtliche Schuldaten). Erkannt werden automatisch Spalten wie Name, NachnameKlasse, Ausweis-ID (optional), lokales Differenzierungsmerkmal (optional aber empfohlen), Notizen (optional) und Standard-Ausleihdauer (optional).

@@ -276,6 +276,12 @@ value="{{ form_data.get('ausweis_id', '') }}" placeholder="z.B. SIS2024001">
+
+ + +