Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from flask import Flask, render_template_string, request, redirect, url_for
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
import logging
|
|
@@ -80,7 +80,6 @@ def upload_db_to_hf():
|
|
| 80 |
except Exception as e:
|
| 81 |
logging.error(f"Ошибка при загрузке резервной копии на Hugging Face: {e}")
|
| 82 |
|
| 83 |
-
|
| 84 |
def download_db_from_hf():
|
| 85 |
if not HF_TOKEN_READ:
|
| 86 |
return
|
|
@@ -209,20 +208,10 @@ catalog_html = '''
|
|
| 209 |
}
|
| 210 |
.products-grid {
|
| 211 |
display: grid;
|
| 212 |
-
grid-template-columns: repeat(
|
| 213 |
gap: 15px;
|
| 214 |
padding: 10px;
|
| 215 |
}
|
| 216 |
-
@media (max-width: 768px) {
|
| 217 |
-
.products-grid {
|
| 218 |
-
grid-template-columns: repeat(2, 1fr);
|
| 219 |
-
}
|
| 220 |
-
}
|
| 221 |
-
@media (max-width: 480px) {
|
| 222 |
-
.products-grid {
|
| 223 |
-
grid-template-columns: 1fr;
|
| 224 |
-
}
|
| 225 |
-
}
|
| 226 |
.product {
|
| 227 |
background: var(--light-text);
|
| 228 |
border-radius: 15px;
|
|
@@ -331,7 +320,22 @@ catalog_html = '''
|
|
| 331 |
box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
|
| 332 |
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
| 333 |
z-index: 1000;
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
.modal {
|
| 336 |
display: none;
|
| 337 |
position: fixed;
|
|
@@ -415,7 +419,7 @@ catalog_html = '''
|
|
| 415 |
|
| 416 |
.quantity-input, .color-select {
|
| 417 |
width: 100%;
|
| 418 |
-
max-width:
|
| 419 |
padding: 8px;
|
| 420 |
border: 1px solid var(--secondary-color);
|
| 421 |
border-radius: 8px;
|
|
@@ -423,7 +427,15 @@ catalog_html = '''
|
|
| 423 |
margin: 5px 0;
|
| 424 |
display: block;
|
| 425 |
margin-bottom: 15px;
|
|
|
|
| 426 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
.modal-content button {
|
| 428 |
margin-top: 0;
|
| 429 |
}
|
|
@@ -445,17 +457,6 @@ catalog_html = '''
|
|
| 445 |
background-color: #BA68C8;
|
| 446 |
box-shadow: 0 4px 15px rgba(186, 104, 200, 0.4);
|
| 447 |
}
|
| 448 |
-
#cart-count {
|
| 449 |
-
position: absolute;
|
| 450 |
-
top: -5px;
|
| 451 |
-
right: -5px;
|
| 452 |
-
background-color: red;
|
| 453 |
-
color: white;
|
| 454 |
-
border-radius: 50%;
|
| 455 |
-
padding: 2px 5px;
|
| 456 |
-
font-size: 0.7em;
|
| 457 |
-
display: none;
|
| 458 |
-
}
|
| 459 |
@media (max-width: 768px) {
|
| 460 |
.header {
|
| 461 |
flex-direction: column;
|
|
@@ -474,10 +475,35 @@ catalog_html = '''
|
|
| 474 |
}
|
| 475 |
@media (max-width: 480px) {
|
| 476 |
.products-grid {
|
| 477 |
-
grid-template-columns: 1fr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
}
|
| 479 |
.modal-content {
|
| 480 |
margin: 15% auto;
|
|
|
|
| 481 |
}
|
| 482 |
}
|
| 483 |
</style>
|
|
@@ -491,7 +517,7 @@ catalog_html = '''
|
|
| 491 |
<div class="filters-container">
|
| 492 |
<button class="category-filter active" data-category="all">Все категории</button>
|
| 493 |
{% for category in categories %}
|
| 494 |
-
<button class="category-filter" data-category="{{ category }}">{{ category }}</button>
|
| 495 |
{% endfor %}
|
| 496 |
</div>
|
| 497 |
<div class="search-container">
|
|
@@ -677,7 +703,7 @@ catalog_html = '''
|
|
| 677 |
if (cart.length > 0) {
|
| 678 |
cartButton.style.display = 'block';
|
| 679 |
cartCount.textContent = totalItems;
|
| 680 |
-
cartCount.style.display =
|
| 681 |
} else {
|
| 682 |
cartButton.style.display = 'none';
|
| 683 |
cartCount.style.display = 'none';
|
|
@@ -702,7 +728,7 @@ catalog_html = '''
|
|
| 702 |
${photoUrl ? `<img src="${photoUrl}" alt="${item.name}">` : ''}
|
| 703 |
<div class="item-details">
|
| 704 |
<strong>${item.name}</strong>
|
| 705 |
-
<p>${item.price} с × ${item.quantity} (Цвет: ${item.color})</p>
|
| 706 |
</div>
|
| 707 |
</div>
|
| 708 |
<span>${itemTotal} с</span>
|
|
@@ -735,7 +761,6 @@ catalog_html = '''
|
|
| 735 |
const whatsappUrl = `https://api.whatsapp.com/send?phone=${phoneNumber}&text=${encodeURIComponent(orderText)}`;
|
| 736 |
|
| 737 |
window.open(whatsappUrl, '_blank');
|
| 738 |
-
|
| 739 |
}
|
| 740 |
|
| 741 |
function clearCart() {
|
|
@@ -866,6 +891,7 @@ def admin():
|
|
| 866 |
else:
|
| 867 |
return "Ошибка: Категория не найдена.", 400
|
| 868 |
except Exception as e:
|
|
|
|
| 869 |
return f"Ошибка при удалении категории: {e}", 500
|
| 870 |
|
| 871 |
elif action == 'add':
|
|
@@ -991,6 +1017,7 @@ def admin():
|
|
| 991 |
except ValueError:
|
| 992 |
return "Ошибка: Неверный индекс товара.", 400
|
| 993 |
except Exception as e:
|
|
|
|
| 994 |
return f"Ошибка при редактировании товара: {e}", 500
|
| 995 |
|
| 996 |
|
|
@@ -1006,6 +1033,7 @@ def admin():
|
|
| 1006 |
except ValueError:
|
| 1007 |
return "Ошибка: Неверный индекс товара.", 400
|
| 1008 |
except Exception as e:
|
|
|
|
| 1009 |
return f"Ошибка при удалении товара: {e}", 500
|
| 1010 |
|
| 1011 |
admin_html = '''
|
|
@@ -1241,6 +1269,7 @@ def admin():
|
|
| 1241 |
<div id="add-color-inputs">
|
| 1242 |
<div class="color-input-group">
|
| 1243 |
<input type="text" name="colors" placeholder="Например: Красный">
|
|
|
|
| 1244 |
</div>
|
| 1245 |
</div>
|
| 1246 |
<button type="button" class="add-color-btn" onclick="addColorInput('add-color-inputs')">Добавить цвет</button>
|
|
@@ -1271,7 +1300,7 @@ def admin():
|
|
| 1271 |
</div>
|
| 1272 |
|
| 1273 |
<h2>Управление базой данных</h2>
|
| 1274 |
-
<form method="POST" action="{{ url_for('backup') }}" style="display: inline-block;">
|
| 1275 |
<button type="submit">Создать резервную копию на HF</button>
|
| 1276 |
</form>
|
| 1277 |
<form method="GET" action="{{ url_for('download') }}" style="display: inline-block;">
|
|
@@ -1361,6 +1390,20 @@ def admin():
|
|
| 1361 |
function removeColorInput(buttonElement) {
|
| 1362 |
buttonElement.closest('.color-input-group').remove();
|
| 1363 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1364 |
</script>
|
| 1365 |
</body>
|
| 1366 |
</html>
|
|
|
|
| 1 |
+
from flask import Flask, render_template_string, request, redirect, url_for, send_from_directory
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
import logging
|
|
|
|
| 80 |
except Exception as e:
|
| 81 |
logging.error(f"Ошибка при загрузке резервной копии на Hugging Face: {e}")
|
| 82 |
|
|
|
|
| 83 |
def download_db_from_hf():
|
| 84 |
if not HF_TOKEN_READ:
|
| 85 |
return
|
|
|
|
| 208 |
}
|
| 209 |
.products-grid {
|
| 210 |
display: grid;
|
| 211 |
+
grid-template-columns: repeat(2, 1fr); /* Fixed 2 columns */
|
| 212 |
gap: 15px;
|
| 213 |
padding: 10px;
|
| 214 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
.product {
|
| 216 |
background: var(--light-text);
|
| 217 |
border-radius: 15px;
|
|
|
|
| 320 |
box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
|
| 321 |
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
| 322 |
z-index: 1000;
|
| 323 |
+
position: relative;
|
| 324 |
+
}
|
| 325 |
+
#cart-button span#cart-count {
|
| 326 |
+
position: absolute;
|
| 327 |
+
top: -5px;
|
| 328 |
+
right: -5px;
|
| 329 |
+
background-color: red;
|
| 330 |
+
color: white;
|
| 331 |
+
border-radius: 50%;
|
| 332 |
+
padding: 2px 5px;
|
| 333 |
+
font-size: 0.7em;
|
| 334 |
+
display: none;
|
| 335 |
+
line-height: 1;
|
| 336 |
+
min-width: 18px;
|
| 337 |
+
text-align: center;
|
| 338 |
+
}
|
| 339 |
.modal {
|
| 340 |
display: none;
|
| 341 |
position: fixed;
|
|
|
|
| 419 |
|
| 420 |
.quantity-input, .color-select {
|
| 421 |
width: 100%;
|
| 422 |
+
max-width: 150px;
|
| 423 |
padding: 8px;
|
| 424 |
border: 1px solid var(--secondary-color);
|
| 425 |
border-radius: 8px;
|
|
|
|
| 427 |
margin: 5px 0;
|
| 428 |
display: block;
|
| 429 |
margin-bottom: 15px;
|
| 430 |
+
box-sizing: border-box;
|
| 431 |
}
|
| 432 |
+
.modal-content label {
|
| 433 |
+
font-weight: 500;
|
| 434 |
+
display: block;
|
| 435 |
+
margin-bottom: 5px;
|
| 436 |
+
margin-top: 0;
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
.modal-content button {
|
| 440 |
margin-top: 0;
|
| 441 |
}
|
|
|
|
| 457 |
background-color: #BA68C8;
|
| 458 |
box-shadow: 0 4px 15px rgba(186, 104, 200, 0.4);
|
| 459 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
@media (max-width: 768px) {
|
| 461 |
.header {
|
| 462 |
flex-direction: column;
|
|
|
|
| 475 |
}
|
| 476 |
@media (max-width: 480px) {
|
| 477 |
.products-grid {
|
| 478 |
+
grid-template-columns: repeat(2, 1fr); /* Keep 2 columns even smaller */
|
| 479 |
+
gap: 10px;
|
| 480 |
+
}
|
| 481 |
+
.product {
|
| 482 |
+
padding: 10px;
|
| 483 |
+
}
|
| 484 |
+
.product-image {
|
| 485 |
+
border-radius: 8px;
|
| 486 |
+
}
|
| 487 |
+
.product h2 {
|
| 488 |
+
font-size: 0.9rem;
|
| 489 |
+
margin: 8px 0 4px 0;
|
| 490 |
+
}
|
| 491 |
+
.product-price {
|
| 492 |
+
font-size: 1rem;
|
| 493 |
+
}
|
| 494 |
+
.product-description {
|
| 495 |
+
font-size: 0.7rem;
|
| 496 |
+
margin-bottom: 10px;
|
| 497 |
+
}
|
| 498 |
+
.product-button {
|
| 499 |
+
padding: 6px;
|
| 500 |
+
font-size: 0.7rem;
|
| 501 |
+
border-radius: 6px;
|
| 502 |
+
margin: 3px 0;
|
| 503 |
}
|
| 504 |
.modal-content {
|
| 505 |
margin: 15% auto;
|
| 506 |
+
padding: 15px;
|
| 507 |
}
|
| 508 |
}
|
| 509 |
</style>
|
|
|
|
| 517 |
<div class="filters-container">
|
| 518 |
<button class="category-filter active" data-category="all">Все категории</button>
|
| 519 |
{% for category in categories %}
|
| 520 |
+
<button class="category-filter" data-category="{{ category|e }}">{{ category|e }}</button>
|
| 521 |
{% endfor %}
|
| 522 |
</div>
|
| 523 |
<div class="search-container">
|
|
|
|
| 703 |
if (cart.length > 0) {
|
| 704 |
cartButton.style.display = 'block';
|
| 705 |
cartCount.textContent = totalItems;
|
| 706 |
+
cartCount.style.display = 'block';
|
| 707 |
} else {
|
| 708 |
cartButton.style.display = 'none';
|
| 709 |
cartCount.style.display = 'none';
|
|
|
|
| 728 |
${photoUrl ? `<img src="${photoUrl}" alt="${item.name}">` : ''}
|
| 729 |
<div class="item-details">
|
| 730 |
<strong>${item.name}</strong>
|
| 731 |
+
<p>${item.price} с × ${item.quantity} шт. (Цвет: ${item.color})</p>
|
| 732 |
</div>
|
| 733 |
</div>
|
| 734 |
<span>${itemTotal} с</span>
|
|
|
|
| 761 |
const whatsappUrl = `https://api.whatsapp.com/send?phone=${phoneNumber}&text=${encodeURIComponent(orderText)}`;
|
| 762 |
|
| 763 |
window.open(whatsappUrl, '_blank');
|
|
|
|
| 764 |
}
|
| 765 |
|
| 766 |
function clearCart() {
|
|
|
|
| 891 |
else:
|
| 892 |
return "Ошибка: Категория не найдена.", 400
|
| 893 |
except Exception as e:
|
| 894 |
+
logging.error(f"Ошибка при удалении категории: {e}")
|
| 895 |
return f"Ошибка при удалении категории: {e}", 500
|
| 896 |
|
| 897 |
elif action == 'add':
|
|
|
|
| 1017 |
except ValueError:
|
| 1018 |
return "Ошибка: Неверный индекс товара.", 400
|
| 1019 |
except Exception as e:
|
| 1020 |
+
logging.error(f"Ошибка при редактировании товара: {e}")
|
| 1021 |
return f"Ошибка при редактировании товара: {e}", 500
|
| 1022 |
|
| 1023 |
|
|
|
|
| 1033 |
except ValueError:
|
| 1034 |
return "Ошибка: Неверный индекс товара.", 400
|
| 1035 |
except Exception as e:
|
| 1036 |
+
logging.error(f"Ошибка при удалении товара: {e}")
|
| 1037 |
return f"Ошибка при удалении товара: {e}", 500
|
| 1038 |
|
| 1039 |
admin_html = '''
|
|
|
|
| 1269 |
<div id="add-color-inputs">
|
| 1270 |
<div class="color-input-group">
|
| 1271 |
<input type="text" name="colors" placeholder="Например: Красный">
|
| 1272 |
+
<button type="button" class="remove-color-btn" onclick="removeColorInput(this)">Удалить</button>
|
| 1273 |
</div>
|
| 1274 |
</div>
|
| 1275 |
<button type="button" class="add-color-btn" onclick="addColorInput('add-color-inputs')">Добавить цвет</button>
|
|
|
|
| 1300 |
</div>
|
| 1301 |
|
| 1302 |
<h2>Управление базой данных</h2>
|
| 1303 |
+
<form method="POST" action="{{ url_for('backup') }}" style="display: inline-block; margin-right: 10px;">
|
| 1304 |
<button type="submit">Создать резервную копию на HF</button>
|
| 1305 |
</form>
|
| 1306 |
<form method="GET" action="{{ url_for('download') }}" style="display: inline-block;">
|
|
|
|
| 1390 |
function removeColorInput(buttonElement) {
|
| 1391 |
buttonElement.closest('.color-input-group').remove();
|
| 1392 |
}
|
| 1393 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 1394 |
+
// Ensure at least one color input exists on load for new product form
|
| 1395 |
+
const addColorContainer = document.getElementById('add-color-inputs');
|
| 1396 |
+
if (addColorContainer && addColorContainer.children.length === 0) {
|
| 1397 |
+
addColorInput('add-color-inputs');
|
| 1398 |
+
}
|
| 1399 |
+
|
| 1400 |
+
// Ensure at least one color input exists on load for edit forms
|
| 1401 |
+
document.querySelectorAll('.edit-form [id^="edit-color-inputs-"]').forEach(container => {
|
| 1402 |
+
if (container.children.length === 0) {
|
| 1403 |
+
addColorInput(container.id);
|
| 1404 |
+
}
|
| 1405 |
+
});
|
| 1406 |
+
});
|
| 1407 |
</script>
|
| 1408 |
</body>
|
| 1409 |
</html>
|