Implementation of an automatic id code generation.
Release Inventarsystem / release-docker (push) Successful in 3m12s

This commit is contained in:
2026-08-17 11:50:35 +02:00
parent bb89b434ed
commit 9ea0ae6157
2 changed files with 24 additions and 5 deletions
+23 -4
View File
@@ -16,6 +16,7 @@ Features:
- History logging of item usage
- Booking and reservation of items
"""
from random import random
from flask import Flask, render_template, request, redirect, url_for, session, flash, send_from_directory, get_flashed_messages, jsonify, Response, make_response, send_file, abort
from werkzeug.utils import secure_filename
@@ -3985,6 +3986,19 @@ def library_admin():
back_target='library'
)
def generate_ausweis_id():
import random
import string
while True:
random_digits = "".join(random.choices(string.digits, k=6))
new_id = f"ID_{random_digits}"
if not us.get_user_by_student_card(new_id):
print(f"Generated unique ID: {new_id}")
return new_id
else:
print(f"Already found: {new_id}, trying another...")
@app.route('/student_cards_admin', methods=['GET', 'POST'])
def student_cards_admin():
@@ -4085,13 +4099,18 @@ def student_cards_admin():
flash('Fehler beim Aktualisieren des Ausweises.', 'error')
elif action == 'add':
if not ausweis_id or not student_name:
flash('Bitte Ausweis-ID und Schülername angeben.', 'error')
if not student_name:
flash('Bitte Schülername angeben.', 'error')
else:
# Check if ID already exists
existing = student_cards.find_one({'AusweisId': ausweis_id})
if ausweis_id:
existing = student_cards.find_one({'AusweisId': ausweis_id})
else:
ausweis_id = generate_ausweis_id()
existing = False
if existing:
flash('Diese Ausweis-ID existiert bereits.', 'error')
flash('Diese ID existiert bereits.', 'error')
else:
try:
encrypted_payload = encrypt_document_fields(
+1 -1
View File
@@ -272,7 +272,7 @@
<div class="form-row">
<div class="form-group">
<label for="ausweis_id">Ausweis-ID *</label>
<input type="text" id="ausweis_id" name="ausweis_id" required
<input type="text" id="ausweis_id" name="ausweis_id"
value="{{ form_data.get('ausweis_id', '') }}"
placeholder="z.B. SIS2024001">
</div>