Kgshop commited on
Commit
0ba30ce
·
verified ·
1 Parent(s): 0855e97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -63
app.py CHANGED
@@ -154,7 +154,6 @@ def save_data(data):
154
  except Exception:
155
  pass
156
 
157
-
158
  CATALOG_TEMPLATE = '''
159
  <!DOCTYPE html>
160
  <html lang="ru">
@@ -189,12 +188,6 @@ CATALOG_TEMPLATE = '''
189
  .quantity-control button { border: none; background: #e0e0e0; width: 35px; height: 35px; font-size: 1.2rem; cursor: pointer; }
190
  .quantity-control input { width: 40px; height: 35px; border: none; text-align: center; background: transparent; font-weight: bold; pointer-events: none; }
191
 
192
- .social-buttons { position: fixed; left: 15px; bottom: 80px; display: flex; flex-direction: column; gap: 10px; z-index: 99; }
193
- .social-btn { width: 45px; height: 45px; border-radius: 50%; color: #fff; display: flex; justify-content: center; align-items: center; font-size: 1.5rem; text-decoration: none; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
194
- .btn-wa { background: #25D366; }
195
- .btn-ig { background: #E1306C; }
196
- .btn-tg { background: #0088cc; }
197
-
198
  .cart-bar { position: fixed; bottom: 0; left: 0; width: 100%; background: #fff; box-shadow: 0 -2px 10px rgba(0,0,0,0.1); padding: 15px 20px; display: none; justify-content: space-between; align-items: center; z-index: 100; }
199
  .cart-info { display: flex; flex-direction: column; }
200
  .cart-total { font-size: 1.2rem; font-weight: bold; }
@@ -226,12 +219,6 @@ CATALOG_TEMPLATE = '''
226
  <div class="categories-container" id="categoriesContainer"></div>
227
  <div class="products-container" id="productsContainer"></div>
228
 
229
- <div class="social-buttons">
230
- <a href="#" class="social-btn btn-wa"><i class="fab fa-whatsapp"></i></a>
231
- <a href="#" class="social-btn btn-ig"><i class="fab fa-instagram"></i></a>
232
- <a href="#" class="social-btn btn-tg"><i class="fab fa-telegram-plane"></i></a>
233
- </div>
234
-
235
  <div class="cart-bar" id="cartBar">
236
  <div class="cart-info">
237
  <span style="font-size: 0.8rem; color: #666;">Итого:</span>
@@ -264,7 +251,7 @@ CATALOG_TEMPLATE = '''
264
  updateCartUI();
265
  }
266
 
267
- function renderCategories(filter = '') {
268
  const container = document.getElementById('categoriesContainer');
269
  document.getElementById('productsContainer').style.display = 'none';
270
  container.style.display = 'grid';
@@ -274,8 +261,6 @@ CATALOG_TEMPLATE = '''
274
  container.innerHTML = '';
275
 
276
  categoriesList.forEach(cat => {
277
- if(filter && !cat.toLowerCase().includes(filter.toLowerCase())) return;
278
-
279
  const catProducts = products.filter(p => p.category === cat);
280
  const count = catProducts.length;
281
 
@@ -293,7 +278,50 @@ CATALOG_TEMPLATE = '''
293
  }
294
 
295
  function filterCategories() {
296
- renderCategories(document.getElementById('searchInput').value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
  }
298
 
299
  function showProducts(category) {
@@ -306,31 +334,7 @@ CATALOG_TEMPLATE = '''
306
  container.innerHTML = '';
307
 
308
  const catProducts = products.filter(p => p.category === category);
309
-
310
- catProducts.forEach(p => {
311
- const qty = cart[p.product_id] ? cart[p.product_id].quantity : 0;
312
- const photoUrl = p.photos && p.photos.length > 0
313
- ? `https://huggingface.co/datasets/${repoId}/resolve/main/photos/${p.photos[0]}`
314
- : 'https://via.placeholder.com/100';
315
-
316
- const div = document.createElement('div');
317
- div.className = 'product-card';
318
- div.innerHTML = `
319
- <img src="${photoUrl}" class="product-img">
320
- <div class="product-info">
321
- <div class="product-title">${p.name}</div>
322
- <div class="product-bottom">
323
- <div class="product-price">${p.price} ${currency}</div>
324
- <div class="quantity-control">
325
- <button onclick="updateCart('${p.product_id}', -1)">-</button>
326
- <input type="text" id="qty-${p.product_id}" value="${qty}" readonly>
327
- <button onclick="updateCart('${p.product_id}', 1)">+</button>
328
- </div>
329
- </div>
330
- </div>
331
- `;
332
- container.appendChild(div);
333
- });
334
  }
335
 
336
  function updateCart(productId, change) {
@@ -420,7 +424,7 @@ ORDER_TEMPLATE = '''
420
  <title>Накладная №{{ order.id }}</title>
421
  <style>
422
  * { box-sizing: border-box; font-family: 'Times New Roman', serif; }
423
- body { margin: 0; padding: 20px; background: #f0f0f0; display: flex; flex-direction: column; align-items: center; }
424
  .invoice-box { background: #fff; width: 100%; max-width: 900px; padding: 40px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
425
  .header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px; }
426
  .header h1 { margin: 0; font-size: 32px; font-weight: bold; }
@@ -431,15 +435,15 @@ ORDER_TEMPLATE = '''
431
  .img-cell img { width: 50px; height: 50px; object-fit: cover; }
432
  .total-row td { font-size: 18px; }
433
 
434
- .floating-buttons { position: fixed; bottom: 30px; right: 30px; display: flex; flex-direction: column; gap: 15px; }
435
- .btn { padding: 15px; border-radius: 50px; border: none; font-size: 16px; font-weight: bold; cursor: pointer; color: #fff; display: flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; box-shadow: 0 4px 6px rgba(0,0,0,0.2); }
436
  .btn-wa { background: #25D366; }
437
  .btn-print { background: #333; }
438
 
439
  @media print {
440
  body { background: #fff; padding: 0; }
441
  .invoice-box { box-shadow: none; padding: 0; max-width: 100%; }
442
- .floating-buttons { display: none; }
443
  }
444
  </style>
445
  </head>
@@ -494,19 +498,14 @@ ORDER_TEMPLATE = '''
494
  </table>
495
  </div>
496
 
497
- <div class="floating-buttons">
498
  <button class="btn btn-print" onclick="window.print()">Печать</button>
499
  <button class="btn btn-wa" onclick="sendToWA()">Отправить в WhatsApp</button>
500
  </div>
501
 
502
  <script>
503
  function sendToWA() {
504
- let msg = `Заказ №{{ order.id }}\n\n`;
505
- {% for item in order.cart %}
506
- msg += `- {{ item.name }} x{{ item.quantity }} = {{ item.price * item.quantity }}\n`;
507
- {% endfor %}
508
- msg += `\nИтого: {{ order.total_price }} {{ currency_code }}`;
509
-
510
  window.open(`https://api.whatsapp.com/send?phone={{ whatsapp_number }}&text=${encodeURIComponent(msg)}`, '_blank');
511
  }
512
  </script>
@@ -531,8 +530,8 @@ ADMIN_TEMPLATE = '''
531
  button { padding: 10px 15px; border: none; border-radius: 4px; background: #333; color: #fff; cursor: pointer; }
532
  button.danger { background: #dc3545; }
533
  .category-block { border: 1px solid #ddd; margin-bottom: 10px; border-radius: 4px; }
534
- .category-header { background: #f8f9fa; padding: 15px; cursor: pointer; font-weight: bold; display: flex; justify-content: space-between; align-items: center; }
535
- .category-content { padding: 15px; display: none; border-top: 1px solid #ddd; }
536
  .product-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #eee; }
537
  .product-item img { width: 40px; height: 40px; object-fit: cover; margin-right: 10px; border-radius: 4px; }
538
  .add-product-form { background: #fdfdfd; padding: 15px; border: 1px dashed #ccc; margin-top: 15px; }
@@ -559,7 +558,7 @@ ADMIN_TEMPLATE = '''
559
 
560
  {% for category in categories %}
561
  <div class="category-block">
562
- <div class="category-header" onclick="toggleCategory('{{ loop.index }}')">
563
  <span>{{ category }}</span>
564
  <form method="POST" style="margin:0;" onsubmit="return confirm('Удалить категорию?');">
565
  <input type="hidden" name="action" value="delete_category">
@@ -601,13 +600,6 @@ ADMIN_TEMPLATE = '''
601
  </div>
602
  {% endfor %}
603
  </div>
604
-
605
- <script>
606
- function toggleCategory(id) {
607
- const el = document.getElementById('cat-' + id);
608
- el.style.display = el.style.display === 'block' ? 'none' : 'block';
609
- }
610
- </script>
611
  </body>
612
  </html>
613
  '''
 
154
  except Exception:
155
  pass
156
 
 
157
  CATALOG_TEMPLATE = '''
158
  <!DOCTYPE html>
159
  <html lang="ru">
 
188
  .quantity-control button { border: none; background: #e0e0e0; width: 35px; height: 35px; font-size: 1.2rem; cursor: pointer; }
189
  .quantity-control input { width: 40px; height: 35px; border: none; text-align: center; background: transparent; font-weight: bold; pointer-events: none; }
190
 
 
 
 
 
 
 
191
  .cart-bar { position: fixed; bottom: 0; left: 0; width: 100%; background: #fff; box-shadow: 0 -2px 10px rgba(0,0,0,0.1); padding: 15px 20px; display: none; justify-content: space-between; align-items: center; z-index: 100; }
192
  .cart-info { display: flex; flex-direction: column; }
193
  .cart-total { font-size: 1.2rem; font-weight: bold; }
 
219
  <div class="categories-container" id="categoriesContainer"></div>
220
  <div class="products-container" id="productsContainer"></div>
221
 
 
 
 
 
 
 
222
  <div class="cart-bar" id="cartBar">
223
  <div class="cart-info">
224
  <span style="font-size: 0.8rem; color: #666;">Итого:</span>
 
251
  updateCartUI();
252
  }
253
 
254
+ function renderCategories() {
255
  const container = document.getElementById('categoriesContainer');
256
  document.getElementById('productsContainer').style.display = 'none';
257
  container.style.display = 'grid';
 
261
  container.innerHTML = '';
262
 
263
  categoriesList.forEach(cat => {
 
 
264
  const catProducts = products.filter(p => p.category === cat);
265
  const count = catProducts.length;
266
 
 
278
  }
279
 
280
  function filterCategories() {
281
+ const query = document.getElementById('searchInput').value.toLowerCase();
282
+ if (!query) {
283
+ renderCategories();
284
+ return;
285
+ }
286
+
287
+ document.getElementById('categoriesContainer').style.display = 'none';
288
+ const container = document.getElementById('productsContainer');
289
+ container.style.display = 'flex';
290
+ document.getElementById('backBtn').style.display = 'block';
291
+ document.getElementById('pageTitle').innerText = 'Результаты поиска';
292
+ container.innerHTML = '';
293
+
294
+ const matchedProducts = products.filter(p =>
295
+ p.name.toLowerCase().includes(query) ||
296
+ p.category.toLowerCase().includes(query)
297
+ );
298
+
299
+ matchedProducts.forEach(p => renderProductCard(p, container));
300
+ }
301
+
302
+ function renderProductCard(p, container) {
303
+ const qty = cart[p.product_id] ? cart[p.product_id].quantity : 0;
304
+ const photoUrl = p.photos && p.photos.length > 0
305
+ ? `https://huggingface.co/datasets/${repoId}/resolve/main/photos/${p.photos[0]}`
306
+ : 'https://via.placeholder.com/100';
307
+
308
+ const div = document.createElement('div');
309
+ div.className = 'product-card';
310
+ div.innerHTML = `
311
+ <img src="${photoUrl}" class="product-img">
312
+ <div class="product-info">
313
+ <div class="product-title">${p.name}</div>
314
+ <div class="product-bottom">
315
+ <div class="product-price">${p.price} ${currency}</div>
316
+ <div class="quantity-control">
317
+ <button onclick="updateCart('${p.product_id}', -1)">-</button>
318
+ <input type="text" id="qty-${p.product_id}" value="${qty}" readonly>
319
+ <button onclick="updateCart('${p.product_id}', 1)">+</button>
320
+ </div>
321
+ </div>
322
+ </div>
323
+ `;
324
+ container.appendChild(div);
325
  }
326
 
327
  function showProducts(category) {
 
334
  container.innerHTML = '';
335
 
336
  const catProducts = products.filter(p => p.category === category);
337
+ catProducts.forEach(p => renderProductCard(p, container));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
338
  }
339
 
340
  function updateCart(productId, change) {
 
424
  <title>Накладная №{{ order.id }}</title>
425
  <style>
426
  * { box-sizing: border-box; font-family: 'Times New Roman', serif; }
427
+ body { margin: 0; padding: 20px; padding-bottom: 90px; background: #f0f0f0; display: flex; flex-direction: column; align-items: center; }
428
  .invoice-box { background: #fff; width: 100%; max-width: 900px; padding: 40px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
429
  .header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 30px; border-bottom: 2px solid #000; padding-bottom: 10px; }
430
  .header h1 { margin: 0; font-size: 32px; font-weight: bold; }
 
435
  .img-cell img { width: 50px; height: 50px; object-fit: cover; }
436
  .total-row td { font-size: 18px; }
437
 
438
+ .action-bar { position: fixed; bottom: 0; left: 0; width: 100%; background: #fff; box-shadow: 0 -2px 10px rgba(0,0,0,0.1); padding: 15px 20px; display: flex; gap: 15px; z-index: 100; }
439
+ .btn { flex: 1; padding: 15px; border-radius: 10px; border: none; font-size: 16px; font-weight: bold; cursor: pointer; color: #fff; display: flex; align-items: center; justify-content: center; text-decoration: none; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
440
  .btn-wa { background: #25D366; }
441
  .btn-print { background: #333; }
442
 
443
  @media print {
444
  body { background: #fff; padding: 0; }
445
  .invoice-box { box-shadow: none; padding: 0; max-width: 100%; }
446
+ .action-bar { display: none; }
447
  }
448
  </style>
449
  </head>
 
498
  </table>
499
  </div>
500
 
501
+ <div class="action-bar">
502
  <button class="btn btn-print" onclick="window.print()">Печать</button>
503
  <button class="btn btn-wa" onclick="sendToWA()">Отправить в WhatsApp</button>
504
  </div>
505
 
506
  <script>
507
  function sendToWA() {
508
+ let msg = `Заказ №{{ order.id }}\nНакладная: ${window.location.href}`;
 
 
 
 
 
509
  window.open(`https://api.whatsapp.com/send?phone={{ whatsapp_number }}&text=${encodeURIComponent(msg)}`, '_blank');
510
  }
511
  </script>
 
530
  button { padding: 10px 15px; border: none; border-radius: 4px; background: #333; color: #fff; cursor: pointer; }
531
  button.danger { background: #dc3545; }
532
  .category-block { border: 1px solid #ddd; margin-bottom: 10px; border-radius: 4px; }
533
+ .category-header { background: #f8f9fa; padding: 15px; font-weight: bold; display: flex; justify-content: space-between; align-items: center; }
534
+ .category-content { padding: 15px; display: block; border-top: 1px solid #ddd; }
535
  .product-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid #eee; }
536
  .product-item img { width: 40px; height: 40px; object-fit: cover; margin-right: 10px; border-radius: 4px; }
537
  .add-product-form { background: #fdfdfd; padding: 15px; border: 1px dashed #ccc; margin-top: 15px; }
 
558
 
559
  {% for category in categories %}
560
  <div class="category-block">
561
+ <div class="category-header">
562
  <span>{{ category }}</span>
563
  <form method="POST" style="margin:0;" onsubmit="return confirm('Удалить категорию?');">
564
  <input type="hidden" name="action" value="delete_category">
 
600
  </div>
601
  {% endfor %}
602
  </div>
 
 
 
 
 
 
 
603
  </body>
604
  </html>
605
  '''