@@ -135,13 +135,15 @@ def handle_jpeg_generation(pdf_filename):
135135 jpeg_stream .seek (0 )
136136 jpeg_files .append ((f'page_{ i + 1 } .jpg' , jpeg_stream ))
137137
138- zip_buffer = BytesIO ()
139- with zipfile .ZipFile (zip_buffer , 'a' , zipfile .ZIP_DEFLATED ) as zip_file :
138+ zip_filename = os .path .splitext (pdf_filename )[0 ] + ".zip"
139+ zip_path = os .path .join (Config .FILE_DIRECTORY , zip_filename )
140+
141+ with zipfile .ZipFile (zip_path , 'w' , zipfile .ZIP_DEFLATED ) as zip_file :
140142 for file_name , file_bytes in jpeg_files :
141143 zip_file .writestr (file_name , file_bytes .read ())
142- zip_buffer . seek ( 0 )
143- logger .info (f"JPEG-Bilder erfolgreich erstellt und in ZIP-Datei gepackt" )
144- return zip_buffer
144+
145+ logger .info (f"JPEG-Bilder erfolgreich erstellt und in ZIP-Datei gepackt: { zip_filename } " )
146+ return zip_filename
145147
146148@router .get ("/appointments" )
147149async def appointments_page (
@@ -196,7 +198,7 @@ async def process_appointments(
196198 if not login_token :
197199 return RedirectResponse (url = "/" , status_code = status .HTTP_303_SEE_OTHER )
198200
199- # Standardwerte für Datumsbereich, falls nicht im Formular
201+ # Default values for date range if not in the form
200202 if not start_date or not end_date :
201203 start_date_default , end_date_default = get_date_range_from_form ()
202204 start_date = start_date or start_date_default
@@ -209,15 +211,15 @@ async def process_appointments(
209211 if calendar_ids :
210212 calendar_ids_int = [int (id ) for id in calendar_ids if id .isdigit ()]
211213
212- # Wenn keine Kalender ausgewählt sind, alle verfügbaren Kalender verwenden
214+ # If no calendars are selected, use all available calendars
213215 if not calendar_ids_int and calendars :
214216 calendar_ids_int = [calendar ['id' ] for calendar in calendars ]
215- logger .info (f"Keine Kalender ausgewählt, verwende alle verfügbaren Kalender : { calendar_ids_int } " )
217+ logger .info (f"No calendars selected, using all available calendars : { calendar_ids_int } " )
216218
217- # Standardwerte für Farbeinstellungen
219+ # Default values for color settings
218220 color_settings = load_color_settings (db , "default" )
219221
220- # Überschreibe mit Formulardaten, falls vorhanden
222+ # Override with form data if available
221223 if background_color :
222224 color_settings ['background_color' ] = background_color
223225 if alpha is not None :
@@ -232,7 +234,7 @@ async def process_appointments(
232234 appointments_data = await fetch_appointments (login_token , start_date , end_date , calendar_ids_int )
233235 appointments = [appointment_to_dict (app ) for app in appointments_data ]
234236
235- # Zusätzliche Informationen laden
237+ # Load additional information
236238 additional_infos = get_additional_infos (db , [appointment ['id' ] for appointment in appointments ])
237239 for appointment in appointments :
238240 appointment ['additional_info' ] = additional_infos .get (appointment ['id' ], "" )
@@ -259,7 +261,7 @@ async def process_appointments(
259261
260262 elif generate_pdf_btn :
261263 if not appointment_id :
262- # Wenn keine Termine ausgewählt wurden, zurück zur Terminübersicht
264+ # If no appointments were selected, return to appointment overview
263265 return templates .TemplateResponse (
264266 "appointments.html" ,
265267 {
@@ -275,7 +277,7 @@ async def process_appointments(
275277 }
276278 )
277279
278- # Zusätzliche Informationen speichern
280+ # Save additional information
279281 appointment_info_list = []
280282 form_data = await request .form ()
281283 for app_id in appointment_id :
@@ -296,39 +298,39 @@ async def process_appointments(
296298 except Exception as e :
297299 print (f"Fehler beim Lesen des Hintergrundbildes: { e } " )
298300
299- # Hole die tatsächlichen Termine von der API
300- logger .info (f"Ausgewählte Termin- IDs: { appointment_id } " )
301- logger .info (f"Rufe Termine ab für Zeitraum { start_date } bis { end_date } und Kalender { calendar_ids_int } " )
301+ # Get the actual appointments from the API
302+ logger .info (f"Selected appointment IDs: { appointment_id } " )
303+ logger .info (f"Retrieving appointments for period { start_date } to { end_date } and calendars { calendar_ids_int } " )
302304
303- # Hole alle Termine für den angegebenen Zeitraum
305+ # Get all appointments for the specified time period
304306 appointments_data = await fetch_appointments (login_token , start_date , end_date , calendar_ids_int )
305307 logger .info (f"Anzahl abgerufener Termine: { len (appointments_data )} " )
306308
307309 # Konvertiere die Termine in das richtige Format
308310 appointments = [appointment_to_dict (app ) for app in appointments_data ]
309311
310- # Füge zusätzliche Informationen aus dem Formular hinzu
312+ # Add additional information from the form
311313 for appointment in appointments :
312314 app_id = appointment ['id' ]
313315 additional_info = form_data .get (f'additional_info_{ app_id } ' , "" )
314316 appointment ['additional_info' ] = additional_info
315317
316- logger .info (f"Anzahl der Termine für PDF: { len (appointments )} " )
317-
318- # Debug-Logging für IDs
319- logger .info (f"Ausgewählte Termin- IDs: { appointment_id } " )
320- logger .info (f"Verfügbare Termin- IDs: { [app ['id' ] for app in appointments ]} " )
318+ logger .info (f"Number of appointments for PDF: { len (appointments )} " )
319+
320+ # Debug logging for IDs
321+ logger .info (f"Selected appointment IDs: { appointment_id } " )
322+ logger .info (f"Available appointment IDs: { [app ['id' ] for app in appointments ]} " )
321323
322- # Nur ausgewählte Termine verwenden - mit Stringvergleich
324+ # Use only selected appointments - with string comparison
323325 selected_appointments = []
324326 for app in appointments :
325327 for app_id in appointment_id :
326328 if str (app ['id' ]) == str (app_id ):
327329 selected_appointments .append (app )
328330 break
329331
330- # Logging für ausgewählte Termine
331- logger .info (f"Generiere PDF für { len (selected_appointments )} Termine :" )
332+ # Logging for selected appointments
333+ logger .info (f"Generating PDF for { len (selected_appointments )} appointments :" )
332334 for idx , app in enumerate (selected_appointments , 1 ):
333335 logger .info (f" { idx } . { app ['description' ]} am { app ['startDateView' ]} ({ app ['startTimeView' ]} -{ app ['endTimeView' ]} )" )
334336
@@ -343,7 +345,7 @@ async def process_appointments(
343345
344346 elif generate_jpeg_btn :
345347 if not appointment_id :
346- # Wenn keine Termine ausgewählt wurden, zurück zur Terminübersicht
348+ # If no appointments were selected, return to appointment overview
347349 return templates .TemplateResponse (
348350 "appointments.html" ,
349351 {
@@ -359,7 +361,7 @@ async def process_appointments(
359361 }
360362 )
361363
362- # Ähnlich wie bei PDF, aber mit JPEG-Konvertierung
364+ # Similar to PDF, but with JPEG conversion
363365 appointment_info_list = []
364366 form_data = await request .form ()
365367 for app_id in appointment_id :
@@ -380,39 +382,39 @@ async def process_appointments(
380382 except Exception as e :
381383 print (f"Fehler beim Lesen des Hintergrundbildes: { e } " )
382384
383- # Hole die tatsächlichen Termine von der API
384- logger .info (f"Ausgewählte Termin- IDs: { appointment_id } " )
385- logger .info (f"Rufe Termine ab für Zeitraum { start_date } bis { end_date } und Kalender { calendar_ids_int } " )
385+ # Get the actual appointments from the API
386+ logger .info (f"Selected appointment IDs: { appointment_id } " )
387+ logger .info (f"Retrieving appointments for period { start_date } to { end_date } and calendars { calendar_ids_int } " )
386388
387- # Hole alle Termine für den angegebenen Zeitraum
389+ # Get all appointments for the specified time period
388390 appointments_data = await fetch_appointments (login_token , start_date , end_date , calendar_ids_int )
389391 logger .info (f"Anzahl abgerufener Termine: { len (appointments_data )} " )
390392
391393 # Konvertiere die Termine in das richtige Format
392394 appointments = [appointment_to_dict (app ) for app in appointments_data ]
393395
394- # Füge zusätzliche Informationen aus dem Formular hinzu
396+ # Add additional information from the form
395397 for appointment in appointments :
396398 app_id = appointment ['id' ]
397399 additional_info = form_data .get (f'additional_info_{ app_id } ' , "" )
398400 appointment ['additional_info' ] = additional_info
399401
400- logger .info (f"Anzahl der Termine für JPEG: { len (appointments )} " )
401-
402- # Debug-Logging für IDs
403- logger .info (f"Ausgewählte Termin- IDs: { appointment_id } " )
404- logger .info (f"Verfügbare Termin- IDs: { [app ['id' ] for app in appointments ]} " )
402+ logger .info (f"Number of appointments for JPEG: { len (appointments )} " )
403+
404+ # Debug logging for IDs
405+ logger .info (f"Selected appointment IDs: { appointment_id } " )
406+ logger .info (f"Available appointment IDs: { [app ['id' ] for app in appointments ]} " )
405407
406- # Nur ausgewählte Termine verwenden - mit Stringvergleich
408+ # Use only selected appointments - with string comparison
407409 selected_appointments = []
408410 for app in appointments :
409411 for app_id in appointment_id :
410412 if str (app ['id' ]) == str (app_id ):
411413 selected_appointments .append (app )
412414 break
413415
414- # Logging für ausgewählte Termine
415- logger .info (f"Generiere JPEG für { len (selected_appointments )} Termine :" )
416+ # Logging for selected appointments
417+ logger .info (f"Generating JPEG for { len (selected_appointments )} appointments :" )
416418 for idx , app in enumerate (selected_appointments , 1 ):
417419 logger .info (f" { idx } . { app ['description' ]} am { app ['startDateView' ]} ({ app ['startTimeView' ]} -{ app ['endTimeView' ]} )" )
418420
@@ -422,13 +424,13 @@ async def process_appointments(
422424 background_image_stream )
423425
424426 # JPEG generieren
425- zip_buffer = handle_jpeg_generation (filename )
427+ zip_filename = handle_jpeg_generation (filename )
426428
427- # Als Datei zurückgeben
429+ # Return as file
428430 response = FileResponse (
429- zip_buffer ,
431+ os . path . join ( Config . FILE_DIRECTORY , zip_filename ) ,
430432 media_type = "application/zip" ,
431- filename = "images.zip"
433+ filename = zip_filename
432434 )
433435 response .set_cookie (key = "jpegGenerated" , value = "true" , max_age = 1 , path = '/' )
434436 return response
0 commit comments