Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -139,7 +139,7 @@ translations = {
|
|
| 139 |
'manage_products': 'Управление товарами',
|
| 140 |
'add_new_product': 'Добавить новый товар',
|
| 141 |
'product_name_label': 'Название товара *:',
|
| 142 |
-
'product_price_kgs_label': 'Цена (KGS)
|
| 143 |
'product_discount_percent_label': 'Скидка (%):',
|
| 144 |
'product_description_label': 'Описание:',
|
| 145 |
'product_category_label': 'Категория:',
|
|
@@ -179,7 +179,7 @@ translations = {
|
|
| 179 |
'delete_button': 'Удалить',
|
| 180 |
'editing_product_title': 'Редактирование: {product_name}',
|
| 181 |
'product_name_edit_label': 'Название *:',
|
| 182 |
-
'product_price_kgs_edit_label': 'Цена (KGS)
|
| 183 |
'product_discount_percent_edit_label': 'Скидка (%):',
|
| 184 |
'product_description_edit_label': 'Описание:',
|
| 185 |
'product_category_edit_label': 'Категория:',
|
|
@@ -215,7 +215,7 @@ translations = {
|
|
| 215 |
'flash_supplier_already_exists': "Поставщик '{supplier_name}' уже существует.",
|
| 216 |
'flash_supplier_delete_success': "Поставщик '{supplier_name}' удален.",
|
| 217 |
'flash_supplier_delete_failed': "Не удалось удалить поставщика '{supplier_name}'.",
|
| 218 |
-
'flash_product_name_price_required': 'Название
|
| 219 |
'flash_invalid_price_format': 'Неверный формат цены.',
|
| 220 |
'flash_invalid_discount_format': 'Неверный формат скидки (0-100).',
|
| 221 |
'flash_photo_limit_reached': 'Загружено только первые {photo_limit} фото.',
|
|
@@ -1939,7 +1939,7 @@ ADMIN_TEMPLATE = '''
|
|
| 1939 |
<label for="add_name">{{ get_translation('product_name_label') }}</label>
|
| 1940 |
<input type="text" id="add_name" name="name" required>
|
| 1941 |
<label for="add_price_kgs">{{ get_translation('product_price_kgs_label') }}</label>
|
| 1942 |
-
<input type="number" id="add_price_kgs" name="price_kgs" step="0.01" min="0"
|
| 1943 |
<label for="add_discount_percent">{{ get_translation('product_discount_percent_label') }}</label>
|
| 1944 |
<input type="number" id="add_discount_percent" name="discount_percent" step="1" min="0" max="100" value="0">
|
| 1945 |
<label for="add_description">{{ get_translation('product_description_label') }}</label>
|
|
@@ -2065,7 +2065,7 @@ ADMIN_TEMPLATE = '''
|
|
| 2065 |
<label>{{ get_translation('product_name_edit_label') }}</label>
|
| 2066 |
<input type="text" name="name" value="{{ product_info['name'] }}" required>
|
| 2067 |
<label>{{ get_translation('product_price_kgs_edit_label') }}</label>
|
| 2068 |
-
<input type="number" name="price_kgs" step="0.01" min="0" value="{{ product_info.price_kgs }}"
|
| 2069 |
<label>{{ get_translation('product_discount_percent_edit_label') }}</label>
|
| 2070 |
<input type="number" name="discount_percent" step="1" min="0" max="100" value="{{ product_info.get('discount_percent', 0) }}">
|
| 2071 |
<label>{{ get_translation('product_description_edit_label') }}</label>
|
|
@@ -2674,17 +2674,17 @@ def admin_api():
|
|
| 2674 |
if action == 'add_product':
|
| 2675 |
name = request.form.get('name', '').strip()
|
| 2676 |
price_kgs_str = request.form.get('price_kgs', '').replace(',', '.')
|
| 2677 |
-
if not name
|
| 2678 |
return jsonify({'error': get_translation('flash_product_name_price_required')}), 400
|
| 2679 |
try:
|
| 2680 |
-
price_kgs = round(float(price_kgs_str), 2)
|
| 2681 |
-
if price_kgs < 0: price_kgs = 0
|
| 2682 |
except ValueError:
|
| 2683 |
return jsonify({'error': get_translation('flash_invalid_price_format')}), 400
|
| 2684 |
|
| 2685 |
discount_percent_str = request.form.get('discount_percent', '0')
|
| 2686 |
try:
|
| 2687 |
-
discount_percent = int(discount_percent_str)
|
| 2688 |
if not (0 <= discount_percent <= 100): discount_percent = 0
|
| 2689 |
except ValueError:
|
| 2690 |
discount_percent = 0
|
|
@@ -2765,16 +2765,19 @@ def admin_api():
|
|
| 2765 |
|
| 2766 |
product_to_edit['name'] = request.form.get('name', product_to_edit['name']).strip()
|
| 2767 |
|
| 2768 |
-
price_kgs_str = request.form.get('price_kgs'
|
| 2769 |
-
|
| 2770 |
-
|
| 2771 |
-
|
| 2772 |
-
|
| 2773 |
-
|
|
|
|
|
|
|
|
|
|
| 2774 |
|
| 2775 |
discount_percent_str = request.form.get('discount_percent', str(product_to_edit.get('discount_percent',0)))
|
| 2776 |
try:
|
| 2777 |
-
discount_percent = int(discount_percent_str)
|
| 2778 |
if not (0 <= discount_percent <= 100): discount_percent = product_to_edit.get('discount_percent', 0)
|
| 2779 |
product_to_edit['discount_percent'] = discount_percent
|
| 2780 |
except ValueError: pass
|
|
|
|
| 139 |
'manage_products': 'Управление товарами',
|
| 140 |
'add_new_product': 'Добавить новый товар',
|
| 141 |
'product_name_label': 'Название товара *:',
|
| 142 |
+
'product_price_kgs_label': 'Цена (KGS):',
|
| 143 |
'product_discount_percent_label': 'Скидка (%):',
|
| 144 |
'product_description_label': 'Описание:',
|
| 145 |
'product_category_label': 'Категория:',
|
|
|
|
| 179 |
'delete_button': 'Удалить',
|
| 180 |
'editing_product_title': 'Редактирование: {product_name}',
|
| 181 |
'product_name_edit_label': 'Название *:',
|
| 182 |
+
'product_price_kgs_edit_label': 'Цена (KGS):',
|
| 183 |
'product_discount_percent_edit_label': 'Скидка (%):',
|
| 184 |
'product_description_edit_label': 'Описание:',
|
| 185 |
'product_category_edit_label': 'Категория:',
|
|
|
|
| 215 |
'flash_supplier_already_exists': "Поставщик '{supplier_name}' уже существует.",
|
| 216 |
'flash_supplier_delete_success': "Поставщик '{supplier_name}' удален.",
|
| 217 |
'flash_supplier_delete_failed': "Не удалось удалить поставщика '{supplier_name}'.",
|
| 218 |
+
'flash_product_name_price_required': 'Название товара обязательно.',
|
| 219 |
'flash_invalid_price_format': 'Неверный формат цены.',
|
| 220 |
'flash_invalid_discount_format': 'Неверный формат скидки (0-100).',
|
| 221 |
'flash_photo_limit_reached': 'Загружено только первые {photo_limit} фото.',
|
|
|
|
| 1939 |
<label for="add_name">{{ get_translation('product_name_label') }}</label>
|
| 1940 |
<input type="text" id="add_name" name="name" required>
|
| 1941 |
<label for="add_price_kgs">{{ get_translation('product_price_kgs_label') }}</label>
|
| 1942 |
+
<input type="number" id="add_price_kgs" name="price_kgs" step="0.01" min="0">
|
| 1943 |
<label for="add_discount_percent">{{ get_translation('product_discount_percent_label') }}</label>
|
| 1944 |
<input type="number" id="add_discount_percent" name="discount_percent" step="1" min="0" max="100" value="0">
|
| 1945 |
<label for="add_description">{{ get_translation('product_description_label') }}</label>
|
|
|
|
| 2065 |
<label>{{ get_translation('product_name_edit_label') }}</label>
|
| 2066 |
<input type="text" name="name" value="{{ product_info['name'] }}" required>
|
| 2067 |
<label>{{ get_translation('product_price_kgs_edit_label') }}</label>
|
| 2068 |
+
<input type="number" name="price_kgs" step="0.01" min="0" value="{{ product_info.price_kgs }}">
|
| 2069 |
<label>{{ get_translation('product_discount_percent_edit_label') }}</label>
|
| 2070 |
<input type="number" name="discount_percent" step="1" min="0" max="100" value="{{ product_info.get('discount_percent', 0) }}">
|
| 2071 |
<label>{{ get_translation('product_description_edit_label') }}</label>
|
|
|
|
| 2674 |
if action == 'add_product':
|
| 2675 |
name = request.form.get('name', '').strip()
|
| 2676 |
price_kgs_str = request.form.get('price_kgs', '').replace(',', '.')
|
| 2677 |
+
if not name:
|
| 2678 |
return jsonify({'error': get_translation('flash_product_name_price_required')}), 400
|
| 2679 |
try:
|
| 2680 |
+
price_kgs = round(float(price_kgs_str), 2) if price_kgs_str.strip() else 0.0
|
| 2681 |
+
if price_kgs < 0: price_kgs = 0.0
|
| 2682 |
except ValueError:
|
| 2683 |
return jsonify({'error': get_translation('flash_invalid_price_format')}), 400
|
| 2684 |
|
| 2685 |
discount_percent_str = request.form.get('discount_percent', '0')
|
| 2686 |
try:
|
| 2687 |
+
discount_percent = int(discount_percent_str) if discount_percent_str.strip() else 0
|
| 2688 |
if not (0 <= discount_percent <= 100): discount_percent = 0
|
| 2689 |
except ValueError:
|
| 2690 |
discount_percent = 0
|
|
|
|
| 2765 |
|
| 2766 |
product_to_edit['name'] = request.form.get('name', product_to_edit['name']).strip()
|
| 2767 |
|
| 2768 |
+
price_kgs_str = request.form.get('price_kgs')
|
| 2769 |
+
if price_kgs_str is not None:
|
| 2770 |
+
price_kgs_str = price_kgs_str.replace(',', '.')
|
| 2771 |
+
try:
|
| 2772 |
+
product_to_edit['price_kgs'] = round(float(price_kgs_str), 2) if price_kgs_str.strip() else 0.0
|
| 2773 |
+
if product_to_edit['price_kgs'] < 0:
|
| 2774 |
+
product_to_edit['price_kgs'] = 0.0
|
| 2775 |
+
except ValueError:
|
| 2776 |
+
pass
|
| 2777 |
|
| 2778 |
discount_percent_str = request.form.get('discount_percent', str(product_to_edit.get('discount_percent',0)))
|
| 2779 |
try:
|
| 2780 |
+
discount_percent = int(discount_percent_str) if discount_percent_str.strip() else 0
|
| 2781 |
if not (0 <= discount_percent <= 100): discount_percent = product_to_edit.get('discount_percent', 0)
|
| 2782 |
product_to_edit['discount_percent'] = discount_percent
|
| 2783 |
except ValueError: pass
|