diff --git "a/app.py" "b/app.py" --- "a/app.py" +++ "b/app.py" @@ -250,20 +250,6 @@ def catalog(): text-align: center; margin: 5px 0; } - .product-price .wholesale { - font-size: 0.9rem; - color: #526df2; - font-weight: 500; - display: block; - margin-top: 5px; - } - .product-price .discount { - font-size: 0.9rem; - color: #2ecc71; - font-weight: 500; - display: block; - margin-top: 5px; - } .product-description { font-size: 0.85rem; color: #666; @@ -462,17 +448,6 @@ def catalog(): .navbar a:hover { color: #526df2; } - .wholesale-badge { - position: absolute; - top: 10px; - right: 10px; - background-color: #526df2; - color: white; - padding: 5px 10px; - border-radius: 15px; - font-size: 0.75rem; - font-weight: 500; - } .discount-badge { position: absolute; top: 40px; @@ -520,70 +495,51 @@ def catalog(): - -

Наш адрес

Рынок Дордой, Джунхай, 5 проход 505-506 контейнеры

График работы

С 9:00 до 16:00 без выходных

-
{% for product in products %} -
- - {% if product.get('photos') and product['photos']|length > 0 %} -
- {{ product['name'] }} -
- {% endif %} - {% if product.get('wholesale_price') and product.get('min_wholesale') %} - Опт от {{ product['min_wholesale'] }} - {% endif %} - {% if product.get('discount') %} - Скидка {{ product['discount'] }}% - {% endif %} -

{{ product['name'] }}

-
- {% if product.get('discount') %} - {{ product['price'] }} с - {{ (product['price'] * (1 - product['discount'] / 100))|round(2) }} с - Скидка: {{ product['discount'] }}% - {% else %} - {{ product['price'] }} с +
+ + {% if product.get('photos') and product['photos']|length > 0 %} +
+ {{ product['name'] }} +
{% endif %} - {% if product.get('wholesale_price') and product.get('min_wholesale') %} - Опт: {{ product['wholesale_price'] }} с + {% if product.get('discount') %} + Скидка {{ product['discount'] }}% {% endif %} +

{{ product['name'] }}

+
+ {% if product.get('discount') %} + {{ product['price'] }} с + {{ (product['price'] * (1 - product['discount'] / 100))|round(2) }} с + Скидка: {{ product['discount'] }}% + {% else %} + {{ product['price'] }} с + {% endif %} +
+

{{ product['description'][:50] }}{% if product['description']|length > 50 %}...{% endif %}

+
-

{{ product['description'][:50] }}{% if product['description']|length > 50 %}...{% endif %}

- -
{% endfor %}
- - - - - - - - - - + + - - - ''' return render_template_string(catalog_html, products=products, repo_id=REPO_ID) -@app.route('/categories') -def categories_page(): +@app.route('/admin') +def admin(): data = load_data() + products = data['products'] categories = data['categories'] - - categories_html = ''' + + admin_html = ''' - Категории + Админ Панель - - -
-
-

Категории

- -
-
- {% for category in categories %} - -

{{ category }}

-
- {% endfor %} -
-
- - - - - - - ''' - return render_template_string(categories_html, categories=categories) - -@app.route('/category/') -def category_products(category): - data = load_data() - products = [p for p in data['products'] if p.get('category') == category] - # categories = data['categories'] # No longer needed here - - category_html = ''' - - - - - - {{ category }} - - - - - - -
-
-

{{ category }}

- -
-
- {% for product in products %} -
- - {% if product.get('photos') and product['photos']|length > 0 %} -
- {{ product['name'] }} -
- {% endif %} - {% if product.get('wholesale_price') and product.get('min_wholesale') %} - Опт от {{ product['min_wholesale'] }} - {% endif %} - {% if product.get('discount') %} - Скидка {{ product['discount'] }}% - {% endif %} -

{{ product['name'] }}

-
- {% if product.get('discount') %} - {{ product['price'] }} с - {{ (product['price'] * (1 - product['discount'] / 100))|round(2) }} с - Скидка: {{ product['discount'] }}% - {% else %} - {{ product['price'] }} с - {% endif %} - {% if product.get('wholesale_price') and product.get('min_wholesale') %} - Опт: {{ product['wholesale_price'] }} с - {% endif %} -
-

{{ product['description'][:50] }}{% if product['description']|length > 50 %}...{% endif %}

- -
- {% endfor %} -
-
- - - - - - - - - - - - - - - - - - - - - ''' - return render_template_string(category_html, products=products, category=category, repo_id=REPO_ID) - - -@app.route('/favorites') -def favorites_page(): - data = load_data() - products = data['products'] - favorites = request.args.get('favorites', '[]') # Not really used directly, but kept for consistency - - favorites_html = ''' - - - - - - Избранное - - - - - - -
-
-

Избранное

- -
-
-
-
- - - - - - - - - - - - - - - - - - - - - - ''' - return render_template_string(favorites_html, products=products, repo_id=REPO_ID) - - - -@app.route('/discounts') -def discounts_page(): - data = load_data() - products = [p for p in data['products'] if p.get('discount')] - # categories = data['categories'] # No longer used in this view - - discounts_html = ''' - - - - - - Скидки - - - - - - -
-
-

Скидки

- -
-
- {% for product in products %} -
- - {% if product.get('photos') and product['photos']|length > 0 %} -
- {{ product['name'] }} -
- {% endif %} - {% if product.get('wholesale_price') and product.get('min_wholesale') %} - Опт от {{ product['min_wholesale'] }} - {% endif %} - {% if product.get('discount') %} - Скидка {{ product['discount'] }}% - {% endif %} -

{{ product['name'] }}

-
- {% if product.get('discount') %} - {{ product['price'] }} с - {{ (product['price'] * (1 - product['discount'] / 100))|round(2) }} с - Скидка: {{ product['discount'] }}% - {% else %} - {{ product['price'] }} с - {% endif %} - {% if product.get('wholesale_price') and product.get('min_wholesale') %} - Опт: {{ product['wholesale_price'] }} с - {% endif %} -
-

{{ product['description'][:50] }}{% if product['description']|length > 50 %}...{% endif %}

- -
- {% endfor %} -
-
- - - - - - - - - - - - - - - - - - - - - ''' - return render_template_string(discounts_html, products=products, repo_id=REPO_ID) - - -@app.route('/product/') -def product_details(index): - data = load_data() - if index < 0 or index >= len(data['products']): - return "Product not found", 404 # Return a 404 error if index is out of bounds - product = data['products'][index] - - product_html = ''' - -
-

{{ product['name'] }}

-
-
- {% for photo in product.get('photos', []) %} -
- {{ product['name'] }} -
- {% endfor %} -
-
-
-
-
-
- {% if product.get('discount') %} - {{ product['price'] }} с - {{ (product['price'] * (1 - product['discount'] / 100))|round(2) }} с - Скидка: {{ product['discount'] }}% - {% else %} - {{ product['price'] }} с - {% endif %} - {% if product.get('wholesale_price') and product.get('min_wholesale') %} - Опт: {{ product['wholesale_price'] }} с (от {{ product['min_wholesale'] }}) - {% endif %} -
-

Описание: {{ product['description'] }}

-

Категория: {{ product.get('category', 'Без категории') }}

- {% if product.get('colors') %} -
- Цвета: - {% for color in product['colors'] %} - {{ color }} - {% endfor %} -
- {% endif %} -
- ''' - return render_template_string(product_html, product=product, repo_id=REPO_ID) - -@app.route('/admin', methods=['GET', 'POST']) -def admin(): - data = load_data() - products = data['products'] - categories = data['categories'] - - if request.method == 'POST': - action = request.form.get('action') - - if action == 'add': - photos = request.files.getlist('photos') - photo_filenames = [] - for photo in photos: - if photo and photo.filename: - filename = secure_filename(photo.filename) - api = HfApi() - api.upload_file( - path_or_fileobj=photo, - path_in_repo=f"photos/{filename}", - repo_id=REPO_ID, - repo_type="dataset", - token=HF_TOKEN_WRITE - ) - photo_filenames.append(filename) - - colors = request.form.getlist('colors') - colors = [color.strip() for color in colors if color.strip()] - - new_product = { - 'name': request.form['name'], - 'price': float(request.form['price']), - 'wholesale_price': float(request.form['wholesale_price']) if request.form['wholesale_price'] else None, - 'min_wholesale': int(request.form['min_wholesale']) if request.form['min_wholesale'] else None, - 'description': request.form['description'], - 'category': request.form['category'], - 'colors': colors, - 'photos': photo_filenames, - 'discount': float(request.form['discount']) if request.form['discount'] else None - } - products.append(new_product) - - elif action == 'edit': - index = int(request.form['index']) - photos = request.files.getlist('photos') - photo_filenames = products[index].get('photos', []) # Keep existing photos - for photo in photos: - if photo and photo.filename: - filename = secure_filename(photo.filename) - api = HfApi() - api.upload_file( - path_or_fileobj=photo, - path_in_repo=f"photos/{filename}", - repo_id=REPO_ID, - repo_type="dataset", - token=HF_TOKEN_WRITE - ) - photo_filenames.append(filename) # Add new photos - - colors = request.form.getlist('colors') - colors = [color.strip() for color in colors if color.strip()] - - products[index] = { - 'name': request.form['name'], - 'price': float(request.form['price']), - 'wholesale_price': float(request.form['wholesale_price']) if request.form['wholesale_price'] else None, - 'min_wholesale': int(request.form['min_wholesale']) if request.form['min_wholesale'] else None, - 'description': request.form['description'], - 'category': request.form['category'], - 'colors': colors, - 'photos': photo_filenames, # Updated photo list - 'discount': float(request.form['discount']) if request.form['discount'] else None - } - - elif action == 'delete': - index = int(request.form['index']) - # Delete photos from Hugging Face Hub before deleting the product - product_to_delete = products[index] - if 'photos' in product_to_delete: - api = HfApi() - for photo in product_to_delete['photos']: - try: - api.delete_file( - path_in_repo=f"photos/{photo}", - repo_id=REPO_ID, - repo_type="dataset", - token=HF_TOKEN_WRITE - ) - except Exception as e: - logging.error(f"Error deleting photo {photo}: {e}") - products.pop(index) - - - elif action == 'add_category': - category = request.form['category_name'].strip() - if category and category not in categories: - categories.append(category) - - elif action == 'delete_category': - index = int(request.form['category_index']) - category_to_delete = categories[index] - categories.pop(index) - #Set category to "Без категории" for products in the deleted category - for product in products: - if product.get('category') == category_to_delete: - product['category'] = 'Без категории' - - save_data({'products': products, 'categories': categories}) - return redirect(url_for('admin')) - - admin_html = ''' - - - - - - Админ-панель - -
-

Админ-панель

- -
-

Добавить товар

-
- - - - - - - - - - - - - - - - - - -
-
- -
-
- - -
+
+

Админ Панель

+
- -
-

Добавить категорию

-
- - - - -
+
+

Продукты

+
- -
- {% for category in categories %} -
-

{{ category }}

-
- - - -
+
+ +

+ +

+

Цена:

+

Категория:

+

Цвета:

+
+

Связанные товары:

+
+
- {% endfor %} -
- -

Список товаров

-
-
-
- {% for product in products %} -
-

{{ product['name'] }}

-

Цена (розница): {{ product['price'] }} с

- {% if product.get('wholesale_price') and product.get('min_wholesale') %} -

Цена (опт): {{ product['wholesale_price'] }} с (от {{ product['min_wholesale'] }})

- {% endif %} - {% if product.get('discount') %} -

Скидка: {{ product['discount'] }}%

- {% endif %} -

Описание: {{ product['description'] }}

-

Категория: {{ product.get('category', 'Без категории') }}

-

Цвета: {{ product.get('colors', ['Нет цветов'])|join(', ') }}

- {% if product.get('photos') %} -

Фотографии:

- {% for photo in product['photos'] %} - {{ product['name'] }} - {% endfor %} - {% endif %} -
- Редактировать -
- - - - - - - - - - - - - - - - - - - -
- {% for color in product.get('colors', []) %} -
- -
- {% endfor %} -
- - -
-
-
- - - -
+ + + + + + + + + + + + + + + + {% for product in products %} + + + + + + + + + + {% endfor %} + +
ФотоНазваниеОписаниеЦенаКатегорияЦветаДействия
+ {% if product.get('photos') and product['photos']|length > 0 %} + {{ product['name'] }} + {% endif %} + {{ product['name'] }}{{ product['description'] }}{{ product['price'] }} с{{ product.get('category', 'Без категории') }} + {% if product.get('colors') %} + {% for color in product['colors'] %} + + {% endfor %} + {% else %} + Нет + {% endif %} + + + +
+
@@ -3708,4 +1576,4 @@ if __name__ == '__main__': load_data() except Exception as e: logging.error(f"Не удалось загрузить базу данных: {e}") - app.run(debug=True, host='0.0.0.0', port=7860) \ No newline at end of file + app.run(debug=True, host='0.0.0.0', port=7860)