admin lot tags #47
173
admin/templates/lot_tag_panel.html
Normal file
173
admin/templates/lot_tag_panel.html
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
{% load i18n django_bootstrap5 %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col">
|
||||||
|
<h3>{{ subtitle }}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="col text-end">
|
||||||
|
<button type="button" class="btn btn-green-admin" data-bs-toggle="modal" data-bs-target="#addLotTagModal">
|
||||||
|
{% trans "Add" %}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row mt-4">
|
||||||
|
<div class="col">
|
||||||
|
{% if lot_tags %}
|
||||||
|
<table class="table table-hover table-bordered align-middle">
|
||||||
|
<thead class="table-light">
|
||||||
|
<tr>
|
||||||
|
<th scope="col">{% trans "Tag" %}
|
||||||
|
</th>
|
||||||
|
<th scope="col" width="15%" class="text-center">{% trans "Actions" %}
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="sortable_list">
|
||||||
|
{% for tag in lot_tags %}
|
||||||
|
<tr>
|
||||||
|
<td class="font-monospace">
|
||||||
|
{{ tag.name }}
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<!-- action buttons -->
|
||||||
|
<td>
|
||||||
|
<div class="btn-group float-end">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn btn-sm btn-outline-info d-flex align-items-center"
|
||||||
|
data-bs-toggle="modal" data-bs-target="#editLotTagModal{{ tag.id }}">
|
||||||
|
<i class="bi bi-pencil me-1"></i>
|
||||||
|
{% trans 'Edit' %}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button" class="btn btn-sm btn-outline-danger d-flex align-items-center"
|
||||||
|
data-bs-toggle="modal"
|
||||||
|
data-bs-target="#deleteLotTagModal{{ tag.id }}" >
|
||||||
|
<i class="bi bi-trash me-1"></i>
|
||||||
|
{% trans 'Delete' %}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<div class="alert alert-primary text-center mt-5" role="alert">
|
||||||
|
{% trans "No Lot Tags found on current organization" %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- add lot tag Modal -->
|
||||||
|
<div class="modal fade" id="addLotTagModal" tabindex="-1" aria-labelledby="addLoTagModalLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="addLotTagModalLabel">{% trans "Add Lot Tag" %}</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
|
||||||
|
<form method="post" action="{% url 'admin:add_lot_tag' %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="lotTagInput" class="form-label">{% trans "Tag" %}</label>
|
||||||
|
<input type="text" class="form-control" id="lotTagInput" name="name" maxlength="50" required>
|
||||||
|
<div class="form-text">{% trans "Maximum 50 characters." %}</div>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans "Close" %}</button>
|
||||||
|
<button type="submit" class="btn btn-primary">{% trans "Add Lot tag" %}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Edit Lot Tag Modals -->
|
||||||
|
{% for tag in lot_tags %}
|
||||||
|
<div class="modal fade" id="editLotTagModal{{ tag.id }}" tabindex="-1" aria-labelledby="editLotTagModalLabel{{ tag.id }}" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<form method="post" action="{% url 'admin:edit_lot_tag' tag.id %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title" id="editLotTagModalLabel{{ tag.id }}">
|
||||||
|
{% trans "Edit Lot Tag" %}
|
||||||
|
</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{% trans 'Close' %}"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="editLotTagInput{{ tag.id }}" class="form-label">{% trans "Tag" %}</label>
|
||||||
|
<input type="text" class="form-control" id="editLotTagInput{{ tag.id }}" name="name" maxlength="50" value="{{ tag.name }}" required>
|
||||||
|
<div class="form-text">{% trans "Maximum 50 characters." %}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{% trans "Cancel" %}</button>
|
||||||
|
<button type="submit" class="btn btn-green-admin">{% trans "Save Changes" %}</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
|
<!-- delete lot tag definition Modal -->
|
||||||
|
{% for tag in lot_tags %}
|
||||||
|
<div class="modal fade" id="deleteLotTagModal{{ tag.id }}" tabindex="-1" aria-labelledby="deleteLotTagModalLabel{{ tag.id }}" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title fw-bold" id="deleteLotTagModalLabel{{ tag.id }}">
|
||||||
|
{% trans "Delete Lot Tag" %}
|
||||||
|
</h5>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="{% trans 'Close' %}"></button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
{% if tag.lot_set.first %}
|
||||||
|
<div class="alert alert-warning text-center" role="alert">
|
||||||
|
{% trans "There are lots with this tag. Change the tag for this lots" %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="d-flex align-items-center border rounded p-3 mt-3">
|
||||||
|
<div>
|
||||||
|
<p class="mb-0 fw-bold">{{ tag.name }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<form method="post" action="{% url 'admin:delete_lot_tag' tag.pk %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||||
|
{% trans "Cancel" %}
|
||||||
|
</button>
|
||||||
|
{% if tag.lot_set.first %}
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||||
|
{% trans "Delete" %}
|
||||||
|
</button>
|
||||||
|
{% else %}
|
||||||
|
<button type="submit" class="btn btn-danger">
|
||||||
|
{% trans "Delete" %}
|
||||||
|
</button>
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
|
@ -15,4 +15,8 @@ urlpatterns = [
|
||||||
path("states/delete/<int:pk>", views.DeleteStateDefinitionView.as_view(), name='delete_state_definition'),
|
path("states/delete/<int:pk>", views.DeleteStateDefinitionView.as_view(), name='delete_state_definition'),
|
||||||
path("states/update_order/", views.UpdateStateOrderView.as_view(), name='update_state_order'),
|
path("states/update_order/", views.UpdateStateOrderView.as_view(), name='update_state_order'),
|
||||||
path("states/edit/<int:pk>/", views.UpdateStateDefinitionView.as_view(), name='edit_state_definition'),
|
path("states/edit/<int:pk>/", views.UpdateStateDefinitionView.as_view(), name='edit_state_definition'),
|
||||||
|
path("lot_tag/", views.LotTagPanelView.as_view(), name="tag_panel"),
|
||||||
|
path("lot_tag/add", views.AddLotTagView.as_view(), name="add_lot_tag"),
|
||||||
|
path("lot_tag/delete/<int:pk>", views.DeleteLotTagView.as_view(), name='delete_lot_tag'),
|
||||||
|
path("lot_tag/edit/<int:pk>/", views.UpdateLotTagView.as_view(), name='edit_lot_tag'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -18,6 +18,7 @@ from admin.forms import OrderingStateForm
|
||||||
from user.models import User, Institution
|
from user.models import User, Institution
|
||||||
from admin.email import NotifyActivateUserByEmail
|
from admin.email import NotifyActivateUserByEmail
|
||||||
from action.models import StateDefinition
|
from action.models import StateDefinition
|
||||||
|
from lot.models import LotTag
|
||||||
|
|
||||||
|
|
||||||
class AdminView(DashboardView):
|
class AdminView(DashboardView):
|
||||||
|
@ -112,6 +113,74 @@ class EditUserView(AdminView, UpdateView):
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
|
class LotTagPanelView(AdminView, TemplateView):
|
||||||
|
template_name = "lot_tag_panel.html"
|
||||||
|
title = _("Lot Tag Panel")
|
||||||
|
breadcrumb = _("admin / Lot Tag Panel")
|
||||||
|
|
||||||
|
|
||||||
|
class AddLotTagView(AdminView, CreateView):
|
||||||
|
template_name = "lot_tag_panel.html"
|
||||||
|
title = _("New lot tag Definition")
|
||||||
|
breadcrumb = "Admin / New lot tag"
|
||||||
|
success_url = reverse_lazy('admin:tag_panel')
|
||||||
|
model = LotTag
|
||||||
|
fields = ('name',)
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
form.instance.owner = self.request.user.institution
|
||||||
|
form.instance.user = self.request.user
|
||||||
|
|
||||||
|
response = super().form_valid(form)
|
||||||
|
messages.success(self.request, _("Lot Tag successfully added."))
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
class DeleteLotTagView(AdminView, DeleteView):
|
||||||
|
model = LotTag
|
||||||
|
success_url = reverse_lazy('admin:tag_panel')
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
pk = kwargs.get('pk')
|
||||||
|
self.object = get_object_or_404(
|
||||||
|
self.model,
|
||||||
|
owner=self.request.user.institution,
|
||||||
|
pk=pk
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.object.lot_set.first():
|
||||||
|
msg = _('This tag have lots. Impossible deleted.')
|
||||||
|
messages.warning(self.request, msg)
|
||||||
|
return redirect(reverse_lazy('admin:tag_panel'))
|
||||||
|
|
||||||
|
response = super().delete(request, *args, **kwargs)
|
||||||
|
msg = _('Lot Tag has been deleted.')
|
||||||
|
messages.success(self.request, msg)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateLotTagView(AdminView, UpdateView):
|
||||||
|
model = LotTag
|
||||||
|
template_name = 'lot_tag_panel.html'
|
||||||
|
fields = ['name']
|
||||||
|
success_url = reverse_lazy('admin:tag_panel')
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
pk = self.kwargs.get('pk')
|
||||||
|
self.object = get_object_or_404(
|
||||||
|
self.model,
|
||||||
|
owner=self.request.user.institution,
|
||||||
|
pk=pk
|
||||||
|
)
|
||||||
|
return super().get_form_kwargs()
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
response = super().form_valid(form)
|
||||||
|
msg = _("Lot Tag updated successfully.")
|
||||||
|
messages.success(self.request, msg)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
class InstitutionView(AdminView, UpdateView):
|
class InstitutionView(AdminView, UpdateView):
|
||||||
template_name = "institution.html"
|
template_name = "institution.html"
|
||||||
title = _("Edit institution")
|
title = _("Edit institution")
|
||||||
|
|
|
@ -82,11 +82,11 @@
|
||||||
<ul class="nav flex-column">
|
<ul class="nav flex-column">
|
||||||
{% if user.is_admin %}
|
{% if user.is_admin %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="admin {% if path in 'panel users states_panel edit_user delete_user new_user institution' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_admin" aria-expanded="false" aria-controls="ul_admin" href="javascript:void()">
|
<a class="admin {% if path in 'panel users states_panel tag_panel edit_user delete_user new_user institution' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_admin" aria-expanded="false" aria-controls="ul_admin" href="javascript:void()">
|
||||||
<i class="bi bi-person-fill-gear icon_sidebar"></i>
|
<i class="bi bi-person-fill-gear icon_sidebar"></i>
|
||||||
{% trans 'Admin' %}
|
{% trans 'Admin' %}
|
||||||
</a>
|
</a>
|
||||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path in 'panel institution users edit_user new_user delete_user states_panel' %}expanded{% else %}collapse{% endif %}" id="ul_admin" data-bs-parent="#sidebarMenu">
|
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path in 'panel users tag_panel states_panel' %}expanded{% else %}collapse{% endif %}" id="ul_admin" data-bs-parent="#sidebarMenu">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link{% if path in 'panel institution' %} active2{% endif %}" href="{% url 'admin:panel' %}">
|
<a class="nav-link{% if path in 'panel institution' %} active2{% endif %}" href="{% url 'admin:panel' %}">
|
||||||
{% trans 'Panel' %}
|
{% trans 'Panel' %}
|
||||||
|
@ -100,33 +100,44 @@
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link{% if path == 'states_panel' %} active2{% endif %}" href="{% url 'admin:states_panel' %}">
|
<a class="nav-link{% if path == 'states_panel' %} active2{% endif %}" href="{% url 'admin:states_panel' %}">
|
||||||
{% trans 'States' %}
|
{% trans 'States' %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link{% if path == 'tag_panel' %} active2{% endif %}" href="{% url 'admin:tag_panel' %}">
|
||||||
|
{% trans 'Lot Tags' %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="admin {% if path == 'unassigned_devices' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_devices" aria-expanded="false" aria-controls="ul_devices" href="javascript:void()">
|
<a class="admin {% if path in 'all_device' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_device" aria-expanded="false" aria-controls="ul_lots" href="javascript:void()">
|
||||||
<i class="bi bi-laptop icon_sidebar"></i>
|
<i class="bi bi-database icon_sidebar"></i>
|
||||||
{% trans 'Devices' %}
|
{% trans 'Device' %}
|
||||||
</a>
|
</a>
|
||||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path == 'unassigned_devices' %}expanded{% else %}collapse{% endif %}" id="ul_devices" data-bs-parent="#sidebarMenu">
|
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path in 'all_device' %}expanded{% else %}collapse{% endif %}" id="ul_device" data-bs-parent="#sidebarMenu">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link{% if path == 'unassigned_devices' %} active2{% endif %}" href="{% url 'dashboard:unassigned_devices' %}">
|
<a class="nav-link{% if path == 'all_device' %} active2{% endif %}" href="{% url 'dashboard:all_device' %}">
|
||||||
{% trans 'Unassigned devices' %}
|
{% trans 'All' %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="admin {% if path == 'tag' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_lots" aria-expanded="false" aria-controls="ul_lots" href="javascript:void()">
|
<a class="admin {% if path == 'tags' or path == 'lot' or path in 'unassigned dashboard' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_lots" aria-expanded="false" aria-controls="ul_lots" href="javascript:void()">
|
||||||
<i class="bi bi-database icon_sidebar"></i>
|
<i class="bi bi-database icon_sidebar"></i>
|
||||||
{% trans 'Lots' %}
|
{% trans 'Lots' %}
|
||||||
</a>
|
</a>
|
||||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path == 'tag' %}expanded{% else %}collapse{% endif %}" id="ul_lots" data-bs-parent="#sidebarMenu">
|
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path == 'tags' or path == 'lot' or path in 'unassigned dashboard' %}expanded{% else %}collapse{% endif %}" id="ul_lots" data-bs-parent="#sidebarMenu">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link{% if path == 'unassigned' %} active2{% endif %}" href="{% url 'dashboard:unassigned' %}">
|
||||||
|
{% trans 'Unassigned' %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|
||||||
{% for tag in lot_tags %}
|
{% for tag in lot_tags %}
|
||||||
<li class="nav-items">
|
<li class="nav-items">
|
||||||
<a class="nav-link{% if path == 'tag' %} active2{% endif %}" href="{% url 'lot:tag' tag.id %}">
|
<a class="nav-link{% if path == 'tags' %} active2{% endif %}" href="{% url 'lot:tags' tag.id %}">
|
||||||
{{ tag.name }}
|
{{ tag.name }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -134,37 +145,29 @@
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="admin {% if path in 'upload list' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_evidences" aria-expanded="false" aria-controls="ul_evidences" href="javascript:void()">
|
<a class="admin {% if path in 'upload list import add' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_evidences" aria-expanded="false" aria-controls="ul_evidences" href="javascript:void()">
|
||||||
<i class="bi bi-usb-drive icon_sidebar"></i>
|
<i class="bi bi-usb-drive icon_sidebar"></i>
|
||||||
{% trans 'Evidences' %}
|
{% trans 'Evidences' %}
|
||||||
</a>
|
</a>
|
||||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path in 'upload list' %}expanded{% else %}collapse{% endif %}" id="ul_evidences" data-bs-parent="#sidebarMenu">
|
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path in 'upload list import add' %}expanded{% else %}collapse{% endif %}" id="ul_evidences" data-bs-parent="#sidebarMenu">
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link{% if path == 'upload' %} active2{% endif %}" href="{% url 'evidence:upload' %}">
|
|
||||||
{% trans 'Upload one' %}
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link{% if path == 'list' %} active2{% endif %}" href="{% url 'evidence:list' %}">
|
<a class="nav-link{% if path == 'list' %} active2{% endif %}" href="{% url 'evidence:list' %}">
|
||||||
{% trans 'Old evidences' %}
|
{% trans 'List of evidences' %}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link{% if path == 'upload' %} active2{% endif %}" href="{% url 'evidence:upload' %}">
|
||||||
|
{% trans 'Upload with JSON file' %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="admin {% if path in 'import add' %}active {% endif %}nav-link fw-bold" data-bs-toggle="collapse" data-bs-target="#ul_placeholders" aria-expanded="false" aria-controls="ul_placeholders" href="javascript:void()">
|
|
||||||
<i class="bi-menu-button-wide icon_sidebar"></i>
|
|
||||||
{% trans 'Placeholders' %}
|
|
||||||
</a>
|
|
||||||
<ul class="flex-column mb-2 ul_sidebar accordion-collapse {% if path in 'import add' %}expanded{% else %}collapse{% endif %}" id="ul_placeholders" data-bs-parent="#sidebarMenu">
|
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link{% if path == 'import' %} active2{% endif %}" href="{% url 'evidence:import' %}">
|
<a class="nav-link{% if path == 'import' %} active2{% endif %}" href="{% url 'evidence:import' %}">
|
||||||
{% trans 'Upload Spreadsheet' %}
|
{% trans 'Upload with Spreadsheet' %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link{% if path == 'add' %} active2{% endif %}" href="{% url 'device:add' %}">
|
<a class="nav-link{% if path == 'add' %} active2{% endif %}" href="{% url 'device:add' %}">
|
||||||
{% trans 'Create one' %}
|
{% trans 'Upload with Web Form' %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -4,7 +4,8 @@ from dashboard import views
|
||||||
app_name = 'dashboard'
|
app_name = 'dashboard'
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.UnassignedDevicesView.as_view(), name="unassigned_devices"),
|
path("", views.UnassignedDevicesView.as_view(), name="unassigned"),
|
||||||
|
path("all", views.AllDevicesView.as_view(), name="all_device"),
|
||||||
path("<int:pk>/", views.LotDashboardView.as_view(), name="lot"),
|
path("<int:pk>/", views.LotDashboardView.as_view(), name="lot"),
|
||||||
path("search", views.SearchView.as_view(), name="search"),
|
path("search", views.SearchView.as_view(), name="search"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -22,6 +22,16 @@ class UnassignedDevicesView(InventaryMixin):
|
||||||
return Device.get_unassigned(self.request.user.institution, offset, limit)
|
return Device.get_unassigned(self.request.user.institution, offset, limit)
|
||||||
|
|
||||||
|
|
||||||
|
class AllDevicesView(InventaryMixin):
|
||||||
|
template_name = "unassigned_devices.html"
|
||||||
|
section = "All"
|
||||||
|
title = _("All Devices")
|
||||||
|
breadcrumb = "Devices / All Devices"
|
||||||
|
|
||||||
|
def get_devices(self, user, offset, limit):
|
||||||
|
return Device.get_all(self.request.user.institution, offset, limit)
|
||||||
|
|
||||||
|
|
||||||
class LotDashboardView(InventaryMixin, DetailsMixin):
|
class LotDashboardView(InventaryMixin, DetailsMixin):
|
||||||
template_name = "unassigned_devices.html"
|
template_name = "unassigned_devices.html"
|
||||||
section = "dashboard_lot"
|
section = "dashboard_lot"
|
||||||
|
|
|
@ -136,6 +136,85 @@ class Device:
|
||||||
self.lots = [
|
self.lots = [
|
||||||
x.lot for x in DeviceLot.objects.filter(device_id=self.id)]
|
x.lot for x in DeviceLot.objects.filter(device_id=self.id)]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_all(cls, institution, offset=0, limit=None):
|
||||||
|
sql = """
|
||||||
|
WITH RankedProperties AS (
|
||||||
|
SELECT
|
||||||
|
t1.value,
|
||||||
|
t1.key,
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
|
PARTITION BY t1.uuid
|
||||||
|
ORDER BY
|
||||||
|
CASE
|
||||||
|
WHEN t1.key = 'CUSTOM_ID' THEN 1
|
||||||
|
WHEN t1.key = 'ereuse24' THEN 2
|
||||||
|
ELSE 3
|
||||||
|
END,
|
||||||
|
t1.created DESC
|
||||||
|
) AS row_num
|
||||||
|
FROM evidence_systemproperty AS t1
|
||||||
|
WHERE t1.owner_id = {institution}
|
||||||
|
)
|
||||||
|
SELECT DISTINCT
|
||||||
|
value
|
||||||
|
FROM
|
||||||
|
RankedProperties
|
||||||
|
WHERE
|
||||||
|
row_num = 1
|
||||||
|
""".format(
|
||||||
|
institution=institution.id,
|
||||||
|
)
|
||||||
|
if limit:
|
||||||
|
sql += " limit {} offset {}".format(int(limit), int(offset))
|
||||||
|
|
||||||
|
sql += ";"
|
||||||
|
|
||||||
|
annotations = []
|
||||||
|
with connection.cursor() as cursor:
|
||||||
|
cursor.execute(sql)
|
||||||
|
annotations = cursor.fetchall()
|
||||||
|
|
||||||
|
devices = [cls(id=x[0]) for x in annotations]
|
||||||
|
count = cls.get_all_count(institution)
|
||||||
|
return devices, count
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_all_count(cls, institution):
|
||||||
|
|
||||||
|
sql = """
|
||||||
|
WITH RankedProperties AS (
|
||||||
|
SELECT
|
||||||
|
t1.value,
|
||||||
|
t1.key,
|
||||||
|
ROW_NUMBER() OVER (
|
||||||
|
PARTITION BY t1.uuid
|
||||||
|
ORDER BY
|
||||||
|
CASE
|
||||||
|
WHEN t1.key = 'CUSTOM_ID' THEN 1
|
||||||
|
WHEN t1.key = 'ereuse24' THEN 2
|
||||||
|
ELSE 3
|
||||||
|
END,
|
||||||
|
t1.created DESC
|
||||||
|
) AS row_num
|
||||||
|
|
||||||
|
FROM evidence_systemproperty AS t1
|
||||||
|
WHERE t1.owner_id = {institution}
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
COUNT(DISTINCT value)
|
||||||
|
FROM
|
||||||
|
RankedProperties
|
||||||
|
WHERE
|
||||||
|
row_num = 1
|
||||||
|
""".format(
|
||||||
|
institution=institution.id
|
||||||
|
)
|
||||||
|
with connection.cursor() as cursor:
|
||||||
|
cursor.execute(sql)
|
||||||
|
return cursor.fetchall()[0][0]
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_unassigned(cls, institution, offset=0, limit=None):
|
def get_unassigned(cls, institution, offset=0, limit=None):
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
<a class="btn btn-grey" href="{% url 'dashboard:unassigned' %}">{% translate "Cancel" %}</a>
|
||||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class NewDeviceView(DashboardView, FormView):
|
||||||
template_name = "new_device.html"
|
template_name = "new_device.html"
|
||||||
title = _("New Device")
|
title = _("New Device")
|
||||||
breadcrumb = "Device / New Device"
|
breadcrumb = "Device / New Device"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('dashboard:unassigned')
|
||||||
form_class = DeviceFormSet
|
form_class = DeviceFormSet
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
{% bootstrap_form form alert_error_type="none" error_css_class="alert alert-danger alert-icon alert-icon-border" %}
|
{% bootstrap_form form alert_error_type="none" error_css_class="alert alert-danger alert-icon alert-icon-border" %}
|
||||||
<div class="form-actions-no-box">
|
<div class="form-actions-no-box">
|
||||||
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
<a class="btn btn-grey" href="{% url 'dashboard:unassigned' %}">{% translate "Cancel" %}</a>
|
||||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -17,17 +17,17 @@ class LoginView(auth_views.LoginView):
|
||||||
template_name = 'login.html'
|
template_name = 'login.html'
|
||||||
extra_context = {
|
extra_context = {
|
||||||
'title': _('Login'),
|
'title': _('Login'),
|
||||||
'success_url': reverse_lazy('dashboard:unassigned_devices'),
|
'success_url': reverse_lazy('dashboard:unassigned'),
|
||||||
'commit_id': settings.COMMIT,
|
'commit_id': settings.COMMIT,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.extra_context['success_url'] = request.GET.get(
|
self.extra_context['success_url'] = request.GET.get(
|
||||||
'next',
|
'next',
|
||||||
reverse_lazy('dashboard:unassigned_devices')
|
reverse_lazy('dashboard:unassigned')
|
||||||
)
|
)
|
||||||
if not self.request.user.is_anonymous:
|
if not self.request.user.is_anonymous:
|
||||||
return redirect(reverse_lazy('dashboard:unassigned_devices'))
|
return redirect(reverse_lazy('dashboard:unassigned'))
|
||||||
|
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -72,4 +72,3 @@ class PasswordResetView(auth_views.PasswordResetView):
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
return HttpResponseRedirect(self.success_url)
|
return HttpResponseRedirect(self.success_url)
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% bootstrap_form form %}
|
{% bootstrap_form form %}
|
||||||
<div class="form-actions-no-box">
|
<div class="form-actions-no-box">
|
||||||
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
<a class="btn btn-grey" href="{% url 'dashboard:unassigned' %}">{% translate "Cancel" %}</a>
|
||||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Delete' %}" />
|
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Delete' %}" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% bootstrap_form form %}
|
{% bootstrap_form form %}
|
||||||
<div class="form-actions-no-box">
|
<div class="form-actions-no-box">
|
||||||
<a class="btn btn-grey" href="{% url 'dashboard:unassigned_devices' %}">{% translate "Cancel" %}</a>
|
<a class="btn btn-grey" href="{% url 'dashboard:unassigned' %}">{% translate "Cancel" %}</a>
|
||||||
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ urlpatterns = [
|
||||||
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("tag/<int:pk>/", views.LotsTagsView.as_view(), name="tag"),
|
path("tag/<int:pk>/", views.LotsTagsView.as_view(), name="tags"),
|
||||||
path("<int:pk>/property", views.LotPropertiesView.as_view(), name="properties"),
|
path("<int:pk>/property", views.LotPropertiesView.as_view(), name="properties"),
|
||||||
path("<int:pk>/property/add", views.AddLotPropertyView.as_view(), name="add_property"),
|
path("<int:pk>/property/add", views.AddLotPropertyView.as_view(), name="add_property"),
|
||||||
path("<int:pk>/property/update", views.UpdateLotPropertyView.as_view(), name="update_property"),
|
path("<int:pk>/property/update", views.UpdateLotPropertyView.as_view(), name="update_property"),
|
||||||
|
|
10
lot/views.py
10
lot/views.py
|
@ -18,7 +18,7 @@ class NewLotView(DashboardView, CreateView):
|
||||||
template_name = "new_lot.html"
|
template_name = "new_lot.html"
|
||||||
title = _("New lot")
|
title = _("New lot")
|
||||||
breadcrumb = "lot / New lot"
|
breadcrumb = "lot / New lot"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('dashboard:unassigned')
|
||||||
model = Lot
|
model = Lot
|
||||||
fields = (
|
fields = (
|
||||||
"type",
|
"type",
|
||||||
|
@ -39,7 +39,7 @@ class DeleteLotView(DashboardView, DeleteView):
|
||||||
template_name = "delete_lot.html"
|
template_name = "delete_lot.html"
|
||||||
title = _("Delete lot")
|
title = _("Delete lot")
|
||||||
breadcrumb = "lot / Delete lot"
|
breadcrumb = "lot / Delete lot"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('dashboard:unassigned')
|
||||||
model = Lot
|
model = Lot
|
||||||
fields = (
|
fields = (
|
||||||
"type",
|
"type",
|
||||||
|
@ -58,7 +58,7 @@ class EditLotView(DashboardView, UpdateView):
|
||||||
template_name = "new_lot.html"
|
template_name = "new_lot.html"
|
||||||
title = _("Edit lot")
|
title = _("Edit lot")
|
||||||
breadcrumb = "Lot / Edit lot"
|
breadcrumb = "Lot / Edit lot"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('dashboard:unassigned')
|
||||||
model = Lot
|
model = Lot
|
||||||
fields = (
|
fields = (
|
||||||
"type",
|
"type",
|
||||||
|
@ -84,7 +84,7 @@ class AddToLotView(DashboardView, FormView):
|
||||||
template_name = "list_lots.html"
|
template_name = "list_lots.html"
|
||||||
title = _("Add to lots")
|
title = _("Add to lots")
|
||||||
breadcrumb = "lot / add to lots"
|
breadcrumb = "lot / add to lots"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('dashboard:unassigned')
|
||||||
form_class = LotsForm
|
form_class = LotsForm
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
@ -125,7 +125,7 @@ class LotsTagsView(DashboardView, TemplateView):
|
||||||
template_name = "lots.html"
|
template_name = "lots.html"
|
||||||
title = _("lots")
|
title = _("lots")
|
||||||
breadcrumb = _("lots") + " /"
|
breadcrumb = _("lots") + " /"
|
||||||
success_url = reverse_lazy('dashboard:unassigned_devices')
|
success_url = reverse_lazy('dashboard:unassigned')
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
self.pk = kwargs.get('pk')
|
self.pk = kwargs.get('pk')
|
||||||
|
|
Loading…
Reference in a new issue