From 87f1fc2c7a279418dc5a6f900c6a5f30b0878d93 Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Thu, 13 Nov 2025 16:24:33 +0100 Subject: [PATCH] =?UTF-8?q?Refactor:=20Excel=20import=20jde=20p=C5=99?= =?UTF-8?q?=C3=ADmo=20do=20inline=20editoru=20s=20v=C3=BDb=C4=9Brem=20bare?= =?UTF-8?q?v?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problém: - V kroku 2 uživatel nastavoval barvy, ale ty se neaplikovaly v kroku 3 - Zbytečný mezikrok kde uživatel musel klikat 'Generovat' nebo 'Upravit' Řešení: - Step 2 nyní přímo zobrazuje inline editor s načtenými daty z Excelu - Uživatel může upravit řádky, typy a nastavit barvy přímo v jednom kroku - Odstraněn step 2b (duplikát) a step 3 (již nepotřebný) - Zjednodušen workflow: Import Excel -> Inline editor -> Generovat Změny: - cgi-bin/scenar.py: Step 2 nyní renderuje inline editor přímo - Odstraněny nepotřebné kroky 2b a 3 - Barvy se nyní nastavují přímo v inline editoru u typů programu Testy: 18/18 unit testů prošlo ✅ --- cgi-bin/scenar.py | 217 ++++++++-------------------------------------- tmp/test.xlsx | Bin 8666 -> 6102 bytes 2 files changed, 38 insertions(+), 179 deletions(-) diff --git a/cgi-bin/scenar.py b/cgi-bin/scenar.py index a9723b0..13349bf 100755 --- a/cgi-bin/scenar.py +++ b/cgi-bin/scenar.py @@ -511,104 +511,7 @@ elif step == '2' and file_item is not None and file_item.filename: if data.empty: render_error("Načtená data jsou prázdná nebo obsahují neplatné hodnoty. Zkontrolujte vstupní soubor.") else: - # Extract program types - program_types = sorted([str(t).strip() for t in data["Typ"].dropna().unique()]) - file_content_base64 = base64.b64encode(file_content).decode('utf-8') - - print(''' - - - -Scenar Creator - Typy programu - - - -
-

Typy programu

-

Vyplň popis a barvu pro každý typ programu:

-
- - - - -''') - - for i, typ in enumerate(program_types, start=0): - print(f'''
- - - - -
''') - - print('''
- - -
- -
-
- -''') - - except ValidationError as e: - render_error(f"Chyba validace: {str(e)}") - except (TemplateError, ScenarsError) as e: - render_error(f"Chyba: {str(e)}") - except Exception as e: - logger.error(f"Unexpected error: {str(e)}") - render_error(f"Neočekávaná chyba: {str(e)}") - -elif step == '2b': - """Load Excel data into inline editor for editing.""" - try: - # Get file content from either file upload or base64 - file_content = None - if file_item is not None and file_item.filename: - file_content = file_item.file.read() - else: - file_content_base64 = form.getvalue('file_content_base64', '') - if file_content_base64: - file_content = base64.b64decode(file_content_base64) - - if not file_content: - render_error("Chyba: Soubor nebyl nalezen.") - else: - file_size = len(file_content) - - # Validate inputs - validate_inputs(title, detail, file_size) - - # Read Excel - data, error_rows = read_excel(file_content, show_debug) - - if data.empty: - render_error("Načtená data jsou prázdná nebo obsahují neplatné hodnoty. Zkontrolujte vstupní soubor.") - else: + # Instead of showing type selection form, go directly to inline editor (step 2b) # Extract program types and prepare for inline editor program_types = sorted([str(t).strip() for t in data["Typ"].dropna().unique()]) @@ -632,9 +535,12 @@ textarea { resize: vertical; min-height: 80px; } button { padding: 10px 20px; background: #007BFF; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; } button:hover { background: #0056b3; } +button.danger { background: #dc3545; } +button.danger:hover { background: #c82333; } table { width: 100%; border-collapse: collapse; margin-bottom: 20px; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background: #f0f0f0; } +.type-def { margin-bottom: 15px; padding: 10px; background: #f9f9f9; border-left: 3px solid #007BFF; } @@ -701,7 +607,7 @@ th { background: #f0f0f0; } - + ''') @@ -714,24 +620,29 @@ th { background: #f0f0f0; }
-

Typy programu

+

Typy programu (nastavení barev a popisů)

''') # Load type definitions type_counter = 0 for type_name in program_types: - print(f'''
- - - - + print(f'''
+ + +
''') type_counter += 1 print('''
- +
@@ -744,6 +655,8 @@ th { background: #f0f0f0; }