add Inbox lotTag as unassigned section
This commit is contained in:
parent
18204d2e4f
commit
5fdaeb690a
|
@ -14,7 +14,7 @@
|
|||
</div>
|
||||
<div class="row mt-4">
|
||||
<div class="col">
|
||||
{% if lot_tags %}
|
||||
{% if lot_tags_edit %}
|
||||
<table class="table table-hover table-bordered align-middle">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
|
@ -25,7 +25,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody id="sortable_list">
|
||||
{% for tag in lot_tags %}
|
||||
{% for tag in lot_tags_edit %}
|
||||
<tr>
|
||||
<td class="font-monospace">
|
||||
{{ tag.name }}
|
||||
|
@ -93,7 +93,7 @@
|
|||
</div>
|
||||
|
||||
<!-- Edit Lot Tag Modals -->
|
||||
{% for tag in lot_tags %}
|
||||
{% for tag in lot_tags_edit %}
|
||||
<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">
|
||||
|
@ -125,7 +125,7 @@
|
|||
|
||||
|
||||
<!-- delete lot tag definition Modal -->
|
||||
{% for tag in lot_tags %}
|
||||
{% for tag in lot_tags_edit %}
|
||||
<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">
|
||||
|
|
|
@ -118,6 +118,14 @@ class LotTagPanelView(AdminView, TemplateView):
|
|||
title = _("Lot Tag Panel")
|
||||
breadcrumb = _("admin / Lot Tag Panel")
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
lot_tags = LotTag.objects.filter(
|
||||
owner=self.request.user.institution
|
||||
)
|
||||
context.update({"lot_tags_edit": lot_tags})
|
||||
return context
|
||||
|
||||
|
||||
class AddLotTagView(AdminView, CreateView):
|
||||
template_name = "lot_tag_panel.html"
|
||||
|
@ -130,6 +138,11 @@ class AddLotTagView(AdminView, CreateView):
|
|||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
name = form.instance.name
|
||||
if LotTag.objects.filter(name=name).first():
|
||||
msg = _(f"The name '{name}' exist.")
|
||||
messages.error(self.request, msg)
|
||||
return redirect(self.success_url)
|
||||
|
||||
response = super().form_valid(form)
|
||||
messages.success(self.request, _("Lot Tag successfully added."))
|
||||
|
@ -153,6 +166,12 @@ class DeleteLotTagView(AdminView, DeleteView):
|
|||
messages.warning(self.request, msg)
|
||||
return redirect(reverse_lazy('admin:tag_panel'))
|
||||
|
||||
if self.object.inbox:
|
||||
msg = f"The tag '{self.object.name}'"
|
||||
msg += " is a inbox, you can redefine but not delete."
|
||||
messages.error(self.request, msg)
|
||||
return redirect(self.success_url)
|
||||
|
||||
response = super().delete(request, *args, **kwargs)
|
||||
msg = _('Lot Tag has been deleted.')
|
||||
messages.success(self.request, msg)
|
||||
|
@ -175,6 +194,12 @@ class UpdateLotTagView(AdminView, UpdateView):
|
|||
return super().get_form_kwargs()
|
||||
|
||||
def form_valid(self, form):
|
||||
name = form.instance.name
|
||||
if LotTag.objects.filter(name=name).first():
|
||||
msg = _(f"The name '{name}' exist.")
|
||||
messages.error(self.request, msg)
|
||||
return redirect(self.success_url)
|
||||
|
||||
response = super().form_valid(form)
|
||||
msg = _("Lot Tag updated successfully.")
|
||||
messages.success(self.request, msg)
|
||||
|
@ -249,14 +274,11 @@ class DeleteStateDefinitionView(AdminView, StateDefinitionContextMixin, SuccessM
|
|||
def get_success_message(self, cleaned_data):
|
||||
return f'State definition: {self.object.state}, has been deleted'
|
||||
|
||||
def delete(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
#only an admin of current institution can delete
|
||||
if not object.institution == self.request.user.institution:
|
||||
def form_valid(self, form):
|
||||
if not self.object.institution == self.request.user.institution:
|
||||
raise Http404
|
||||
|
||||
return super().delete(request, *args, **kwargs)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class UpdateStateOrderView(AdminView, TemplateView):
|
||||
|
|
|
@ -8,6 +8,7 @@ from django.views.generic.base import TemplateView
|
|||
from device.models import Device
|
||||
from evidence.models import SystemProperty
|
||||
from lot.models import LotTag
|
||||
from action.models import StateDefinition
|
||||
|
||||
|
||||
class Http403(PermissionDenied):
|
||||
|
@ -32,7 +33,12 @@ class DashboardView(LoginRequiredMixin):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
lot_tags = LotTag.objects.filter(
|
||||
owner=self.request.user.institution,
|
||||
inbox=False
|
||||
)
|
||||
context.update({
|
||||
"inbox": LotTag.objects.get(inbox=True).name,
|
||||
"commit_id": settings.COMMIT,
|
||||
'title': self.title,
|
||||
'subtitle': self.subtitle,
|
||||
|
@ -41,7 +47,7 @@ class DashboardView(LoginRequiredMixin):
|
|||
'section': self.section,
|
||||
'path': resolve(self.request.path).url_name,
|
||||
'user': self.request.user,
|
||||
'lot_tags': LotTag.objects.filter(owner=self.request.user.institution)
|
||||
'lot_tags': lot_tags
|
||||
})
|
||||
return context
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@
|
|||
<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' %}
|
||||
{{ inbox }}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
|
18
lot/migrations/0007_lottag_inbox.py
Normal file
18
lot/migrations/0007_lottag_inbox.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 5.0.6 on 2025-02-17 10:47
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('lot', '0006_lotproperty_property_unique_type_key_lot'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='lottag',
|
||||
name='inbox',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
]
|
|
@ -15,6 +15,7 @@ class LotTag(models.Model):
|
|||
name = models.CharField(max_length=STR_SIZE, blank=False, null=False)
|
||||
owner = models.ForeignKey(Institution, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)
|
||||
inbox = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
|
@ -28,6 +28,14 @@ class NewLotView(DashboardView, CreateView):
|
|||
"closed",
|
||||
)
|
||||
|
||||
def get_form(self):
|
||||
form = super().get_form()
|
||||
form.fields["type"].queryset = LotTag.objects.filter(
|
||||
owner=self.request.user.institution,
|
||||
inbox=False
|
||||
)
|
||||
return form
|
||||
|
||||
def form_valid(self, form):
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
|
|
|
@ -2,6 +2,7 @@ from django.core.management.base import BaseCommand
|
|||
from user.models import Institution
|
||||
from lot.models import LotTag
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Create a new Institution"
|
||||
|
||||
|
@ -13,6 +14,11 @@ class Command(BaseCommand):
|
|||
self.create_lot_tags()
|
||||
|
||||
def create_lot_tags(self):
|
||||
LotTag.objects.create(
|
||||
inbox=True,
|
||||
name="Inbox",
|
||||
owner=self.institution
|
||||
)
|
||||
tags = [
|
||||
"Entrada",
|
||||
"Salida",
|
||||
|
|
Loading…
Reference in a new issue