Testdaten Checkbox

Dieser Commit ist enthalten in:
2025-06-09 22:50:04 +02:00
Ursprung 17e38d8e2b
Commit 06bfdfaf2a
5 geänderte Dateien mit 76 neuen und 29 gelöschten Zeilen

Datei anzeigen

@@ -1360,7 +1360,7 @@ def dashboard():
security_level = 'success'
security_level_text = 'NORMAL'
# Resource Pool Statistiken
# Resource Pool Statistiken (nur Live-Daten, keine Testdaten)
cur.execute("""
SELECT
resource_type,
@@ -1369,6 +1369,7 @@ def dashboard():
COUNT(*) FILTER (WHERE status = 'quarantine') as quarantine,
COUNT(*) as total
FROM resource_pools
WHERE is_test = FALSE
GROUP BY resource_type
""")
@@ -3163,6 +3164,9 @@ def resources():
conn = get_connection()
cur = conn.cursor()
# Prüfe ob Testdaten angezeigt werden sollen (gleiche Logik wie bei Kunden)
show_test = request.args.get('show_test', 'false').lower() == 'true'
# Statistiken abrufen
cur.execute("""
SELECT
@@ -3172,8 +3176,9 @@ def resources():
COUNT(*) FILTER (WHERE status = 'quarantine') as quarantine,
COUNT(*) as total
FROM resource_pools
WHERE is_test = %s
GROUP BY resource_type
""")
""", (show_test,))
stats = {}
for row in cur.fetchall():
@@ -3185,7 +3190,7 @@ def resources():
'available_percent': round((row[1] / row[4] * 100) if row[4] > 0 else 0, 1)
}
# Letzte Aktivitäten
# Letzte Aktivitäten (gefiltert nach Test/Live)
cur.execute("""
SELECT
rh.action,
@@ -3196,9 +3201,10 @@ def resources():
rh.details
FROM resource_history rh
JOIN resource_pools rp ON rh.resource_id = rp.id
WHERE rp.is_test = %s
ORDER BY rh.action_at DESC
LIMIT 10
""")
""", (show_test,))
recent_activities = cur.fetchall()
# Ressourcen-Liste mit Pagination
@@ -3226,9 +3232,9 @@ def resources():
FROM resource_pools rp
LEFT JOIN licenses l ON rp.allocated_to_license = l.id
LEFT JOIN customers c ON l.customer_id = c.id
WHERE 1=1
WHERE rp.is_test = %s
"""
params = []
params = [show_test]
if resource_type:
query += " AND rp.resource_type = %s"
@@ -3268,6 +3274,7 @@ def resources():
resource_type=resource_type,
status_filter=status_filter,
search=search,
show_test=show_test,
datetime=datetime,
timedelta=timedelta)
@@ -3275,16 +3282,20 @@ def resources():
@login_required
def add_resources():
"""Ressourcen zum Pool hinzufügen"""
# Hole show_test Parameter für die Anzeige
show_test = request.args.get('show_test', 'false').lower() == 'true'
if request.method == 'POST':
resource_type = request.form.get('resource_type')
resources_text = request.form.get('resources_text', '')
is_test = request.form.get('is_test') == 'on' # Checkbox für Testdaten
# Parse resources (one per line)
resources = [r.strip() for r in resources_text.split('\n') if r.strip()]
if not resources:
flash('Keine Ressourcen angegeben', 'error')
return redirect(url_for('add_resources'))
return redirect(url_for('add_resources', show_test=show_test))
conn = get_connection()
cur = conn.cursor()
@@ -3295,10 +3306,10 @@ def add_resources():
for resource_value in resources:
try:
cur.execute("""
INSERT INTO resource_pools (resource_type, resource_value, status_changed_by)
VALUES (%s, %s, %s)
INSERT INTO resource_pools (resource_type, resource_value, status_changed_by, is_test)
VALUES (%s, %s, %s, %s)
ON CONFLICT (resource_type, resource_value) DO NOTHING
""", (resource_type, resource_value, session['username']))
""", (resource_type, resource_value, session['username'], is_test))
if cur.rowcount > 0:
added += 1
@@ -3323,13 +3334,13 @@ def add_resources():
conn.close()
log_audit('CREATE', 'resource_pool', None,
new_values={'type': resource_type, 'added': added, 'duplicates': duplicates},
additional_info=f"{added} Ressourcen hinzugefügt, {duplicates} Duplikate übersprungen")
new_values={'type': resource_type, 'added': added, 'duplicates': duplicates, 'is_test': is_test},
additional_info=f"{added} {'Test-' if is_test else ''}Ressourcen hinzugefügt, {duplicates} Duplikate übersprungen")
flash(f'{added} Ressourcen hinzugefügt, {duplicates} Duplikate übersprungen', 'success')
return redirect(url_for('resources'))
flash(f'{added} {"Test-" if is_test else ""}Ressourcen hinzugefügt, {duplicates} Duplikate übersprungen', 'success')
return redirect(url_for('resources', show_test=show_test))
return render_template('add_resources.html')
return render_template('add_resources.html', show_test=show_test)
@app.route('/resources/quarantine/<int:resource_id>', methods=['POST'])
@login_required