delete, edit, view lots

This commit is contained in:
Cayo Puigdefabregas 2024-07-10 13:55:57 +02:00
parent 9f37c8fbd7
commit d687c96112
7 changed files with 150 additions and 9 deletions

View File

@ -104,17 +104,17 @@
</a> </a>
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'People' %}expanded{% else %}collapse{% endif %}" id="ul_lots" data-bs-parent="#sidebarMenu"> <ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if section == 'People' %}expanded{% else %}collapse{% endif %}" id="ul_lots" data-bs-parent="#sidebarMenu">
<li class="nav-items"> <li class="nav-items">
<a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{# url 'idhub:admin_people_list' #}"> <a class="nav-link{% if path == 'admin_people_list' %} active2{% endif %}" href="{% url 'lot:lots_incoming' %}">
{% trans 'Incoming ' %} {% trans 'Incoming ' %}
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link{% if path == 'admin_people_new' %} active2{% endif %}" href="{# url 'idhub:admin_people_new' #}"> <a class="nav-link{% if path == 'admin_people_new' %} active2{% endif %}" href="{% url 'lot:lots_outgoing' %}">
{% trans 'Outgoing ' %} {% trans 'Outgoing ' %}
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link{% if path == 'admin_people_new' %} active2{% endif %}" href="{# url 'idhub:admin_people_new' #}"> <a class="nav-link{% if path == 'admin_people_new' %} active2{% endif %}" href="{% url 'lot:lots_temporal' %}">
{% trans 'Temporal ' %} {% trans 'Temporal ' %}
</a> </a>
</li> </li>

View File

@ -5,4 +5,5 @@ app_name = 'dashboard'
urlpatterns = [ urlpatterns = [
path("", views.UnassignedDevicesView.as_view(), name="unassigned_devices"), path("", views.UnassignedDevicesView.as_view(), name="unassigned_devices"),
path("<int:pk>/", views.LotDashboardView.as_view(), name="lot"),
] ]

View File

@ -1,7 +1,8 @@
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic.base import TemplateView from django.db.models import Count
from dashboard.mixins import InventaryMixin from dashboard.mixins import InventaryMixin, DetailsMixin
from device.models import Device from device.models import Device
from lot.models import Lot
class UnassignedDevicesView(InventaryMixin): class UnassignedDevicesView(InventaryMixin):
@ -12,7 +13,25 @@ class UnassignedDevicesView(InventaryMixin):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
devices = Device.objects.filter(owner=self.request.user) devices = Device.objects.filter(
owner=self.request.user
).annotate(num_lots=Count('lot')).filter(num_lots=0)
context.update({
'devices': devices,
})
return context
class LotDashboardView(InventaryMixin, DetailsMixin):
template_name = "unassigned_devices.html"
section = "Unassigned"
title = _("Lot Devices")
breadcrumb = "Devices / Lot Devices"
model = Lot
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
devices = self.object.devices.filter(owner=self.request.user)
context.update({ context.update({
'devices': devices, 'devices': devices,
}) })

View File

@ -0,0 +1,38 @@
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<div class="row">
<div class="col">
<h3>{{ subtitle }}</h3>
</div>
</div>
{% load django_bootstrap5 %}
<div class="row mb-3">
<div class="col">
Are you sure than want remove the lot {{ object.name }} with {{ object.devices.count }} devices.
</div>
</div>
<form role="form" method="post">
{% csrf_token %}
{% if form.errors %}
<div class="alert alert-danger alert-icon alert-icon-border alert-dismissible" role="alert">
<div class="icon"><span class="mdi mdi-close-circle-o"></span></div>
<div class="message">
{% for field, error in form.errors.items %}
{{ error }}<br />
{% endfor %}
<button class="btn-close" type="button" data-dismiss="alert" aria-label="Close"></button>
</div>
</div>
{% endif %}
{% bootstrap_form form %}
<div class="form-actions-no-box">
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Delete' %}" />
</div>
</form>
{% endblock %}

33
lot/templates/lots.html Normal file
View File

@ -0,0 +1,33 @@
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<div class="row mb-3">
<div class="col">
<h3>{{ subtitle }}</h3>
</div>
<div class="col text-center">
<a href="{% url 'lot:add' %}" type="button" class="btn btn-green-admin">
<i class="bi bi-plus"></i>
{% trans 'Add new lot' %}
</a>
</div>
</div>
<div class="row">
<table class= "table table-striped table-sm">
{% for lot in lots %}
<tr>
<td><a href="{% url 'dashboard:lot' lot.id %}">{{ lot.name }}</a></td>
<td>
<a href="{% url 'lot:edit' lot.id %}"><i class="bi bi-pen"></i></a>
</td>
<td>
<a href="{% url 'lot:delete' lot.id %}"><i class="bi bi-trash text-danger"></i></a>
</td>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}

View File

@ -5,7 +5,11 @@ app_name = 'lot'
urlpatterns = [ urlpatterns = [
path("add/", views.NewLotView.as_view(), name="add"), path("add/", views.NewLotView.as_view(), name="add"),
path("delete/<int:pk>/", views.DeleteLotView.as_view(), name="delete"),
path("edit/<int:pk>/", views.EditLotView.as_view(), name="edit"), path("edit/<int:pk>/", views.EditLotView.as_view(), name="edit"),
path("add/devices/", views.AddToLotView.as_view(), name="add_devices"), path("add/devices/", views.AddToLotView.as_view(), name="add_devices"),
path("del/devices/", views.DelToLotView.as_view(), name="del_devices"), path("del/devices/", views.DelToLotView.as_view(), name="del_devices"),
path("temporal/", views.LotsTemporalView.as_view(), name="lots_temporal"),
path("outgoing/", views.LotsOutgoingView.as_view(), name="lots_outgoing"),
path("incoming/", views.LotsIncomingView.as_view(), name="lots_incoming"),
] ]

View File

@ -1,8 +1,10 @@
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic.base import TemplateView
from django.views.generic.edit import ( from django.views.generic.edit import (
CreateView, CreateView,
DeleteView,
UpdateView, UpdateView,
FormView FormView
) )
@ -31,10 +33,29 @@ class NewLotView(DashboardView, CreateView):
return response return response
class DeleteLotView(DashboardView, DeleteView):
template_name = "delete_lot.html"
title = _("Delete lot")
breadcrumb = "lot / Delete lot"
success_url = reverse_lazy('dashboard:unassigned_devices')
model = Lot
fields = (
"type",
"name",
"code",
"description",
"closed",
)
def form_valid(self, form):
response = super().form_valid(form)
return response
class EditLotView(DashboardView, UpdateView): class EditLotView(DashboardView, UpdateView):
template_name = "new_lot.html" template_name = "new_lot.html"
title = _("Update lot") title = _("Edit lot")
breadcrumb = "Lot / Update lot" breadcrumb = "Lot / Edit lot"
success_url = reverse_lazy('dashboard:unassigned_devices') success_url = reverse_lazy('dashboard:unassigned_devices')
model = Lot model = Lot
fields = ( fields = (
@ -98,3 +119,28 @@ class DelToLotView(AddToLotView):
return response return response
class LotsTemporalView(DashboardView, TemplateView):
template_name = "lots.html"
title = _("Temporal lots")
breadcrumb = "lot / temporal lots"
success_url = reverse_lazy('dashboard:unassigned_devices')
lot_type = Lot.Types.TEMPORAL
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
lots = Lot.objects.filter(owner=self.request.user)
context.update({
'lots': lots.filter(type=self.lot_type),
})
return context
class LotsOutgoingView(LotsTemporalView):
title = _("Outgoing lots")
breadcrumb = "lot / outging lots"
lot_type = Lot.Types.OUTGOING
class LotsIncomingView(LotsTemporalView):
title = _("Incoming lots")
breadcrumb = "lot / Incoming lots"
lot_type = Lot.Types.INCOMING