diff --git a/essenza/product/forms.py b/essenza/product/forms.py index b3ddef9..c9369a9 100644 --- a/essenza/product/forms.py +++ b/essenza/product/forms.py @@ -1,8 +1,18 @@ from django import forms + from .models import Product class ProductForm(forms.ModelForm): class Meta: model = Product - fields = ['name', 'description', 'category', 'brand', 'price', 'photo', 'stock', 'is_active'] + fields = [ + "name", + "description", + "category", + "brand", + "price", + "photo", + "stock", + "is_active", + ] diff --git a/essenza/product/tests.py b/essenza/product/tests.py index 248dc3b..6bf1658 100644 --- a/essenza/product/tests.py +++ b/essenza/product/tests.py @@ -328,13 +328,13 @@ def test_admin_can_access_detail(self): def test_admin_can_create_product(self): """Prueba que un admin puede crear un nuevo producto (POST).""" self.client.force_login(self.admin) - + initial_count = Product.objects.count() data = { "name": "Nuevo Producto Creado", "description": "Creado por el test de admin", - "category": "perfume", + "category": "perfume", "brand": "NewBrand", "price": "99.99", "stock": 100, @@ -355,7 +355,7 @@ def test_admin_can_update_product(self): data = { "name": updated_name, "description": "Descripción actualizada", - "category": "tratamiento", + "category": "tratamiento", "brand": self.product.brand, "price": updated_price, "stock": 50, @@ -365,7 +365,7 @@ def test_admin_can_update_product(self): self.assertEqual(resp.status_code, 302) self.assertRedirects(resp, reverse("product_list")) - + self.product.refresh_from_db() self.assertEqual(self.product.name, updated_name) self.assertEqual(self.product.price, Decimal(updated_price)) diff --git a/essenza/product/urls.py b/essenza/product/urls.py index 83d25b7..dfa067d 100644 --- a/essenza/product/urls.py +++ b/essenza/product/urls.py @@ -6,11 +6,11 @@ urlpatterns = [ path("stock/", views.StockView.as_view(), name="stock"), - path('', views.ProductListView.as_view(), name='product_list'), - path('create/', views.ProductCreateView.as_view(), name='product_create'), - path('/', views.ProductDetailView.as_view(), name='product_detail'), - path('/edit/', views.ProductUpdateView.as_view(), name='product_update'), - path('/delete/', views.ProductDeleteView.as_view(), name='product_delete'), + path("", views.ProductListView.as_view(), name="product_list"), + path("create/", views.ProductCreateView.as_view(), name="product_create"), + path("/", views.ProductDetailView.as_view(), name="product_detail"), + path("/edit/", views.ProductUpdateView.as_view(), name="product_update"), + path("/delete/", views.ProductDeleteView.as_view(), name="product_delete"), ] if settings.DEBUG: diff --git a/essenza/product/views.py b/essenza/product/views.py index a06aa16..783a03f 100644 --- a/essenza/product/views.py +++ b/essenza/product/views.py @@ -9,6 +9,11 @@ from .models import Product +class BaseView(View): + def get(self, request): + return render(request, "base.html") + + class DashboardView(UserPassesTestMixin, View): template_name = "product/dashboard.html" diff --git a/essenza/templates/base.html b/essenza/templates/base.html new file mode 100644 index 0000000..81e3c78 --- /dev/null +++ b/essenza/templates/base.html @@ -0,0 +1,313 @@ +{% load static %} + + + + + {% block title %}Essenza{% endblock %} + + + + + {% block extra_head %}{% endblock %} + + + +
+ + + + + + +
+ + {% block content %}{% endblock %} + + + + {% block extra_js %}{% endblock %} + + diff --git a/essenza/templates/product/catalog.html b/essenza/templates/product/catalog.html index 974a580..5675991 100644 --- a/essenza/templates/product/catalog.html +++ b/essenza/templates/product/catalog.html @@ -1,11 +1,12 @@ +{% extends "base.html" %} + + + {% load static %} {% load humanize %} - - - - - Catálogo · Essenza +{% block title %}Catálogo · Essenza{% endblock %} +{% block content %} - - -
-
+
+
+
{% if product.photo %} @@ -232,5 +185,4 @@

{{ product.name }}

- - +{% endblock %} \ No newline at end of file diff --git a/essenza/templates/product/detail_user.html b/essenza/templates/product/detail_user.html index 19d40c1..1f7b6f2 100644 --- a/essenza/templates/product/detail_user.html +++ b/essenza/templates/product/detail_user.html @@ -1,247 +1,55 @@ +{% extends "base.html" %} {% load static %} - - - - - - {{ product.name }} - Essenza - - - - +{% block title %}{{ product.name }} - Essenza{% endblock %} + +{% block extra_head %} + +{% endblock %} + +{% block content %} +
{% if product.photo %} - {{ product.name }} + {{ product.name }} {% else %} - {{ product.name }} + {{ product.name }} {% endif %}
@@ -251,14 +59,10 @@

{{ product.name }}

€ {{ product.price }}
{% if product.get_categoria_display %} - {{ product.get_categoria_display }} + {{ product.get_categoria_display }} {% endif %} -
- Stock: {{ product.stock }} unidades -
+
Stock: {{ product.stock }} unidades
@@ -274,9 +78,9 @@

{{ product.name }}

Estado
{% if product.is_active %} - ✓ Activo + ✓ Activo {% else %} - ✗ Inactivo + ✗ Inactivo {% endif %}
@@ -288,61 +92,27 @@

{{ product.name }}

- - ← Volver + ← Volver
- - - - - +
+ + +{% endblock %} \ No newline at end of file diff --git a/essenza/templates/product/list.html b/essenza/templates/product/list.html index 1e325c0..ff3d14b 100644 --- a/essenza/templates/product/list.html +++ b/essenza/templates/product/list.html @@ -1,27 +1,24 @@ +{% extends "base.html" %} + +{% block title %}Lista de Productos · Essenza{% endblock %} + +{% block content %} {% load static %} - - - - - - Lista de Productos - Essenza - - -
-
- i -
ESSENZA
- - -
- -
- - - -
-
- -
+
+ - - - +{% endblock %} \ No newline at end of file diff --git a/essenza/templates/product/stock.html b/essenza/templates/product/stock.html index e4779cf..70edfee 100644 --- a/essenza/templates/product/stock.html +++ b/essenza/templates/product/stock.html @@ -1,375 +1,184 @@ -{% load static %} - - - - - Escaparate · Essenza - - - - - - -
- i -
ESSENZA
- - - -
- +{% extends 'base.html' %} {% load static %} {% block title %}Stock · +Essenza{%endblock %} {% block content %} + + + + +
+ {% for p in products %} +
+ {% if p.photo %} + {{ p.name }} + {% else %} + + {% endif %} + +
+
{{ p.name }}
+ + {% if p.description %} +
{{ p.description }}
+ {% endif %} {% if p.category %} +
{{ p.get_category_display }}
+ {% endif %} - -
-
- {% for p in products %} -
- {% if p.photo %} - - {% else %} - + {% if user.is_staff or user.is_superuser %} +
+ {% csrf_token %} + + + +
{% endif %} - -
-
{{ p.name }}
- - {% if p.description %} -
{{ p.description }}
- {% endif %} {% if p.category %} -
{{ p.get_category_display }}
- {% endif %} - -
- {% with stock_value=p.stock|default:0 %} {% if stock_value <= 0 %} - Agotado (0) - {% elif stock_value <= 10 %} - Stock Bajo: {{ stock_value }} - {% else %} - En Stock: {{ stock_value }} - {% endif %} {% endwith %} -
- -
- {% csrf_token %} - - - -
-
- {% endfor %} -
- - - - + {% endblock %} + diff --git a/essenza/templates/user/profile.html b/essenza/templates/user/profile.html index 35ec3b9..594cb4e 100644 --- a/essenza/templates/user/profile.html +++ b/essenza/templates/user/profile.html @@ -1,165 +1,45 @@ +{% extends "base.html" %} {% load static %} - - - - - Mi Perfil · Essenza - - - - - Volver + -
-

ESSENZA

+
+

ESSENZA

-
- {% if user.photo %} - Foto de perfil - {% else %} - Foto de perfil por defecto - {% endif %} +
+ {% if user.photo %} + Foto de perfil + {% else %} + Foto de perfil por defecto + {% endif %} -
-

Nombre: {{ user.first_name }}

-

Apellidos: {{ user.last_name }}

-

Email: {{ user.email }}

-
- - Editar mis datos - +
+

Nombre: {{ user.first_name }}

+

Apellidos: {{ user.last_name }}

+

Email: {{ user.email }}

+ + Editar mis datos +
- - +
+ +{% endblock %} \ No newline at end of file