Kgshop commited on
Commit
8a322e7
·
verified ·
1 Parent(s): b8581ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -12
app.py CHANGED
@@ -384,7 +384,7 @@ def catalog():
384
  border-radius: 8px;
385
  margin-right: 15px;
386
  }
387
- .quantity-input, .color-select {
388
  width: 100%;
389
  max-width: 150px;
390
  padding: 8px;
@@ -458,13 +458,14 @@ def catalog():
458
  </div>
459
  </div>
460
 
461
- <!-- Quantity and Color Modal -->
462
  <div id="quantityModal" class="modal">
463
  <div class="modal-content">
464
  <span class="close" onclick="closeModal('quantityModal')">×</span>
465
- <h2>Укажите количество и цвет</h2>
466
  <input type="number" id="quantityInput" class="quantity-input" min="1" value="1">
467
  <select id="colorSelect" class="color-select"></select>
 
468
  <button class="product-button" onclick="confirmAddToCart()">Добавить</button>
469
  </div>
470
  </div>
@@ -539,6 +540,8 @@ def catalog():
539
  function openQuantityModal(index) {
540
  selectedProductIndex = index;
541
  const product = products[index];
 
 
542
  const colorSelect = document.getElementById('colorSelect');
543
  colorSelect.innerHTML = '';
544
  if (product.colors && product.colors.length > 0) {
@@ -554,6 +557,24 @@ def catalog():
554
  option.text = 'Нет цвета';
555
  colorSelect.appendChild(option);
556
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557
  document.getElementById('quantityModal').style.display = 'block';
558
  document.getElementById('quantityInput').value = 1;
559
  }
@@ -562,13 +583,14 @@ def catalog():
562
  if (selectedProductIndex === null) return;
563
  const quantity = parseInt(document.getElementById('quantityInput').value) || 1;
564
  const color = document.getElementById('colorSelect').value;
 
565
  if (quantity <= 0) {
566
  alert("Укажите количество больше 0");
567
  return;
568
  }
569
  let cart = JSON.parse(localStorage.getItem('cart') || '[]');
570
  const product = products[selectedProductIndex];
571
- const cartItemId = `${product.name}-${color}`;
572
  const existingItem = cart.find(item => item.id === cartItemId);
573
 
574
  if (existingItem) {
@@ -580,7 +602,8 @@ def catalog():
580
  price: product.price,
581
  photo: product.photos && product.photos.length > 0 ? product.photos[0] : '',
582
  quantity: quantity,
583
- color: color
 
584
  });
585
  }
586
 
@@ -608,7 +631,7 @@ def catalog():
608
  ${item.photo ? `<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/${item.photo}" alt="${item.name}">` : ''}
609
  <div>
610
  <strong>${item.name}</strong>
611
- <p>${item.price} с × ${item.quantity} (Цвет: ${item.color})</p>
612
  </div>
613
  </div>
614
  <span>${itemTotal} с</span>
@@ -631,7 +654,7 @@ def catalog():
631
  cart.forEach((item, index) => {
632
  const itemTotal = item.price * item.quantity;
633
  total += itemTotal;
634
- orderText += `${index + 1}. ${item.name} - ${item.price} с × ${item.quantity} (Цвет: ${item.color})%0A`;
635
  });
636
  orderText += `Итого: ${total} с`;
637
  window.open(`https://api.whatsapp.com/send?phone=996705665777&text=${orderText}`, '_blank');
@@ -713,6 +736,7 @@ def product_detail(index):
713
  <p><strong>Цена:</strong> {{ product['price'] }} с</p>
714
  <p><strong>Описание:</strong> {{ product['description'] }}</p>
715
  <p><strong>Доступные цвета:</strong> {{ product.get('colors', ['Нет цветов'])|join(', ') }}</p>
 
716
  </div>
