delete, edit, view lots
This commit is contained in:
parent
9f37c8fbd7
commit
d687c96112
|
@ -104,17 +104,17 @@
|
|||
</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">
|
||||
<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 ' %}
|
||||
</a>
|
||||
</li>
|
||||
<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 ' %}
|
||||
</a>
|
||||
</li>
|
||||
<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 ' %}
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -5,4 +5,5 @@ app_name = 'dashboard'
|
|||
|
||||
urlpatterns = [
|
||||
path("", views.UnassignedDevicesView.as_view(), name="unassigned_devices"),
|
||||
path("<int:pk>/", views.LotDashboardView.as_view(), name="lot"),
|
||||
]
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic.base import TemplateView
|
||||
from dashboard.mixins import InventaryMixin
|
||||
from django.db.models import Count
|
||||
from dashboard.mixins import InventaryMixin, DetailsMixin
|
||||
from device.models import Device
|
||||
from lot.models import Lot
|
||||
|
||||
|
||||
class UnassignedDevicesView(InventaryMixin):
|
||||
|
@ -12,7 +13,25 @@ class UnassignedDevicesView(InventaryMixin):
|
|||
|
||||
def get_context_data(self, **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({
|
||||
'devices': devices,
|
||||
})
|
||||
|
|
38
lot/templates/delete_lot.html
Normal file
38
lot/templates/delete_lot.html
Normal 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
33
lot/templates/lots.html
Normal 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 %}
|
|
@ -5,7 +5,11 @@ app_name = 'lot'
|
|||
|
||||
urlpatterns = [
|
||||
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("add/devices/", views.AddToLotView.as_view(), name="add_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"),
|
||||
]
|
||||
|
|
50
lot/views.py
50
lot/views.py
|
@ -1,8 +1,10 @@
|
|||
from django.urls import reverse_lazy
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import (
|
||||
CreateView,
|
||||
DeleteView,
|
||||
UpdateView,
|
||||
FormView
|
||||
)
|
||||
|
@ -31,10 +33,29 @@ class NewLotView(DashboardView, CreateView):
|
|||
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):
|
||||
template_name = "new_lot.html"
|
||||
title = _("Update lot")
|
||||
breadcrumb = "Lot / Update lot"
|
||||
title = _("Edit lot")
|
||||
breadcrumb = "Lot / Edit lot"
|
||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
||||
model = Lot
|
||||
fields = (
|
||||
|
@ -98,3 +119,28 @@ class DelToLotView(AddToLotView):
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue