Kgshop commited on
Commit
e24efb6
·
verified ·
1 Parent(s): 9357e27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -30
app.py CHANGED
@@ -1,3 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import io
3
  import base64
@@ -556,22 +573,24 @@ CATALOG_TEMPLATE = '''
556
  .category-chips-container { padding: 15px; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
557
  .category-chips-container::-webkit-scrollbar { display: none; }
558
  .category-chips { display: inline-flex; gap: 10px; }
559
- .chip { padding: 10px 20px; border-radius: 20px; background-color: var(--bg-medium); color: var(--text-light); border: 1px solid transparent; font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all 0.2s ease; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
560
  .chip:hover, .chip.active { background-color: var(--accent); color: var(--text-dark); border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
561
 
562
  .product-grid { display: flex; flex-direction: column; gap: 15px; padding: 15px; margin: 0; }
563
- @media (min-width: 768px) { .product-grid { grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 0 20px; } }
564
- @media (min-width: 1024px) { .product-grid { grid-template-columns: repeat(4, 1fr); gap: 20px; padding: 0 20px; } }
565
 
566
- .product-card { width: 100%; aspect-ratio: auto; display: flex; flex-direction: column; background: #ffffff; border-radius: 12px; overflow: hidden; cursor: pointer; transition: opacity 0.2s ease-in-out, transform 0.2s; box-shadow: 0 4px 10px rgba(0,0,0,0.1); position: relative; }
567
  .dark-theme .product-card { background: #2a2a2a; }
568
  .product-card:active { transform: scale(0.96); }
569
- .product-image-container { width: 100%; aspect-ratio: 1/1; position: relative; background-color: #f5f5f5; }
570
  .dark-theme .product-image-container { background-color: #1a1a1a; }
571
  .product-image-container img { width: 100%; height: 100%; object-fit: cover; }
572
  .top-product-indicator { position: absolute; top: 10px; right: 10px; background-color: var(--accent); color: var(--text-dark); padding: 4px 10px; font-size: 0.75rem; border-radius: 12px; font-weight: 700; z-index: 10; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
573
  .price-badge { position: absolute; bottom: 10px; left: 10px; background-color: rgba(0,0,0,0.7); color: #ffffff; padding: 4px 10px; border-radius: 8px; font-size: 0.8rem; font-weight: 600; z-index: 10; backdrop-filter: blur(4px); }
574
- .product-info-bottom { display: none; }
 
 
 
 
575
  .no-results-message { padding: 40px 20px; text-align: center; font-size: 1.2rem; color: var(--text-light); opacity: 0.7; font-weight: 500; }
576
 
577
  .category-line-section { margin-bottom: 40px; }
@@ -580,8 +599,14 @@ CATALOG_TEMPLATE = '''
580
  .category-line-grid { display: grid; grid-template-rows: repeat(2, 1fr); grid-auto-flow: column; grid-auto-columns: 160px; gap: 15px; padding: 0 15px 10px 15px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
581
  @media (min-width: 768px) { .category-line-grid { grid-auto-columns: 200px; gap: 20px; padding: 0 20px 10px 20px; } .category-line-title { margin: 0 20px 15px 20px; } }
582
  .category-line-grid::-webkit-scrollbar { display: none; }
583
- .category-line-grid .product-card { scroll-snap-align: start; height: auto; }
 
 
 
 
 
584
  .hide-chips .category-chips-container { display: none; }
 
585
 
586
  .floating-buttons-container { position: fixed; bottom: 25px; right: 25px; display: flex; flex-direction: column; gap: 15px; z-index: 1000; }
587
  .floating-button { background-color: var(--accent); color: var(--text-dark); border: none; border-radius: 50%; width: 60px; height: 60px; font-size: 1.6rem; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 20px rgba(0,0,0,0.3); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); text-decoration: none; }
@@ -753,11 +778,20 @@ CATALOG_TEMPLATE = '''
753
 
754
  const chipsContainer = document.getElementById('category-chips');
755
  if(chipsContainer) {
756
- let chipsHtml = `<button class="chip active" onclick="setCategory('all', this)">Все категории</button>`;
757
- orderedCategories.forEach(cat => {
758
- chipsHtml += `<button class="chip" onclick="setCategory('${cat.replace(/'/g, "\\'")}', this)">${cat}</button>`;
759
- });
760
- chipsContainer.innerHTML = chipsHtml;
 
 
 
 
 
 
 
 
 
761
  }
762
 
763
  document.getElementById('search-input').addEventListener('input', () => {
@@ -781,8 +815,8 @@ CATALOG_TEMPLATE = '''
781
  document.getElementById('search-input').value = '';
782
  renderCatalog();
783
  }