717
  '''
718
  return render_template_string(detail_html, product=product, repo_id=REPO_ID)
@@ -750,6 +774,7 @@ def admin():
750
  category = request.form.get('category')
751
  photos_files = request.files.getlist('photos')
752
  colors = request.form.getlist('colors')
 
753
  photos_list = []
754
 
755
  if photos_files:
@@ -783,7 +808,8 @@ def admin():
783
  'description': description,
784
  'category': category if category in categories else 'Без категории',
785
  'photos': photos_list,
786
- 'colors': colors if colors else []
 
787
  }
788
  products.append(new_product)
789
  save_data(data)
@@ -797,6 +823,7 @@ def admin():
797
  category = request.form.get('category')
798
  photos_files = request.files.getlist('photos')
799
  colors = request.form.getlist('colors')
 
800
 
801
  if photos_files and any(photo.filename for photo in photos_files):
802
  new_photos_list = []
@@ -826,6 +853,7 @@ def admin():
826
  products[index]['description'] = description
827
  products[index]['category'] = category if category in categories else 'Без категории'
828
  products[index]['colors'] = colors if colors else []
 
829
  save_data(data)
830
  return redirect(url_for('admin'))
831
 
@@ -942,15 +970,15 @@ def admin():
942
  background: #f7fafc;
943
  border-radius: 10px;
944
  }
945
- .color-input-group {
946
  display: flex;
947
  gap: 10px;
948
  margin-top: 5px;
949
  }
950
- .add-color-btn {
951
  background-color: #10b981;
952
  }
953
- .add-color-btn:hover {
954
  background-color: #059669;
955
  }
956
  </style>
@@ -985,7 +1013,14 @@ def admin():
985
  <input type="text" name="colors" placeholder="Например: Красный">
986
  </div>
987
  </div>
988
- <button type="button" class="add-color-btn" onclick="addColorInput()">Добавить цвет</button>
 
 
 
 
 
 
 
989
  <button type="submit">Добавить товар</button>
990
  </form>
991
 
@@ -1028,6 +1063,7 @@ def admin():
1028
  <p><strong>Цена:</strong> {{ product['price'] }} с</p>
1029
  <p><strong>Описание:</strong> {{ product['description'] }}</p>
1030
  <p><strong>Цвета:</strong> {{ product.get('colors', ['Нет цветов'])|join(', ') }}</p>
 
1031
  {% if product.get('photos') and product['photos']|length > 0 %}
1032
  <div style="display: flex; flex-wrap: wrap; gap: 10px;">
1033
  {% for photo in product['photos'] %}
@@ -1066,6 +1102,15 @@ def admin():
1066
  {% endfor %}
1067
  </div>
1068
  <button type="button" class="add-color-btn" onclick="addColorInput('edit-color-inputs-{{ loop.index0 }}')">Добавить цвет</button>
 
 
 
 
 
 
 
 
 
1069
  <button type="submit">Сохранить</button>
1070
  </form>
1071
  </details>
@@ -1086,6 +1131,14 @@ def admin():
1086
  newInput.innerHTML = '<input type="text" name="colors" placeholder="Например: Красный">';
1087
  container.appendChild(newInput);
1088
  }
 
 
 
 
 
 
 
 
1089
  </script>
1090
  </body>
1091
  </html>
 
384
  border-radius: 8px;
385
  margin-right: 15px;
386
  }
387
+ .quantity-input, .color-select, .model-select {
388
  width: 100%;
389
  max-width: 150px;
390
  padding: 8px;
 
458
  </div>
459
  </div>
460
 
461
+ <!-- Quantity, Color and Model Modal -->
462
  <div id="quantityModal" class="modal">
463
  <div class="modal-content">
464
  <span class="close" onclick="closeModal('quantityModal')">×</span>
465
+ <h2>Укажите количество, цвет и модель</h2>
466
  <input type="number" id="quantityInput" class="quantity-input" min="1" value="1">
467
  <select id="colorSelect" class="color-select"></select>
468
+ <select id="modelSelect" class="model-select"></select>
469
  <button class="product-button" onclick="confirmAddToCart()">Добавить</button>
470
  </div>
471
  </div>
 
540
  function openQuantityModal(index) {
541
  selectedProductIndex = index;
542
  const product = products[index];
543
+
544
+ // Заполнение цветов
545
  const colorSelect = document.getElementById('colorSelect');
546
  colorSelect.innerHTML = '';
547
  if (product.colors && product.colors.length > 0) {
 
557
  option.text = 'Нет цвета';
558
  colorSelect.appendChild(option);
559
  }
560
+
561
+ // Заполнение моделей
562
+ const modelSelect = document.getElementById('modelSelect');
563
+ modelSelect.innerHTML = '';
564
+ if (product.models && product.models.length > 0) {
565
+ product.models.forEach(model => {
566
+ const option = document.createElement('option');
567
+ option.value = model;
568
+ option.text = model;
569
+ modelSelect.appendChild(option);
570
+ });
571
+ } else {
572
+ const option = document.createElement('option');
573
+ option.value = 'Нет модели';
574
+ option.text = 'Нет модели';
575
+ modelSelect.appendChild(option);
576
+ }
577
+
578
  document.getElementById('quantityModal').style.display = 'block';
579
  document.getElementById('quantityInput').value = 1;
580
  }
 
583
  if (selectedProductIndex === null) return;
584
  const quantity = parseInt(document.getElementById('quantityInput').value) || 1;
585
  const color = document.getElementById('colorSelect').value;
586
+ const model = document.getElementById('modelSelect').value;
587
  if (quantity <= 0) {
588
  alert("Укажите количество больше 0");
589
  return;
590
  }
591
  let cart = JSON.parse(localStorage.getItem('cart') || '[]');
592
  const product = products[selectedProductIndex];
593
+ const cartItemId = `${product.name}-${color}-${model}`;
594
  const existingItem = cart.find(item => item.id === cartItemId);
595
 
596
  if (existingItem) {
 
602
  price: product.price,
603
  photo: product.photos && product.photos.length > 0 ? product.photos[0] : '',
604
  quantity: quantity,
605
+ color: color,
606
+ model: model
607
  });
608
  }
609
 
 
631
  ${item.photo ? `<img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/${item.photo}" alt="${item.name}">` : ''}
632
  <div>
633
  <strong>${item.name}</strong>
634
+ <p>${item.price} с × ${item.quantity} (Цвет: ${item.color}, Модель: ${item.model})</p>
635
  </div>
636
  </div>
637
  <span>${itemTotal} с</span>
 
654
  cart.forEach((item, index) => {
655
  const itemTotal = item.price * item.quantity;
656
  total += itemTotal;
657
+ orderText += `${index + 1}. ${item.name} - ${item.price} с × ${item.quantity} (Цвет: ${item.color}, Модель: ${item.model})%0A`;
658
  });
659
  orderText += `Итого: ${total} с`;
660
  window.open(`https://api.whatsapp.com/send?phone=996705665777&text=${orderText}`, '_blank');
 
736
  <p><strong>Цена:</strong> {{ product['price'] }} с</p>
737
  <p><strong>Описание:</strong> {{ product['description'] }}</p>
738
  <p><strong>Доступные цвета:</strong> {{ product.get('colors', ['Нет цветов'])|join(', ') }}</p>
739
+ <p><strong>Доступные модели:</strong> {{ product.get('models', ['Нет моделей'])|join(', ') }}</p>
740
  </div>
741
  '''
