diff --git "a/app.py" "b/app.py" --- "a/app.py" +++ "b/app.py" @@ -228,7 +228,7 @@ def download_db_from_hf(specific_file=None, retries=DOWNLOAD_RETRIES, delay=DOWN try: if file_name == DATA_FILE: with open(file_name, 'w', encoding='utf-8') as f: - json.dump({'products': [], 'categories': [], 'seasons': [], 'orders': {}, 'employees': [], 'exchange_rate_kzt': 450.0}, f) + json.dump({'products': [], 'categories': [], 'seasons': [], 'orders': {}, 'employees': [], 'settings': {'usd_to_kzt_rate': 450}}, f) logging.info(f"Created empty local file {file_name} because it was not found on HF.") except Exception as create_e: logging.error(f"Failed to create empty local file {file_name}: {create_e}") @@ -292,7 +292,7 @@ def periodic_backup(): def load_data(): - default_data = {'products': [], 'categories': [], 'seasons': [], 'orders': {}, 'employees': [], 'exchange_rate_kzt': 450.0} + default_data = {'products': [], 'categories': [], 'seasons': [], 'orders': {}, 'employees': [], 'settings': {'usd_to_kzt_rate': 450}} try: with open(DATA_FILE, 'r', encoding='utf-8') as file: data = json.load(file) @@ -305,7 +305,8 @@ def load_data(): if 'seasons' not in data: data['seasons'] = [] if 'orders' not in data: data['orders'] = {} if 'employees' not in data: data['employees'] = [] - if 'exchange_rate_kzt' not in data: data['exchange_rate_kzt'] = 450.0 + if 'settings' not in data: data['settings'] = {'usd_to_kzt_rate': 450} + if 'usd_to_kzt_rate' not in data['settings']: data['settings']['usd_to_kzt_rate'] = 450 return data except FileNotFoundError: logging.warning(f"Local file {DATA_FILE} not found. Attempting download from HF.") @@ -323,7 +324,8 @@ def load_data(): if 'seasons' not in data: data['seasons'] = [] if 'orders' not in data: data['orders'] = {} if 'employees' not in data: data['employees'] = [] - if 'exchange_rate_kzt' not in data: data['exchange_rate_kzt'] = 450.0 + if 'settings' not in data: data['settings'] = {'usd_to_kzt_rate': 450} + if 'usd_to_kzt_rate' not in data['settings']: data['settings']['usd_to_kzt_rate'] = 450 return data except FileNotFoundError: logging.error(f"File {DATA_FILE} still not found even after download reported success. Using default.") @@ -355,7 +357,7 @@ def save_data(data): if 'seasons' not in data: data['seasons'] = [] if 'orders' not in data: data['orders'] = {} if 'employees' not in data: data['employees'] = [] - if 'exchange_rate_kzt' not in data: data['exchange_rate_kzt'] = 450.0 + if 'settings' not in data: data['settings'] = {'usd_to_kzt_rate': 450} with open(DATA_FILE, 'w', encoding='utf-8') as file: json.dump(data, file, ensure_ascii=False, indent=4) @@ -374,95 +376,92 @@ CATALOG_TEMPLATE = '''
Резервное копирование происходит автоматически каждые 30 минут, а также после каждого сохранения данных. Используйте эти кнопки для немедленной синхронизации.
- - +Резервное копирование происходит автоматически каждые 30 минут, а также после каждого сохранения данных. Используйте эти кнопки для немедленной синхронизации.
Категорий пока нет.
- {% endif %}Сезонов пока нет.
- {% endif %}Сотрудников пока нет.
- {% endif %}
- {% endif %}
+ {% else %}
{% endif %}
Категория: {{ product.get('category', 'Без категории') }}
Сезон: {{ product.get('season', 'Без сезона') }}
-Цена за линейку: {{ "%.2f"|format(product['price']) }} USD
+Цена: {{ "%.2f"|format(product['price']) }} USD
Шт. в линейке: {{ product.get('items_per_line', 'N/A') }}
Описание: {{ product.get('description', 'N/A')[:150] }}{% if product.get('description', '')|length > 150 %}...{% endif %}
- {% set colors = product.get('variants', []) | map(attribute='color') | list %} -Цвета/Вар-ты: {{ colors|join(', ') if colors else 'Нет' }} ({{ colors|length }} шт.)
+ {% set variants = product.get('variants', []) %} +Цвета: {{ variants|map(attribute='color')|join(', ') if variants else 'Нет' }}
Товаров пока нет.
- {% endif %} + {% else %}Товаров пока нет.
{% endif %}