53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
from django.contrib.auth import get_user_model
|
|
from django.views.generic import DetailView, ListView
|
|
|
|
from backoffice.mixins import BackofficeCRUDMixin, BackofficeHtmxMixin
|
|
from shop.models import CustomerAddress, Order
|
|
|
|
User = get_user_model()
|
|
|
|
SECTION = 'customers'
|
|
|
|
|
|
class CustomerListView(BackofficeCRUDMixin, BackofficeHtmxMixin, ListView):
|
|
model = User
|
|
permission_required = 'auth.view_user'
|
|
section = SECTION
|
|
paginate_by = 20
|
|
template_name = 'backoffice/generic/list.html'
|
|
fragment_template_name = 'backoffice/generic/_list_fragment.html'
|
|
|
|
def get_queryset(self):
|
|
return super().get_queryset().filter(is_staff=False).order_by('email')
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context.update(
|
|
{
|
|
'title': 'Clientes',
|
|
'columns': [('E-mail', 'email'), ('Nombre', 'first_name'), ('Apellidos', 'last_name')],
|
|
'detail_url_name': 'backoffice:customer_detail',
|
|
}
|
|
)
|
|
return context
|
|
|
|
|
|
class CustomerDetailView(BackofficeCRUDMixin, DetailView):
|
|
model = User
|
|
permission_required = 'auth.view_user'
|
|
section = SECTION
|
|
template_name = 'backoffice/customers/customer_detail.html'
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context.update(
|
|
{
|
|
'addresses': CustomerAddress.objects.filter(user=self.object),
|
|
'orders': Order.objects.filter(user=self.object),
|
|
}
|
|
)
|
|
return context
|
|
|
|
# CRUD pendiente: la edición/borrado de clientes ya se gestiona a través del
|
|
# admin de Django (auth.User) — aquí solo se expone consulta.
|