742
  return render_template_string(detail_html, product=product, repo_id=REPO_ID)
 
774
  category = request.form.get('category')
775
  photos_files = request.files.getlist('photos')
776
  colors = request.form.getlist('colors')
777
+ models = request.form.getlist('models')
778
  photos_list = []
779
 
780
  if photos_files:
 
808
  'description': description,
809
  'category': category if category in categories else 'Без категории',
810
  'photos': photos_list,
811
+ 'colors': colors if colors else [],
812
+ 'models': models if models else []
813
  }
814
  products.append(new_product)
815
  save_data(data)
 
823
  category = request.form.get('category')
824
  photos_files = request.files.getlist('photos')
825
  colors = request.form.getlist('colors')
826
+ models = request.form.getlist('models')
827
 
828
  if photos_files and any(photo.filename for photo in photos_files):
829
  new_photos_list = []
 
853
  products[index]['description'] = description
854
  products[index]['category'] = category if category in categories else 'Без категории'
855
  products[index]['colors'] = colors if colors else []
856
+ products[index]['models'] = models if models else []
857
  save_data(data)
858
  return redirect(url_for('admin'))
859
 
 
970
  background: #f7fafc;
971
  border-radius: 10px;
972
  }
973
+ .color-input-group, .model-input-group {
974
  display: flex;
975
  gap: 10px;
976
  margin-top: 5px;
977
  }
