flpolprojects commited on
Commit
99c03dd
·
verified ·
1 Parent(s): daa7bba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -28
app.py CHANGED
@@ -94,6 +94,7 @@ def catalog():
94
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
95
  <title>Каталог</title>
96
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
 
97
  <style>
98
  * {
99
  margin: 0;
@@ -293,9 +294,37 @@ def catalog():
293
  cursor: pointer;
294
  }
295
 
296
- /* Image Carousel Styles */
297
- .carousel-inner > .carousel-item > img {
298
- margin: 0 auto;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  }
300
  </style>
301
  </head>
@@ -334,6 +363,7 @@ def catalog():
334
  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
335
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
336
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
 
337
  <script>
338
  // Function to open the modal
339
  function openModal(index) {
@@ -352,9 +382,28 @@ def catalog():
352
  .then(response => response.text())
353
  .then(data => {
354
  document.getElementById('modalContent').innerHTML = data;
 
 
355
  });
356
  }
357
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  // Close the modal if the user clicks outside of it
359
  window.onclick = function(event) {
360
  if (event.target == document.getElementById('productModal')) {
@@ -377,35 +426,25 @@ def product_detail(index):
377
  detail_html = '''
378
  <div class="container">
379
  <h2>{{ product['name'] }}</h2>
380
- <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
381
- <ol class="carousel-indicators">
382
- {% if product.get('photos') %}
383
- {% for photo in product['photos'] %}
384
- <li data-target="#carouselExampleIndicators" data-slide-to="{{ loop.index0 }}" {% if loop.first %}class="active"{% endif %}></li>
385
- {% endfor %}
386
- {% endif %}
387
- </ol>
388
- <div class="carousel-inner">
389
  {% if product.get('photos') %}
390
  {% for photo in product['photos'] %}
391
- <div class="carousel-item {% if loop.first %}active{% endif %}">
392
- <img class="d-block w-100" src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}" alt="{{ product['name'] }}">
393
  </div>
394
  {% endfor %}
395
  {% else %}
396
- <div class="carousel-item active">
397
- <img class="d-block w-100" src="https://via.placeholder.com/300" alt="No Image">
398
  </div>
399
  {% endif %}
400
  </div>
401
- <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
402
- <span class="carousel-control-prev-icon" aria-hidden="true"></span>
403
- <span class="sr-only">Previous</span>
404
- </a>
405
- <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
406
- <span class="carousel-control-next-icon" aria-hidden="true"></span>
407
- <span class="sr-only">Next</span>
408
- </a>
409
  </div>
410
  <p><strong>Цена:</strong> {{ product['price'] }} ₽</p>
411
  <p><strong>Описание:</strong> {{ product['description'] }}</p>
@@ -425,8 +464,6 @@ def admin():
425
  photos_files = request.files.getlist('photos')
426
  photos_list = []
427
  if photos_files:
428
- if len(photos_files) > 5:
429
- photos_files = photos_files[:5]
430
  for photo in photos_files:
431
  if photo and photo.filename:
432
  photo_filename = secure_filename(photo.filename)
@@ -473,8 +510,6 @@ def admin():
473
  # Если загружены новые фото, обновляем список фотографий товара
474
  if photos_files and any(photo.filename for photo in photos_files):
475
  new_photos_list = []
476
- if len(photos_files) > 5:
477
- photos_files = photos_files[:5]
478
  for photo in photos_files:
479
  if photo and photo.filename:
480
  photo_filename = secure_filename(photo.filename)
 
94
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
95
  <title>Каталог</title>
96
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
97
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/10.2.0/swiper-bundle.min.css">
98
  <style>
99
  * {
100
  margin: 0;
 
294
  cursor: pointer;
295
  }
296
 
297
+ /* Swiper Styles */
298
+ .swiper-container {
299
+ width: 100%;
300
+ height: 300px;
301
+ }
302
+
303
+ .swiper-slide {
304
+ text-align: center;
305
+ font-size: 18px;
306
+ background: #fff;
307
+
308
+ /* Center slide text vertically */
309
+ display: -webkit-box;
310
+ display: -ms-flexbox;
311
+ display: -webkit-flex;
312
+ display: flex;
313
+ -webkit-box-pack: center;
314
+ -ms-flex-pack: center;
315
+ -webkit-justify-content: center;
316
+ justify-content: center;
317
+ -webkit-box-align: center;
318
+ -ms-flex-align: center;
319
+ -webkit-align-items: center;
320
+ align-items: center;
321
+ }
322
+
323
+ .swiper-slide img {
324
+ display: block;
325
+ width: 100%;
326
+ height: 100%;
327
+ object-fit: cover;
328
  }
329
  </style>
330
  </head>
 
363
  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
364
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
365
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
366
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/10.2.0/swiper-bundle.min.js"></script>
367
  <script>
368
  // Function to open the modal
369
  function openModal(index) {
 
382
  .then(response => response.text())
383
  .then(data => {
384
  document.getElementById('modalContent').innerHTML = data;
385
+ // Initialize Swiper after the content is loaded
386
+ initializeSwiper();
387
  });
388
  }
389
 
390
+ function initializeSwiper() {
391
+ var swiper = new Swiper('.swiper-container', {
392
+ slidesPerView: 1,
393
+ spaceBetween: 30,
394
+ loop: true,
395
+ grabCursor: true, // Enables the ability to grab with a cursor
396
+ pagination: {
397
+ el: '.swiper-pagination',
398
+ clickable: true,
399
+ },
400
+ navigation: {
401
+ nextEl: '.swiper-button-next',
402
+ prevEl: '.swiper-button-prev',
403
+ },
404
+ });
405
+ }
406
+
407
  // Close the modal if the user clicks outside of it
408
  window.onclick = function(event) {
409
  if (event.target == document.getElementById('productModal')) {
 
426
  detail_html = '''
427
  <div class="container">
428
  <h2>{{ product['name'] }}</h2>
429
+ <div class="swiper-container">
430
+ <div class="swiper-wrapper">
 
 
 
 
 
 
 
431
  {% if product.get('photos') %}
432
  {% for photo in product['photos'] %}
433
+ <div class="swiper-slide">
434
+ <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}" alt="{{ product['name'] }}">
435
  </div>
436
  {% endfor %}
437
  {% else %}
438
+ <div class="swiper-slide">
439
+ <img src="https://via.placeholder.com/300" alt="No Image">
440
  </div>
441
  {% endif %}
442
  </div>
443
+ <!-- Add Pagination -->
444
+ <div class="swiper-pagination"></div>
445
+ <!-- Add Navigation -->
446
+ <div class="swiper-button-next"></div>
447
+ <div class="swiper-button-prev"></div>
 
 
 
448
  </div>
449
  <p><strong>Цена:</strong> {{ product['price'] }} ₽</p>
450
  <p><strong>Описание:</strong> {{ product['description'] }}</p>
 
464
  photos_files = request.files.getlist('photos')
465
  photos_list = []
466
  if photos_files:
 
 
467
  for photo in photos_files:
468
  if photo and photo.filename:
469
  photo_filename = secure_filename(photo.filename)
 
510
  # Если загружены новые фото, обновляем список фотографий товара
511
  if photos_files and any(photo.filename for photo in photos_files):
512
  new_photos_list = []
 
 
513
  for photo in photos_files:
514
  if photo and photo.filename:
515
  photo_filename = secure_filename(photo.filename)