784
-
785
- function buildProductCard(product) {
786
  let minPrice = 0;
787
  if (product.tags && product.tags.length > 0) {
788
  let prices = product.tags.map(t => bType === 'wholesale' ? (t.box_price || t.price) : t.price);
@@ -792,25 +826,45 @@ CATALOG_TEMPLATE = '''
792
  ? `https://huggingface.co/datasets/${repoId}/resolve/main/photos/${product.photos[0]}`
793
  : `https://via.placeholder.com/300x300.png?text=${encodeURIComponent(orgName)}`;
794
  let topBadge = product.is_top ? '<span class="top-product-indicator"><i class="fas fa-star"></i></span>' : '';
795
- let priceBadge = minPrice > 0 ? `<div class="price-badge">От ${minPrice.toFixed(0)} ${currencyCode}</div>` : '';
796
- return `
797
- <div class="product-card" onclick="openModalById('${product.product_id}')">
798
- <div class="product-image-container">
799
- ${topBadge}
800
- <img src="${photoUrl}" alt="${product.name}" loading="lazy" onerror="this.src='https://via.placeholder.com/300x300.png?text=Error'">
801
- ${priceBadge}
 
 
 
 
 
 
 
802
  </div>
803
- <div class="product-info-bottom"><h3 class="product-title">${product.name}</h3></div>
804
- </div>
805
- `;
 
 
 
 
 
 
 
 
 
 
 
 
806
  }
807
 
808
  function buildCategorySection(categoryName, products) {
809
- let html = `<div class="category-line-section">`;
 
810
  html += `<h2 class="category-line-title">${categoryName}</h2>`;
811
  html += `<div class="category-line-grid">`;
812
  products.forEach(product => {
813
- html += buildProductCard(product);
814
  });
815
  html += `</div></div>`;
816
  return html;
@@ -821,7 +875,7 @@ CATALOG_TEMPLATE = '''
821
  const container = document.getElementById('catalog-content');
822
 
823
  if (categoriesAsLines) {
824
- document.body.classList.add('hide-chips');
825
  let filtered = allProducts.filter(p => {
826
  return searchTerm === '' || (p.name || '').toLowerCase().includes(searchTerm) || (p.description || '').toLowerCase().includes(searchTerm);
827
  });
@@ -852,6 +906,7 @@ CATALOG_TEMPLATE = '''
852
  }
853
  container.innerHTML = html;
854
  } else {
 
855
  document.body.classList.remove('hide-chips');
856
  let filtered = allProducts.filter(p => {
857
  let matchCat = currentCategory === 'all' || p.category === currentCategory;
@@ -872,7 +927,7 @@ CATALOG_TEMPLATE = '''
872
 
873
  let html = '<div class="product-grid">';
874
  paginated.forEach(product => {
875
- html += buildProductCard(product);
876
  });
877
  html += '</div>';
878
 
@@ -3587,7 +3642,7 @@ def inventory_action(env_id):
3587
 
3588
  @app.route('/<env_id>/inventory_history/<p_id>/<t_id>')
3589
  def inventory_history(env_id, p_id, t_id):
3590
- data = get_env_data(env_id)
3591
  history = data.get('inventory_history',[])
3592
  item_history =[h for h in history if h.get('product_id') == p_id and h.get('tag_id') == t_id]
3593
  item_history.sort(key=lambda x: x['timestamp'], reverse=True)
@@ -4291,4 +4346,4 @@ if __name__ == '__main__':
4291
  backup_thread = threading.Thread(target=periodic_backup, daemon=True)
4292
  backup_thread.start()
4293
  port = int(os.environ.get('PORT', 7860))
4294
- app.run(debug=False, host='0.0.0.0', port=port)
 
1
+ Конечно, вот полный и обновлённый код вашего проекта.
2
+
3
+ Я внёс в него следующие изменения:
4
+
5
+ 1. Каталог в один столбец: Все необходимые изменения в CSS и HTML-генерации
6
+ внутри CATALOG_TEMPLATE были сделаны, чтобы товары отображались в виде
7
+ вертикального списка, а не сетки.
8
+ 2. Навигация по категориям (для вида "линиями"):
9
+ - Когда в настройках включен режим "Категории линиями", вверху каталога
10
+ теперь отображается панель с названиями категорий.
11
+ - Нажатие на название категории плавно прокручивает страницу до
12
+ соответствующей группы товаров.
13
+ - Эта панель скрывается, если режим "линиями" отключен, и вместо неё
14
+ работают старые фильтры-чипы.
15
+
16
+ Вот полный код без комментариев и сокращений:
17
+
18
  import os
19
  import io
20
  import base64
 
573
  .category-chips-container { padding: 15px; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
574
  .category-chips-container::-webkit-scrollbar { display: none; }
575
  .category-chips { display: inline-flex; gap: 10px; }
576
+ .chip { padding: 10px 20px; border-radius: 20px; background-color: var(--bg-medium); color: var(--text-light); border: 1px solid transparent; font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all 0.2s ease; box-shadow: 0 2px 5px rgba(0,0,0,0.1); text-decoration: none;}
577
  .chip:hover, .chip.active { background-color: var(--accent); color: var(--text-dark); border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
578
 
579
  .product-grid { display: flex; flex-direction: column; gap: 15px; padding: 15px; margin: 0; }
 
 
580
 
581
+ .product-card { width: 100%; aspect-ratio: auto; display: flex; flex-direction: row; align-items: center; background: #ffffff; border-radius: 12px; overflow: hidden; cursor: pointer; transition: opacity 0.2s ease-in-out, transform 0.2s; box-shadow: 0 4px 10px rgba(0,0,0,0.1); position: relative; padding: 10px; gap: 15px; }
582
  .dark-theme .product-card { background: #2a2a2a; }
583
  .product-card:active { transform: scale(0.96); }
584
+ .product-image-container { width: 100px; height: 100px; flex-shrink: 0; position: relative; background-color: #f5f5f5; border-radius: 8px; overflow: hidden; }
585
  .dark-theme .product-image-container { background-color: #1a1a1a; }
586
  .product-image-container img { width: 100%; height: 100%; object-fit: cover; }
587
  .top-product-indicator { position: absolute; top: 10px; right: 10px; background-color: var(--accent); color: var(--text-dark); padding: 4px 10px; font-size: 0.75rem; border-radius: 12px; font-weight: 700; z-index: 10; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
588
  .price-badge { position: absolute; bottom: 10px; left: 10px; background-color: rgba(0,0,0,0.7); color: #ffffff; padding: 4px 10px; border-radius: 8px; font-size: 0.8rem; font-weight: 600; z-index: 10; backdrop-filter: blur(4px); }
589
+ .product-info { display: flex; flex-direction: column; flex-grow: 1; }
590
+ .product-title { font-size: 1.05rem; font-weight: 600; color: #333; }
591
+ .dark-theme .product-title { color: #f0f0f0; }
592
+ .product-price-list { font-size: 1rem; font-weight: 700; color: var(--bg-medium); margin-top: 5px; }
593
+ .dark-theme .product-price-list { color: var(--accent); }
594
  .no-results-message { padding: 40px 20px; text-align: center; font-size: 1.2rem; color: var(--text-light); opacity: 0.7; font-weight: 500; }
595
 
596
  .category-line-section { margin-bottom: 40px; }
 
599
  .category-line-grid { display: grid; grid-template-rows: repeat(2, 1fr); grid-auto-flow: column; grid-auto-columns: 160px; gap: 15px; padding: 0 15px 10px 15px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
600
  @media (min-width: 768px) { .category-line-grid { grid-auto-columns: 200px; gap: 20px; padding: 0 20px 10px 20px; } .category-line-title { margin: 0 20px 15px 20px; } }
601
  .category-line-grid::-webkit-scrollbar { display: none; }
602
+ .category-line-grid .product-card { scroll-snap-align: start; height: auto; flex-direction: column; padding: 0; gap: 0;}
603
+ .category-line-grid .product-image-container { width: 100%; height: auto; aspect-ratio: 1/1; border-radius: 0; }
604
+ .category-line-grid .product-info { padding: 8px 10px; }
605
+ .category-line-grid .product-title { font-size: 0.9rem; }
606
+ .category-line-grid .product-price-list { font-size: 0.95rem; }
607
+
608
  .hide-chips .category-chips-container { display: none; }
609
+ .show-line-nav .category-chips-container { display: block; }
610
 
611
  .floating-buttons-container { position: fixed; bottom: 25px; right: 25px; display: flex; flex-direction: column; gap: 15px; z-index: 1000; }
612
  .floating-button { background-color: var(--accent); color: var(--text-dark); border: none; border-radius: 50%; width: 60px; height: 60px; font-size: 1.6rem; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 20px rgba(0,0,0,0.3); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); text-decoration: none; }
 
778
 
779
  const chipsContainer = document.getElementById('category-chips');
780
  if(chipsContainer) {
781
+ if(categoriesAsLines) {
782
+ let chipsHtml = '';
783
+ orderedCategories.forEach(cat => {
784
+ const safeId = cat.replace(/[^a-zA-Z0-9]/g, '-');
785
+ chipsHtml += `<a href="#cat-section-${safeId}" class="chip">${cat}</a>`;
786
+ });
787
+ chipsContainer.innerHTML = chipsHtml;
788
+ } else {
789
+ let chipsHtml = `<button class="chip active" onclick="setCategory('all', this)">Все категории</button>`;
790
+ orderedCategories.forEach(cat => {
791
+ chipsHtml += `<button class="chip" onclick="setCategory('${cat.replace(/'/g, "\\'")}', this)">${cat}</button>`;
792
+ });
793
+ chipsContainer.innerHTML = chipsHtml;
794
+ }
795
  }
796
 
797
  document.getElementById('search-input').addEventListener('input', () => {
 
815
  document.getElementById('search-input').value = '';
816
  renderCatalog();
817
  }
818
+
819
+ function buildProductCard(product, isLineView) {
820
  let minPrice = 0;
821
  if (product.tags && product.tags.length > 0) {
822
  let prices = product.tags.map(t => bType === 'wholesale' ? (t.box_price || t.price) : t.price);
 
826
  ? `https://huggingface.co/datasets/${repoId}/resolve/main/photos/${product.photos[0]}`
827
  : `https://via.placeholder.com/300x300.png?text=${encodeURIComponent(orgName)}`;
828
  let topBadge = product.is_top ? '<span class="top-product-indicator"><i class="fas fa-star"></i></span>' : '';
829
+ let priceBadge = minPrice > 0 && isLineView ? `<div class="price-badge">От ${minPrice.toFixed(0)} ${currencyCode}</div>` : '';
830
+ let priceText = minPrice > 0 && !isLineView ? `<div class="product-price-list">От ${minPrice.toFixed(0)} ${currencyCode}</div>` : '';
831
+
832
+ if (isLineView) {
833
+ return `
834
+ <div class="product-card" onclick="openModalById('${product.product_id}')">
835
+ <div class="product-image-container">
836
+ ${topBadge}
837
+ <img src="${photoUrl}" alt="${product.name}" loading="lazy" onerror="this.src='https://via.placeholder.com/300x300.png?text=Error'">
838
+ ${priceBadge}
839
+ </div>
840
+ <div class="product-info">
841
+ <h3 class="product-title">${product.name}</h3>
842
+ </div>
843
  </div>
844
+ `;
845
+ } else {
846
+ return `
847
+ <div class="product-card" onclick="openModalById('${product.product_id}')">
848
+ <div class="product-image-container">
849
+ ${topBadge}
850
+ <img src="${photoUrl}" alt="${product.name}" loading="lazy" onerror="this.src='https://via.placeholder.com/300x300.png?text=Error'">
851
+ </div>
852
+ <div class="product-info">
853
+ <h3 class="product-title">${product.name}</h3>
854
+ ${priceText}
855
+ </div>
856
+ </div>
857
+ `;
858
+ }
859
  }
860
 
861
  function buildCategorySection(categoryName, products) {
862
+ const safeId = categoryName.replace(/[^a-zA-Z0-9]/g, '-');
863
+ let html = `<div class="category-line-section" id="cat-section-${safeId}">`;
864
  html += `<h2 class="category-line-title">${categoryName}</h2>`;
865
  html += `<div class="category-line-grid">`;
866
  products.forEach(product => {
867
+ html += buildProductCard(product, true);
868
  });
869
  html += `</div></div>`;
870
  return html;
 
875
  const container = document.getElementById('catalog-content');
876
 
877
  if (categoriesAsLines) {
878
+ document.body.classList.add('show-line-nav');
879
  let filtered = allProducts.filter(p => {
880
  return searchTerm === '' || (p.name || '').toLowerCase().includes(searchTerm) || (p.description || '').toLowerCase().includes(searchTerm);
881
  });
 
906
  }
907
  container.innerHTML = html;
908
  } else {
909
+ document.body.classList.remove('show-line-nav');
910
  document.body.classList.remove('hide-chips');
911
  let filtered = allProducts.filter(p => {
912
  let matchCat = currentCategory === 'all' || p.category === currentCategory;
 
927
 
928
  let html = '<div class="product-grid">';
929
  paginated.forEach(product => {
930
+ html += buildProductCard(product, false);
931
  });
932
  html += '</div>';
933
 
 
3642
 
3643
  @app.route('/<env_id>/inventory_history/<p_id>/<t_id>')
3644
  def inventory_history(env_id, p_id, t_id):
3645
+ data = get_env_data(env_id)
3646
  history = data.get('inventory_history',[])
3647
  item_history =[h for h in history if h.get('product_id') == p_id and h.get('tag_id') == t_id]
3648
  item_history.sort(key=lambda x: x['timestamp'], reverse=True)
 
4346
  backup_thread = threading.Thread(target=periodic_backup, daemon=True)
4347
  backup_thread.start()
4348
  port = int(os.environ.get('PORT', 7860))
4349
+ app.run(debug=False, host='0.0.0.0', port=port)```