978
+ .add-color-btn, .add-model-btn {
979
  background-color: #10b981;
980
  }
981
+ .add-color-btn:hover, .add-model-btn:hover {
982
  background-color: #059669;
983
  }
984
  </style>
 
1013
  <input type="text" name="colors" placeholder="Например: Красный">
1014
  </div>
1015
  </div>
1016
+ <button type="button" class="add-color-btn" onclick="addColorInput('color-inputs')">Добавить цвет</button>
1017
+ <label>Модели телефона:</label>
1018
+ <div id="model-inputs">
1019
+ <div class="model-input-group">
1020
+ <input type="text" name="models" placeholder="Например: iPhone 14">
1021
+ </div>
1022
+ </div>
1023
+ <button type="button" class="add-model-btn" onclick="addModelInput('model-inputs')">Добавить модель</button>
1024
  <button type="submit">Добавить товар</button>
1025
  </form>
1026
 
 
1063
  <p><strong>Цена:</strong> {{ product['price'] }} с</p>
1064
  <p><strong>Описание:</strong> {{ product['description'] }}</p>
1065
  <p><strong>Цвета:</strong> {{ product.get('colors', ['Нет цветов'])|join(', ') }}</p>
1066
+ <p><strong>Модели:</strong> {{ product.get('models', ['Нет моделей'])|join(', ') }}</p>
1067
  {% if product.get('photos') and product['photos']|length > 0 %}
1068
  <div style="display: flex; flex-wrap: wrap; gap: 10px;">
1069
  {% for photo in product['photos'] %}
 
1102
  {% endfor %}
1103
  </div>
1104
  <button type="button" class="add-color-btn" onclick="addColorInput('edit-color-inputs-{{ loop.index0 }}')">Добавить цвет</button>
1105
+ <label>Модели телефона:</label>
1106
+ <div id="edit-model-inputs-{{ loop.index0 }}">
1107
+ {% for model in product.get('models', []) %}
1108
+ <div class="model-input-group">
1109
+ <input type="text" name="models" value="{{ model }}">
1110
+ </div>
1111
+ {% endfor %}
1112
+ </div>
1113
+ <button type="button" class="add-model-btn" onclick="addModelInput('edit-model-inputs-{{ loop.index0 }}')">Добавить модель</button>
1114
  <button type="submit">Сохранить</button>
1115
  </form>
1116
  </details>
 
1131
  newInput.innerHTML = '<input type="text" name="colors" placeholder="Например: Красный">';
1132
  container.appendChild(newInput);
1133
  }
1134
+
1135
+ function addModelInput(containerId = 'model-inputs') {
1136
+ const container = document.getElementById(containerId);
1137
+ const newInput = document.createElement('div');
1138
+ newInput.className = 'model-input-group';
1139
+ newInput.innerHTML = '<input type="text" name="models" placeholder="Например: iPhone 14">';
1140
+ container.appendChild(newInput);
1141
+ }
1142
  </script>
1143
  </body>
1144
  </html>