From 38f35d191587b4f6fe4237216263bd98060125fc Mon Sep 17 00:00:00 2001 From: SERTY Date: Wed, 30 Jul 2025 19:17:16 +0300 Subject: [PATCH] fix old config format --- app.py | 29 +++++++++++++++-------------- routes.py | 24 +++++++++++++++++++++--- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index 697b6cb..84e830e 100644 --- a/app.py +++ b/app.py @@ -70,20 +70,21 @@ def create_app(): user_id = config.user_id mappings = config.mappings for sheer_title, params in mappings.items(): - cron_schedule = params.get('schedule_cron') - if cron_schedule: - job_id = f"user_{user_id}_sheet_{sheer_title}" - try: - scheduler.add_job( - id=job_id, - func=execute_olap_export, - trigger='cron', - args=[user_id, sheer_title], - **_parse_cron_string(cron_schedule) - ) - app.logger.info(f"Job {job_id} loaded on startup.") - except Exception as e: - app.logger.error(f"Failed to load job {job_id}: {e}") + if isinstance(params, dict): + cron_schedule = params.get('schedule_cron') + if cron_schedule: + job_id = f"user_{user_id}_sheet_{sheer_title}" + try: + scheduler.add_job( + id=job_id, + func=execute_olap_export, + trigger='cron', + args=[user_id, sheer_title], + **_parse_cron_string(cron_schedule) + ) + app.logger.info(f"Job {job_id} loaded on startup.") + except Exception as e: + app.logger.error(f"Failed to load job {job_id}: {e}") else: app.logger.warning("Database tables not found. Skipping job loading on startup. Run 'flask init-db' to create the tables.") scheduler.start() diff --git a/routes.py b/routes.py index d2930e3..05a2f2e 100644 --- a/routes.py +++ b/routes.py @@ -131,13 +131,20 @@ def logout(): @login_required def index(): config = g.user_config + clean_mappings = {} + if config.mappings: + for key, value in config.mappings.items(): + if value['report_id']: + clean_mappings[key] = value + else: + clean_mappings[key] = {'report_id': value, 'schedule_cron': None, 'schedule_period': None} return render_template( 'index.html', rms_config=config.get_rms_dict(), google_config=config.get_google_dict(), presets=config.presets, sheets=config.sheets, - mappings=config.mappings, + mappings=clean_mappings, client_email=config.google_client_email ) @@ -291,10 +298,18 @@ def mapping_set(): if selected_report_id: # Получаем существующие данные расписания для этого листа existing_schedule = current_mappings.get(sheet['title'], {}) + schedule_cron = None + schedule_period = None + + if isinstance(existing_mapping_value, dict): + schedule_cron = existing_mapping_value.get('schedule_cron') + schedule_period = existing_mapping_value.get('schedule_period') + + # Сохраняем новые настройки расписания в новом словаре new_mappings[sheet['title']] = { 'report_id': selected_report_id, - 'schedule_cron': existing_schedule.get('schedule_cron'), - 'schedule_period': existing_schedule.get('schedule_period') + 'schedule_cron': schedule_cron, + 'schedule_period': schedule_period } config.mappings = new_mappings @@ -462,6 +477,9 @@ def save_schedule(): updated_mappings = config.mappings or {} for sheet_title, params in updated_mappings.items(): + if not isinstance(params, dict): + continue + cron_value = request.form.get(f"cron-{sheet_title}", "").strip() period_value = request.form.get(f"period-{sheet_title}", "").strip()