Update app.py
Browse files
app.py
CHANGED
|
@@ -109,7 +109,7 @@ def catalog():
|
|
| 109 |
<head>
|
| 110 |
<meta charset="UTF-8">
|
| 111 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 112 |
-
<title>У Деда - ткани оптом
|
| 113 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 114 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
|
| 115 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/10.2.0/swiper-bundle.min.css">
|
|
@@ -480,34 +480,28 @@ def catalog():
|
|
| 480 |
</div>
|
| 481 |
<div class="products-grid" id="products-grid">
|
| 482 |
{% for product in products %}
|
| 483 |
-
<div class="product"
|
| 484 |
data-name="{{ product['name']|lower }}"
|
| 485 |
data-description="{{ product['description']|lower }}"
|
| 486 |
data-category="{{ product.get('category', 'Без категории') }}">
|
| 487 |
-
{
|
| 488 |
-
|
| 489 |
-
<
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
|
|
|
|
|
|
| 497 |
<button class="product-button add-to-cart" onclick="openQuantityModal({{ loop.index0 }})">В корзину</button>
|
| 498 |
</div>
|
| 499 |
{% endfor %}
|
| 500 |
</div>
|
| 501 |
</div>
|
| 502 |
|
| 503 |
-
<!-- Product Modal -->
|
| 504 |
-
<div id="productModal" class="modal">
|
| 505 |
-
<div class="modal-content">
|
| 506 |
-
<span class="close" onclick="closeModal('productModal')">×</span>
|
| 507 |
-
<div id="modalContent"></div>
|
| 508 |
-
</div>
|
| 509 |
-
</div>
|
| 510 |
-
|
| 511 |
<!-- Quantity and Color Modal -->
|
| 512 |
<div id="quantityModal" class="modal">
|
| 513 |
<div class="modal-content">
|
|
@@ -563,11 +557,6 @@ def catalog():
|
|
| 563 |
document.querySelector('.theme-toggle i').classList.replace('fa-moon', 'fa-sun');
|
| 564 |
}
|
| 565 |
|
| 566 |
-
function openModal(index) {
|
| 567 |
-
loadProductDetails(index);
|
| 568 |
-
document.getElementById('productModal').style.display = "block";
|
| 569 |
-
}
|
| 570 |
-
|
| 571 |
function closeModal(modalId) {
|
| 572 |
document.getElementById(modalId).style.display = "none";
|
| 573 |
}
|
|
@@ -580,15 +569,6 @@ def catalog():
|
|
| 580 |
document.getElementById('logoModal').style.display = 'none';
|
| 581 |
}
|
| 582 |
|
| 583 |
-
function loadProductDetails(index) {
|
| 584 |
-
fetch('/product/' + index)
|
| 585 |
-
.then(response => response.text())
|
| 586 |
-
.then(data => {
|
| 587 |
-
document.getElementById('modalContent').innerHTML = data;
|
| 588 |
-
})
|
| 589 |
-
.catch(error => console.error('Ошибка:', error));
|
| 590 |
-
}
|
| 591 |
-
|
| 592 |
function openQuantityModal(index) {
|
| 593 |
event.stopPropagation();
|
| 594 |
selectedProductIndex = index;
|
|
@@ -750,132 +730,215 @@ def product_detail(index):
|
|
| 750 |
return "Продукт не найден", 404
|
| 751 |
|
| 752 |
detail_html = '''
|
| 753 |
-
<
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 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|
| 846 |
-
<
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
document.addEventListener('keydown', function(event) {
|
| 874 |
-
if (event.key === 'Escape') {
|
| 875 |
-
closePhotoModal();
|
| 876 |
-
}
|
| 877 |
-
});
|
| 878 |
-
</script>
|
| 879 |
'''
|
| 880 |
return render_template_string(detail_html, product=product, repo_id=REPO_ID)
|
| 881 |
|
|
|
|
| 109 |
<head>
|
| 110 |
<meta charset="UTF-8">
|
| 111 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 112 |
+
<title>У Деда - ткани оптом</title>
|
| 113 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
| 114 |
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
|
| 115 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/10.2.0/swiper-bundle.min.css">
|
|
|
|
| 480 |
</div>
|
| 481 |
<div class="products-grid" id="products-grid">
|
| 482 |
{% for product in products %}
|
| 483 |
+
<div class="product"
|
| 484 |
data-name="{{ product['name']|lower }}"
|
| 485 |
data-description="{{ product['description']|lower }}"
|
| 486 |
data-category="{{ product.get('category', 'Без категории') }}">
|
| 487 |
+
<a href="{{ url_for('product_detail', index=loop.index0) }}" style="text-decoration: none; color: inherit;">
|
| 488 |
+
{% if product.get('photos') and product['photos']|length > 0 %}
|
| 489 |
+
<div class="product-image">
|
| 490 |
+
<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ product['photos'][0] }}"
|
| 491 |
+
alt="{{ product['name'] }}"
|
| 492 |
+
loading="lazy">
|
| 493 |
+
</div>
|
| 494 |
+
{% endif %}
|
| 495 |
+
<h2>{{ product['name'] }}</h2>
|
| 496 |
+
<div class="product-price">${{ product['price'] }}</div>
|
| 497 |
+
<p class="product-description">{{ product['description'][:50] }}{% if product['description']|length > 50 %}...{% endif %}</p>
|
| 498 |
+
</a>
|
| 499 |
<button class="product-button add-to-cart" onclick="openQuantityModal({{ loop.index0 }})">В корзину</button>
|
| 500 |
</div>
|
| 501 |
{% endfor %}
|
| 502 |
</div>
|
| 503 |
</div>
|
| 504 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
<!-- Quantity and Color Modal -->
|
| 506 |
<div id="quantityModal" class="modal">
|
| 507 |
<div class="modal-content">
|
|
|
|
| 557 |
document.querySelector('.theme-toggle i').classList.replace('fa-moon', 'fa-sun');
|
| 558 |
}
|
| 559 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
function closeModal(modalId) {
|
| 561 |
document.getElementById(modalId).style.display = "none";
|
| 562 |
}
|
|
|
|
| 569 |
document.getElementById('logoModal').style.display = 'none';
|
| 570 |
}
|
| 571 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 572 |
function openQuantityModal(index) {
|
| 573 |
event.stopPropagation();
|
| 574 |
selectedProductIndex = index;
|
|
|
|
| 730 |
return "Продукт не найден", 404
|
| 731 |
|
| 732 |
detail_html = '''
|
| 733 |
+
<!DOCTYPE html>
|
| 734 |
+
<html lang="ru">
|
| 735 |
+
<head>
|
| 736 |
+
<meta charset="UTF-8">
|
| 737 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 738 |
+
<title>{{ product['name'] }} - У Деда</title>
|
| 739 |
+
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
|
| 740 |
+
<style>
|
| 741 |
+
* {
|
| 742 |
+
margin: 0;
|
| 743 |
+
padding: 0;
|
| 744 |
+
box-sizing: border-box;
|
| 745 |
+
}
|
| 746 |
+
body {
|
| 747 |
+
font-family: 'Poppins', sans-serif;
|
| 748 |
+
background: linear-gradient(135deg, #f0f2f5, #e9ecef);
|
| 749 |
+
color: #2d3748;
|
| 750 |
+
line-height: 1.6;
|
| 751 |
+
}
|
| 752 |
+
.container {
|
| 753 |
+
max-width: 1300px;
|
| 754 |
+
margin: 0 auto;
|
| 755 |
+
padding: 20px;
|
| 756 |
+
}
|
| 757 |
+
.header {
|
| 758 |
+
display: flex;
|
| 759 |
+
justify-content: space-between;
|
| 760 |
+
align-items: center;
|
| 761 |
+
padding: 15px 0;
|
| 762 |
+
border-bottom: 1px solid #e2e8f0;
|
| 763 |
+
}
|
| 764 |
+
.header-logo {
|
| 765 |
+
width: 60px;
|
| 766 |
+
height: 60px;
|
| 767 |
+
border-radius: 50%;
|
| 768 |
+
object-fit: cover;
|
| 769 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
| 770 |
+
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
| 771 |
+
}
|
| 772 |
+
.header-logo:hover {
|
| 773 |
+
transform: scale(1.1);
|
| 774 |
+
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
|
| 775 |
+
}
|
| 776 |
+
.header h1 {
|
| 777 |
+
font-size: 1.5rem;
|
| 778 |
+
font-weight: 600;
|
| 779 |
+
margin-left: 15px;
|
| 780 |
+
}
|
| 781 |
+
.product-detail-container {
|
| 782 |
+
padding: 20px;
|
| 783 |
+
}
|
| 784 |
+
.product-detail-container h2 {
|
| 785 |
+
font-size: 1.8rem;
|
| 786 |
+
font-weight: 600;
|
| 787 |
+
margin-bottom: 20px;
|
| 788 |
+
text-align: center;
|
| 789 |
+
}
|
| 790 |
+
.image-grid {
|
| 791 |
+
display: grid;
|
| 792 |
+
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
|
| 793 |
+
gap: 10px;
|
| 794 |
+
margin-bottom: 20px;
|
| 795 |
+
}
|
| 796 |
+
.image-grid img {
|
| 797 |
+
width: 100%;
|
| 798 |
+
height: 100px;
|
| 799 |
+
object-fit: cover;
|
| 800 |
+
border-radius: 8px;
|
| 801 |
+
cursor: pointer;
|
| 802 |
+
transition: transform 0.3s ease;
|
| 803 |
+
}
|
| 804 |
+
.image-grid img:hover {
|
| 805 |
+
transform: scale(1.1);
|
| 806 |
+
}
|
| 807 |
+
.photo-modal {
|
| 808 |
+
display: none;
|
| 809 |
+
position: fixed;
|
| 810 |
+
top: 0;
|
| 811 |
+
left: 0;
|
| 812 |
+
width: 100%;
|
| 813 |
+
height: 100%;
|
| 814 |
+
background-color: rgba(0, 0, 0, 0.7);
|
| 815 |
+
z-index: 1003;
|
| 816 |
+
justify-content: center;
|
| 817 |
+
align-items: center;
|
| 818 |
+
}
|
| 819 |
+
.photo-modal-content {
|
| 820 |
+
width: 100%;
|
| 821 |
+
height: 100%;
|
| 822 |
+
position: relative;
|
| 823 |
+
display: flex;
|
| 824 |
+
justify-content: center;
|
| 825 |
+
align-items: center;
|
| 826 |
+
}
|
| 827 |
+
.photo-modal-content img {
|
| 828 |
+
width: 100%;
|
| 829 |
+
height: 100%;
|
| 830 |
+
object-fit: contain;
|
| 831 |
+
border-radius: 10px;
|
| 832 |
+
}
|
| 833 |
+
.photo-close {
|
| 834 |
+
position: absolute;
|
| 835 |
+
top: 15px;
|
| 836 |
+
right: 15px;
|
| 837 |
+
font-size: 2rem;
|
| 838 |
+
color: white;
|
| 839 |
+
cursor: pointer;
|
| 840 |
+
z-index: 1004;
|
| 841 |
+
}
|
| 842 |
+
.photo-close:hover {
|
| 843 |
+
color: #ddd;
|
| 844 |
+
}
|
| 845 |
+
.product-info p {
|
| 846 |
+
margin: 10px 0;
|
| 847 |
+
font-size: 1rem;
|
| 848 |
+
}
|
| 849 |
+
.back-button {
|
| 850 |
+
display: block;
|
| 851 |
+
width: 100%;
|
| 852 |
+
max-width: 300px;
|
| 853 |
+
margin: 20px auto;
|
| 854 |
+
padding: 12px;
|
| 855 |
+
border: none;
|
| 856 |
+
border-radius: 8px;
|
| 857 |
+
background-color: #3b82f6;
|
| 858 |
+
color: white;
|
| 859 |
+
font-size: 1rem;
|
| 860 |
+
font-weight: 500;
|
| 861 |
+
cursor: pointer;
|
| 862 |
+
text-align: center;
|
| 863 |
+
text-decoration: none;
|
| 864 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
| 865 |
+
}
|
| 866 |
+
.back-button:hover {
|
| 867 |
+
background-color: #2563eb;
|
| 868 |
+
box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
|
| 869 |
+
transform: translateY(-2px);
|
| 870 |
+
}
|
| 871 |
+
</style>
|
| 872 |
+
</head>
|
| 873 |
+
<body>
|
| 874 |
+
<div class="container">
|
| 875 |
+
<div class="header">
|
| 876 |
+
<a href="/">
|
| 877 |
+
<img src="''' + LOGO_URL + '''" alt="Logo" class="header-logo">
|
| 878 |
+
</a>
|
| 879 |
+
<h1>{{ product['name'] }}</h1>
|
| 880 |
+
</div>
|
| 881 |
+
|
| 882 |
+
<div class="product-detail-container">
|
| 883 |
+
<h2>{{ product['name'] }}</h2>
|
| 884 |
+
|
| 885 |
+
<div class="image-grid">
|
| 886 |
+
{% if product.get('photos') %}
|
| 887 |
+
{% for photo in product['photos'] %}
|
| 888 |
+
<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}"
|
| 889 |
+
alt="{{ product['name'] }}"
|
| 890 |
+
onclick="openPhotoModal('https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}')">
|
| 891 |
+
{% endfor %}
|
| 892 |
+
{% else %}
|
| 893 |
+
<p>Нет фотографий</p>
|
| 894 |
+
{% endif %}
|
| 895 |
+
</div>
|
| 896 |
+
|
| 897 |
+
<div id="photoModal" class="photo-modal">
|
| 898 |
+
<div class="photo-modal-content">
|
| 899 |
+
<span class="photo-close" onclick="closePhotoModal()">×</span>
|
| 900 |
+
<img id="photoImage" src="" alt="Фото товара">
|
| 901 |
+
</div>
|
| 902 |
+
</div>
|
| 903 |
|
| 904 |
+
<div class="product-info">
|
| 905 |
+
<p><strong>Категория:</strong> {{ product.get('category', 'Без категории') }}</p>
|
| 906 |
+
<p><strong>Цена:</strong> ${{ product['price'] }}</p>
|
| 907 |
+
<p><strong>Состав:</strong> {{ product['description'] }}</p>
|
| 908 |
+
<p><strong>Доступные цвета:</strong> {{ product.get('colors', ['Нет цветов'])|join(', ') }}</p>
|
| 909 |
+
<p><strong>Метров в рулоне:</strong> {{ product.get('roll_meters', 'Не указано') }}</p>
|
| 910 |
+
</div>
|
| 911 |
+
|
| 912 |
+
<a href="/" class="back-button">Вернуться в каталог</a>
|
| 913 |
</div>
|
| 914 |
</div>
|
| 915 |
|
| 916 |
+
<script>
|
| 917 |
+
function openPhotoModal(src) {
|
| 918 |
+
const modal = document.getElementById('photoModal');
|
| 919 |
+
document.getElementById('photoImage').src = src;
|
| 920 |
+
modal.style.display = 'flex';
|
| 921 |
+
}
|
| 922 |
+
|
| 923 |
+
function closePhotoModal() {
|
| 924 |
+
document.getElementById('photoModal').style.display = 'none';
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
window.onclick = function(event) {
|
| 928 |
+
const modal = document.getElementById('photoModal');
|
| 929 |
+
if (event.target === modal) {
|
| 930 |
+
closePhotoModal();
|
| 931 |
+
}
|
| 932 |
+
}
|
| 933 |
+
|
| 934 |
+
document.addEventListener('keydown', function(event) {
|
| 935 |
+
if (event.key === 'Escape') {
|
| 936 |
+
closePhotoModal();
|
| 937 |
+
}
|
| 938 |
+
});
|
| 939 |
+
</script>
|
| 940 |
+
</body>
|
| 941 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
'''
|
| 943 |
return render_template_string(detail_html, product=product, repo_id=REPO_ID)
|
| 944 |
|