Changes to implement the ausweis_ident variable to correctly idententify students with the same name
Release Inventarsystem / release-docker (push) Successful in 2m15s
Release Inventarsystem / release-docker (push) Successful in 2m15s
This commit is contained in:
+22
-18
@@ -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,
|
||||
|
||||
@@ -249,7 +249,7 @@
|
||||
|
||||
<div style="border:1px solid #dbe4ee; border-radius:8px; padding:14px; margin-bottom:16px; background:#f8fbff;">
|
||||
<h3 style="margin:0 0 8px 0;">Excel-Import Bibliotheksausweise</h3>
|
||||
<p style="margin:0 0 10px 0; color:#555;">Laden Sie eine <strong>.xlsx</strong>- oder <strong>.csv</strong>-Datei hoch, zum Beispiel aus <strong>ASV (Amtliche Schuldaten)</strong>. Erkannt werden automatisch Spalten wie <strong>Name</strong>, <strong>Nachname</strong, <strong>Klasse</strong>, <strong>Ausweis-ID (optional)</strong>, <strong>Notizen (optional)</strong> und <strong>Standard-Ausleihdauer (optional)</strong>.</p>
|
||||
<p style="margin:0 0 10px 0; color:#555;">Laden Sie eine <strong>.xlsx</strong>- oder <strong>.csv</strong>-Datei hoch, zum Beispiel aus <strong>ASV (Amtliche Schuldaten)</strong>. Erkannt werden automatisch Spalten wie <strong>Name</strong>, <strong>Nachname</strong, <strong>Klasse</strong>, <strong>Ausweis-ID (optional)</strong>, <strong>lokales Differenzierungsmerkmal (optional aber empfohlen)</strong>, <strong>Notizen (optional)</strong> und <strong>Standard-Ausleihdauer (optional)</strong>.</p>
|
||||
<form method="POST" action="{{ url_for('upload_student_cards_excel') }}" enctype="multipart/form-data" style="display:flex; gap:10px; flex-wrap:wrap; align-items:center;">
|
||||
<input type="file" name="student_cards_excel" accept=".xlsx,.csv" required>
|
||||
<button type="submit" class="btn btn-secondary" name="excel_action" value="validate">Nur validieren</button>
|
||||
@@ -276,6 +276,12 @@
|
||||
value="{{ form_data.get('ausweis_id', '') }}"
|
||||
placeholder="z.B. SIS2024001">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="ausweis_ident">Lokales Differenzierungsmerkmal</label>
|
||||
<input type="text" id="ausweis_ident" name="ausweis_ident"
|
||||
value="{{ form_data.get('ausweis_ident', '') }}"
|
||||
placeholder="z.B. xw5oo123bbe">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="student_name">Schüler Name *</label>
|
||||
<input type="text" id="student_name" name="student_name" required
|
||||
|
||||
Reference in New Issue
Block a user