feat: added categories
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
from shop.models import ProductCategory
|
||||
from web.models import WebSettings
|
||||
|
||||
|
||||
def web_settings(request):
|
||||
settings = WebSettings.load()
|
||||
navbar_categories = ProductCategory.objects.filter(hidden=False, show_in_navbar=True)
|
||||
|
||||
return {
|
||||
"logo": settings.logo.url if settings.logo else "",
|
||||
"navbar_categories": navbar_categories,
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
from django.conf import settings
|
||||
from django.core.paginator import Paginator
|
||||
|
||||
from shop.models import Cart
|
||||
from web.settings import ANONYMOUS_CART_ID_COOKIE_NAME
|
||||
|
||||
|
||||
class FilteredQuerysetMixin:
|
||||
queryset = None
|
||||
|
||||
@@ -22,24 +22,14 @@
|
||||
{% translate 'Inicio' %}
|
||||
</a>
|
||||
</li>
|
||||
{% for category in navbar_categories %}
|
||||
<li class="shrink-0">
|
||||
<a href="{% url 'web:index' %}" title=""
|
||||
<a href="{% url 'web:category_view' slug=category.slug %}" title=""
|
||||
class="flex text-sm font-medium text-gray-900 hover:text-primary-700 dark:text-white dark:hover:text-primary-500">
|
||||
{% translate 'Más vendidos' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="shrink-0">
|
||||
<a href="{% url 'web:index' %}" title=""
|
||||
class="flex text-sm font-medium text-gray-900 hover:text-primary-700 dark:text-white dark:hover:text-primary-500">
|
||||
{% translate 'Ideas de regalo' %}
|
||||
</a>
|
||||
</li>
|
||||
<li class="shrink-0">
|
||||
<a href="{% url 'web:index' %}" title=""
|
||||
class="text-sm font-medium text-gray-900 hover:text-primary-700 dark:text-white dark:hover:text-primary-500">
|
||||
{% translate 'Ofertas del día' %}
|
||||
{{ category.name }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
{% include 'components/products/list_filters.html' %}
|
||||
<section
|
||||
class="p-8"
|
||||
hx-get="{% url 'web:list_products' %}{% querystring request.GET %}"
|
||||
hx-get="{% url 'web:list_products' %}{% querystring request.GET %}{% if filter_by_category %}{% querystring category=category.id %}{% endif %}"
|
||||
hx-trigger="load"
|
||||
hx-target="#products"
|
||||
hx-swap="innerHTML"
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from shop.models import ProductCategory
|
||||
from shop.tests.mixins import CreateProductsMixin
|
||||
|
||||
|
||||
class TestCategoryView(TestCase, CreateProductsMixin):
|
||||
def setUp(self):
|
||||
self.product = self.create_product()
|
||||
|
||||
def test_category_view(self):
|
||||
category = ProductCategory.objects.create(
|
||||
name="category 1", show_in_navbar=True, hidden=False
|
||||
)
|
||||
response = self.client.get(reverse("web:category_view", kwargs={"slug": category.slug}))
|
||||
assert response.status_code == 200
|
||||
@@ -9,12 +9,14 @@ from web.views.web import (
|
||||
index,
|
||||
manifest,
|
||||
product_detail,
|
||||
category_view,
|
||||
)
|
||||
|
||||
app_name = "web"
|
||||
|
||||
urlpatterns = [
|
||||
path("", index, name="index"),
|
||||
path("categories/<str:slug>/", category_view, name="category_view"),
|
||||
path("products/<int:pk>/<str:slug>/", product_detail, name="product_detail"),
|
||||
path("cart/", cart_detail, name="cart_detail"),
|
||||
# users
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django.db.models import Sum
|
||||
from qrcode import constants as qr_constants
|
||||
from qrcode.main import QRCode
|
||||
|
||||
from shop.models import Cart, CartItem
|
||||
from web.settings import ANONYMOUS_CART_ID_COOKIE_NAME
|
||||
|
||||
+19
-1
@@ -4,7 +4,7 @@ from django.utils.text import gettext_lazy as _
|
||||
from django.views.decorators.http import require_http_methods
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
from shop.models import CartItem, Product
|
||||
from shop.models import CartItem, Product, ProductCategory
|
||||
from web.models import WebSettings
|
||||
from web.settings import ANONYMOUS_CART_ID_COOKIE_NAME
|
||||
from web.utils import get_or_create_cart
|
||||
@@ -22,6 +22,23 @@ class IndexView(TemplateView):
|
||||
}
|
||||
|
||||
|
||||
class CategoryView(TemplateView):
|
||||
template_name = "web/index.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
settings = WebSettings.load()
|
||||
slug = kwargs.get('slug')
|
||||
category = ProductCategory.objects.get(slug=slug)
|
||||
|
||||
return {
|
||||
"title": settings.web_title,
|
||||
"web_title": settings.web_title,
|
||||
"description": settings.web_description,
|
||||
"category": category,
|
||||
"filter_by_category": True,
|
||||
}
|
||||
|
||||
|
||||
class ProductDetail(TemplateView):
|
||||
template_name = "web/product_detail.html"
|
||||
|
||||
@@ -135,5 +152,6 @@ def manifest(request, *args, **kwargs):
|
||||
|
||||
|
||||
index = IndexView.as_view()
|
||||
category_view = CategoryView.as_view()
|
||||
product_detail = ProductDetail.as_view()
|
||||
cart_detail = CartDetail.as_view()
|
||||
|
||||
Reference in New Issue
Block a user