feat: added user order list view
This commit is contained in:
@@ -62,8 +62,9 @@
|
||||
</div>
|
||||
{% else %}
|
||||
<a href="{% url 'web:login' %}"
|
||||
class="inline-flex items-center rounded-lg justify-center p-2 hover:bg-gray-100 dark:hover:bg-gray-700 text-sm font-medium leading-none text-gray-900 dark:text-white">Inicia
|
||||
sesión</a>
|
||||
class="inline-flex items-center rounded-lg justify-center p-2 hover:bg-gray-100 dark:hover:bg-gray-700 text-sm font-medium leading-none text-gray-900 dark:text-white">
|
||||
Inicia sesión
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
<!-- Show/Hide menu items -->
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" title=""
|
||||
<a href="{% url 'web:orders' %}" title=""
|
||||
class="inline-flex w-full items-center gap-2 rounded-md px-3 py-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-600">
|
||||
{% translate 'Mis pedidos' %}
|
||||
</a>
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
{% extends 'theme/base.html' %}
|
||||
{% load static i18n %}
|
||||
|
||||
{% block main %}
|
||||
{% include 'components/generic/navbar.html' %}
|
||||
<div class="mx-auto max-w-screen-xl px-4 2xl:px-0">
|
||||
<div class="mx-auto max-w-5xl">
|
||||
<div class="gap-4">
|
||||
<h1 class="text-xl font-semibold text-gray-900 dark:text-white sm:text-2xl my-4">
|
||||
{% translate 'Mis pedidos' %}
|
||||
</h1>
|
||||
|
||||
<div class="mt-6 flow-root sm:mt-8">
|
||||
<div class="divide-y divide-gray-200 dark:divide-gray-700">
|
||||
{% for order in page %}
|
||||
|
||||
<article class="flex flex-wrap items-center gap-y-4 py-6">
|
||||
<dl class="w-1/2 sm:w-1/4 lg:w-auto lg:flex-1 px-4">
|
||||
<dt class="text-base font-medium text-gray-500 dark:text-gray-400">
|
||||
{% translate 'Número de pedido' %}
|
||||
</dt>
|
||||
<dd class="mt-1.5 text-base font-semibold text-gray-900 dark:text-white">
|
||||
<a href="{% url 'web:order' uuid=order.uuid %}" class="hover:underline">
|
||||
#{{ order.code }}
|
||||
</a>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl class="w-1/2 sm:w-1/4 lg:w-auto lg:flex-1 px-4">
|
||||
<dt class="text-base font-medium text-gray-500 dark:text-gray-400">
|
||||
{% translate 'Fecha' %}
|
||||
</dt>
|
||||
<dd class="mt-1.5 text-base font-semibold text-gray-900 dark:text-white">
|
||||
{{ order.creation_date }}
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl class="w-1/2 sm:w-1/4 lg:w-auto lg:flex-1 px-4">
|
||||
<dt class="text-base font-medium text-gray-500 dark:text-gray-400">
|
||||
{% translate 'Total' %}
|
||||
</dt>
|
||||
<dd class="mt-1.5 text-base font-semibold text-gray-900 dark:text-white">
|
||||
{{ order.total }}€
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl class="w-1/2 sm:w-1/4 lg:w-auto lg:flex-1 px-4">
|
||||
|
||||
{% if order.status == 'PAI' %}
|
||||
<dd class="inline-flex bg-green-100 text-green-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-green-900 dark:text-green-300">
|
||||
{% translate 'Pagado' %}
|
||||
</dd>
|
||||
|
||||
{% if order.shipping_status == 'NOT' %}
|
||||
<dd class="inline-flex bg-yellow-100 text-yellow-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300">
|
||||
{% translate 'Tramitado' %}
|
||||
</dd>
|
||||
{% elif order.shipping_status == 'RDY' %}
|
||||
<dd class="inline-flex bg-yellow-100 text-yellow-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300">
|
||||
{% translate 'Preparado' %}
|
||||
</dd>
|
||||
{% elif order.shipping_status == 'TBS' %}
|
||||
<dd class="inline-flex bg-yellow-100 text-yellow-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300">
|
||||
{% translate 'Listo' %}
|
||||
</dd>
|
||||
{% elif order.shipping_status == 'SNT' %}
|
||||
<dd class="inline-flex bg-blue-100 text-blue-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300">
|
||||
{% translate 'Enviado' %}
|
||||
</dd>
|
||||
{% elif order.shipping_status == 'DLV' %}
|
||||
<dd class="inline-flex bg-green-100 text-green-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-green-900 dark:text-green-300">
|
||||
{% translate 'Entregado' %}
|
||||
</dd>
|
||||
{% endif %}
|
||||
|
||||
{% elif order.status == 'ERR' %}
|
||||
<dd class="inline-flex bg-red-100 text-red-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-red-900 dark:text-red-300">
|
||||
{% translate 'Error' %}
|
||||
</dd>
|
||||
{% elif order.status == 'RTN' %}
|
||||
<dd class="inline-flex bg-yellow-100 text-yellow-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded dark:bg-yellow-900 dark:text-yellow-300">
|
||||
{% translate 'Devuelto' %}
|
||||
</dd>
|
||||
{% endif %}
|
||||
</dl>
|
||||
|
||||
<a href="{% url 'web:order' uuid=order.uuid %}"
|
||||
class="w-full inline-flex justify-center rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm font-medium text-gray-900 hover:bg-gray-100 hover:text-primary-700 focus:z-10 focus:outline-none focus:ring-4 focus:ring-gray-100 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white dark:focus:ring-gray-700 lg:w-auto">
|
||||
{% translate 'Ver pedido' %}
|
||||
</a>
|
||||
</article>
|
||||
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -21,6 +21,7 @@ from web.views.web import (
|
||||
index,
|
||||
manifest,
|
||||
order_detail,
|
||||
orders,
|
||||
product_detail,
|
||||
wishlist,
|
||||
)
|
||||
@@ -33,6 +34,7 @@ i18n_resolvers = i18n_patterns(
|
||||
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"),
|
||||
path(_("orders/"), login_required(orders, login_url="/login/"), name="orders"),
|
||||
path(_("order/<str:uuid>/"), order_detail, name="order"),
|
||||
# users
|
||||
path(_("login/"), login, name="login"),
|
||||
|
||||
@@ -19,6 +19,7 @@ from shop.models import (
|
||||
from shop.redsys import RedsysClient
|
||||
from shop.utils import create_order_from_cart
|
||||
from web.forms import CreateOrderForm
|
||||
from web.mixins import PaginatedQuerysetMixin, FilteredQuerysetMixin
|
||||
from web.models import WebSettings
|
||||
from web.settings import ANONYMOUS_CART_ID_COOKIE_NAME
|
||||
from web.utils import get_or_create_cart
|
||||
@@ -192,6 +193,24 @@ class WishlistView(TemplateView):
|
||||
}
|
||||
|
||||
|
||||
class OrdersView(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin):
|
||||
template_name = "web/orders.html"
|
||||
|
||||
def get_queryset(self):
|
||||
return Order.objects.filter(user=self.request.user).exclude(status=Order.Statuses.STATUS_PENDING)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
settings = WebSettings.load()
|
||||
qs = self.get_queryset()
|
||||
page = self.get_paginated_queryset(qs)
|
||||
|
||||
return {
|
||||
"page": page,
|
||||
"has_next_page": page.has_next(),
|
||||
"has_previous_page": page.has_previous(),
|
||||
}
|
||||
|
||||
|
||||
@require_http_methods(
|
||||
[
|
||||
"POST",
|
||||
@@ -311,3 +330,4 @@ product_detail = ProductDetail.as_view()
|
||||
cart_detail = CartDetail.as_view()
|
||||
order_detail = OrderDetail.as_view()
|
||||
wishlist = WishlistView.as_view()
|
||||
orders = OrdersView.as_view()
|
||||
|
||||
Reference in New Issue
Block a user