esential bugs being fixed and some new adjustemnets for the student card functionality
Release Inventarsystem / release-docker (push) Failing after 1m2s
Release Inventarsystem / release-docker (push) Failing after 1m2s
This commit is contained in:
+19
-3
@@ -68,6 +68,7 @@ import logging
|
|||||||
from logging.handlers import RotatingFileHandler
|
from logging.handlers import RotatingFileHandler
|
||||||
import secrets
|
import secrets
|
||||||
import importlib
|
import importlib
|
||||||
|
import atexit
|
||||||
try:
|
try:
|
||||||
redis = importlib.import_module('redis')
|
redis = importlib.import_module('redis')
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -2190,12 +2191,13 @@ def _upload_student_cards_excel():
|
|||||||
|
|
||||||
synonyms = {
|
synonyms = {
|
||||||
'ausweis_id': ['ausweis_id', 'ausweisid', 'ausweis-id', 'karte', 'kartennummer', 'card_id', 'id'],
|
'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'],
|
'first_name': ['vorname', 'first_name', 'firstname', 'rufname'],
|
||||||
'last_name': ['nachname', 'last_name', 'lastname'],
|
'last_name': ['nachname', 'last_name', 'lastname'],
|
||||||
'class_name': ['klasse', 'class', 'class_name', 'jahrgang', 'jahrgangsstufe', 'stufe', 'gruppe', 'asv_klasse'],
|
'class_name': ['klasse', 'class', 'class_name', 'jahrgang', 'jahrgangsstufe', 'stufe', 'gruppe', 'asv_klasse'],
|
||||||
'notes': ['notizen', 'notes', 'bemerkungen', 'bemerkung', 'hinweis', 'hinweise'],
|
'notes': ['notizen', 'notes', 'bemerkungen', 'bemerkung', 'hinweis', 'hinweise'],
|
||||||
'default_borrow_days': ['standard_ausleihdauer', 'ausleihdauer', 'borrow_days', 'tage', 'leihtage',
|
'default_borrow_days': ['standard_ausleihdauer', 'ausleihdauer', 'borrow_days', 'tage', 'leihtage', 'max_borrow_days'],
|
||||||
'max_borrow_days'],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def col_index(key):
|
def col_index(key):
|
||||||
@@ -2207,6 +2209,7 @@ def _upload_student_cards_excel():
|
|||||||
|
|
||||||
mapped_indices = {
|
mapped_indices = {
|
||||||
'ausweis_id': col_index('ausweis_id'),
|
'ausweis_id': col_index('ausweis_id'),
|
||||||
|
'ausweis_ident': col_index('ausweis_ident'), # NEU
|
||||||
'first_name': col_index('first_name'),
|
'first_name': col_index('first_name'),
|
||||||
'last_name': col_index('last_name'),
|
'last_name': col_index('last_name'),
|
||||||
'class_name': col_index('class_name'),
|
'class_name': col_index('class_name'),
|
||||||
@@ -2247,17 +2250,21 @@ def _upload_student_cards_excel():
|
|||||||
return row_values[idx]
|
return row_values[idx]
|
||||||
|
|
||||||
ausweis_id = sanitize_form_value(val('ausweis_id'))
|
ausweis_id = sanitize_form_value(val('ausweis_id'))
|
||||||
|
ausweis_ident = sanitize_form_value(val('ausweis_ident')) # NEU gelesen
|
||||||
class_name = sanitize_form_value(val('class_name'))
|
class_name = sanitize_form_value(val('class_name'))
|
||||||
notes = sanitize_form_value(val('notes'))
|
notes = sanitize_form_value(val('notes'))
|
||||||
|
|
||||||
|
# Ausleihdauer extrahieren und standardmäßig auf 14 setzen
|
||||||
default_borrow_days = _excel_int(val('default_borrow_days'))
|
default_borrow_days = _excel_int(val('default_borrow_days'))
|
||||||
if not default_borrow_days:
|
if not default_borrow_days:
|
||||||
default_borrow_days = 14
|
default_borrow_days = 14
|
||||||
|
|
||||||
|
# Vor- und Nachname sicher auslesen und zusammensetzen
|
||||||
first_name = sanitize_form_value(val('first_name')) or ""
|
first_name = sanitize_form_value(val('first_name')) or ""
|
||||||
last_name = sanitize_form_value(val('last_name')) or ""
|
last_name = sanitize_form_value(val('last_name')) or ""
|
||||||
student_name = f"{first_name} {last_name}".strip()
|
student_name = f"{first_name} {last_name}".strip()
|
||||||
|
|
||||||
|
# Leere Zeilen überspringen
|
||||||
if not ausweis_id and not student_name and not class_name:
|
if not ausweis_id and not student_name and not class_name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -2266,8 +2273,15 @@ def _upload_student_cards_excel():
|
|||||||
if not student_name:
|
if not student_name:
|
||||||
row_errors.append('Vorname und Nachname fehlen')
|
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:
|
if not ausweis_id and student_name:
|
||||||
ausweis_id = generate_ausweis_id_excel(existing_ids)
|
ausweis_id = generate_ausweis_id(existing_ids)
|
||||||
validation_warnings.append((row_number, f'Ausweis-ID wurde automatisch erzeugt: {ausweis_id}'))
|
validation_warnings.append((row_number, f'Ausweis-ID wurde automatisch erzeugt: {ausweis_id}'))
|
||||||
existing_ids.add(ausweis_id.upper())
|
existing_ids.add(ausweis_id.upper())
|
||||||
elif ausweis_id:
|
elif ausweis_id:
|
||||||
@@ -2284,6 +2298,7 @@ def _upload_student_cards_excel():
|
|||||||
planned_rows.append({
|
planned_rows.append({
|
||||||
'row_number': row_number,
|
'row_number': row_number,
|
||||||
'ausweis_id': ausweis_id,
|
'ausweis_id': ausweis_id,
|
||||||
|
'ausweis_ident': ausweis_ident,
|
||||||
'student_name': student_name,
|
'student_name': student_name,
|
||||||
'class_name': class_name,
|
'class_name': class_name,
|
||||||
'notes': notes,
|
'notes': notes,
|
||||||
@@ -2322,6 +2337,7 @@ def _upload_student_cards_excel():
|
|||||||
)
|
)
|
||||||
student_cards.insert_one({
|
student_cards.insert_one({
|
||||||
'AusweisId': row['ausweis_id'],
|
'AusweisId': row['ausweis_id'],
|
||||||
|
'AusweisIdent': encrypt_text(row['ausweis_ident']),
|
||||||
'StandardAusleihdauer': int(row['default_borrow_days']),
|
'StandardAusleihdauer': int(row['default_borrow_days']),
|
||||||
'Erstellt': datetime.datetime.now(),
|
'Erstellt': datetime.datetime.now(),
|
||||||
**encrypted_payload,
|
**encrypted_payload,
|
||||||
|
|||||||
@@ -704,6 +704,41 @@ def get_user_by_student_card(student_card_id):
|
|||||||
# Do not call dp.decrypt_text() here because found_user is a MongoDB dictionary.
|
# Do not call dp.decrypt_text() here because found_user is a MongoDB dictionary.
|
||||||
return found_user
|
return found_user
|
||||||
|
|
||||||
|
def get_user_by_student_ident(student_ident):
|
||||||
|
"""Return user dict by student ident by decrypting all cards and matching."""
|
||||||
|
if not student_ident:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Normalisiere den Suchbegriff, den wir finden wollen
|
||||||
|
normalized_target = str(student_ident).strip()
|
||||||
|
if not normalized_target:
|
||||||
|
return None
|
||||||
|
|
||||||
|
client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT)
|
||||||
|
try:
|
||||||
|
db = _get_tenant_db(client)
|
||||||
|
all_student_cards = db['student_cards'].find()
|
||||||
|
|
||||||
|
for user_doc in all_student_cards:
|
||||||
|
encrypted_ident = user_doc.get('AusweisIdent')
|
||||||
|
|
||||||
|
if encrypted_ident:
|
||||||
|
try:
|
||||||
|
decrypted_ident = dp.decrypt_text(encrypted_ident)
|
||||||
|
|
||||||
|
if decrypted_ident and str(decrypted_ident).strip() == normalized_target:
|
||||||
|
return user_doc
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.error(f"Entschlüsselungsfehler bei ID {user_doc.get('_id')}: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
except Exception as exc:
|
||||||
|
app.logger.error(f"Datenbankfehler in get_user_by_student_ident: {exc}")
|
||||||
|
finally:
|
||||||
|
client.close()
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
def make_admin(username):
|
def make_admin(username):
|
||||||
"""Grant administrator privileges to a user."""
|
"""Grant administrator privileges to a user."""
|
||||||
|
|||||||
@@ -19,3 +19,4 @@ py-vapid>=1.9.0
|
|||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
pywebpush
|
pywebpush
|
||||||
pandas
|
pandas
|
||||||
|
atexit
|
||||||
@@ -19,3 +19,4 @@ py-vapid>=1.9.0
|
|||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
pywebpush
|
pywebpush
|
||||||
pandas
|
pandas
|
||||||
|
atexit
|
||||||
Reference in New Issue
Block a user