moved table to a different file
This commit is contained in:
parent
31feb18024
commit
25d28bdc96
90
lot/tables.py
Normal file
90
lot/tables.py
Normal file
|
@ -0,0 +1,90 @@
|
|||
import django_tables2 as tables
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from lot.models import Lot
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
class LotTable(tables.Table):
|
||||
select = tables.CheckBoxColumn(
|
||||
accessor='id',
|
||||
attrs={
|
||||
'th__input': {
|
||||
'id': 'select-all',
|
||||
'class': 'form-check-input'
|
||||
},
|
||||
'td__input': {
|
||||
'class': 'select-checkbox form-check-input'
|
||||
},
|
||||
'th': {'class': 'text-center'},
|
||||
'td': {'class': 'text-center'}
|
||||
},
|
||||
orderable=False
|
||||
)
|
||||
name = tables.Column(
|
||||
linkify=("dashboard:lot", {"pk": tables.A("id")}),
|
||||
verbose_name=_("Lot Name"),
|
||||
attrs={
|
||||
'th': {'class': 'text-start'},
|
||||
'td': {'class': 'fw-bold text-start'}
|
||||
}
|
||||
)
|
||||
description = tables.Column(
|
||||
verbose_name=_("Description"),
|
||||
default=_("No description"),
|
||||
attrs={
|
||||
'th': {'class': 'text-start'},
|
||||
'td': {'class': 'text-muted text-start'}
|
||||
}
|
||||
)
|
||||
archived = tables.Column(
|
||||
verbose_name=_("Status"),
|
||||
attrs={
|
||||
'th': {'class': 'text-center'},
|
||||
'td': {'class': 'text-center'}
|
||||
}
|
||||
)
|
||||
device_count = tables.Column(
|
||||
verbose_name=_("Devices"),
|
||||
accessor='device_count',
|
||||
attrs={
|
||||
'th': {'class': 'text-center'},
|
||||
'td': {'class': 'text-center'}
|
||||
}
|
||||
)
|
||||
created = tables.DateColumn(
|
||||
format="Y-m-d",
|
||||
verbose_name=_("Created On"),
|
||||
attrs={
|
||||
'th': {'class': 'text-end'},
|
||||
'td': {'class': 'text-end'}
|
||||
}
|
||||
)
|
||||
user = tables.Column(
|
||||
verbose_name=_("Created By"),
|
||||
default=_("Unknown"),
|
||||
attrs={
|
||||
'th': {'class': 'text-end'},
|
||||
'td': {'class': 'text-muted text-end'}
|
||||
}
|
||||
)
|
||||
actions = tables.TemplateColumn(
|
||||
template_name="lot_actions.html",
|
||||
verbose_name=_(""),
|
||||
attrs={
|
||||
'th': {'class': 'text-end'},
|
||||
'td': {'class': 'text-end'}
|
||||
}
|
||||
)
|
||||
|
||||
def render_archived(self, value):
|
||||
if value:
|
||||
return mark_safe('<span class="badge bg-warning"><i class="bi bi-archive-fill"></i></span>')
|
||||
return mark_safe('<span class="badge bg-success"><i class="bi bi-folder-fill"></i></span>')
|
||||
|
||||
class Meta:
|
||||
model = Lot
|
||||
fields = ("select", "archived", "name", "description", "device_count", "created", "user", "actions")
|
||||
attrs = {
|
||||
"class": "table table-hover align-middle",
|
||||
"thead": {"class": "table-light"}
|
||||
}
|
||||
order_by = ("-created",)
|
96
lot/views.py
96
lot/views.py
|
@ -4,7 +4,6 @@ from django.shortcuts import get_object_or_404, redirect, Http404, render
|
|||
from django.contrib import messages
|
||||
from django.core.cache import cache
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.db.models import Q, Count, Case, When, IntegerField
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import (
|
||||
|
@ -13,8 +12,9 @@ from django.views.generic.edit import (
|
|||
UpdateView,
|
||||
FormView,
|
||||
)
|
||||
import django_tables2 as tables
|
||||
from django_tables2 import SingleTableView
|
||||
from dashboard.mixins import DashboardView
|
||||
from lot.tables import LotTable
|
||||
from lot.models import Lot, LotTag, LotProperty
|
||||
from lot.forms import LotsForm
|
||||
|
||||
|
@ -38,6 +38,7 @@ class LotSuccessUrlMixin():
|
|||
except LotTag.DoesNotExist:
|
||||
return self.success_url
|
||||
|
||||
|
||||
class NewLotView(LotSuccessUrlMixin, DashboardView, CreateView):
|
||||
template_name = "new_lot.html"
|
||||
title = _("New lot")
|
||||
|
@ -63,8 +64,8 @@ class NewLotView(LotSuccessUrlMixin, DashboardView, CreateView):
|
|||
try:
|
||||
form.instance.owner = self.request.user.institution
|
||||
form.instance.user = self.request.user
|
||||
messages.success(self.request, _("Lot created successfully."))
|
||||
response = super().form_valid(form)
|
||||
messages.success(self.request, _("Lot created successfully."))
|
||||
return response
|
||||
|
||||
except IntegrityError:
|
||||
|
@ -191,94 +192,7 @@ class DelToLotView(AddToLotView):
|
|||
return response
|
||||
|
||||
|
||||
class LotTable(tables.Table):
|
||||
select = tables.CheckBoxColumn(
|
||||
accessor='id',
|
||||
attrs={
|
||||
'th__input': {
|
||||
'id': 'select-all',
|
||||
'class': 'form-check-input'
|
||||
},
|
||||
'td__input': {
|
||||
'class': 'select-checkbox form-check-input'
|
||||
},
|
||||
'th': {'class': 'text-center'},
|
||||
'td': {'class': 'text-center'}
|
||||
},
|
||||
orderable=False
|
||||
)
|
||||
name = tables.Column(
|
||||
linkify=("dashboard:lot", {"pk": tables.A("id")}),
|
||||
verbose_name=_("Lot Name"),
|
||||
attrs={
|
||||
'th': {'class': 'text-start'},
|
||||
'td': {'class': 'fw-bold text-start'}
|
||||
}
|
||||
)
|
||||
description = tables.Column(
|
||||
verbose_name=_("Description"),
|
||||
default=_("No description"),
|
||||
attrs={
|
||||
'th': {'class': 'text-start'},
|
||||
'td': {'class': 'text-muted text-start'}
|
||||
}
|
||||
)
|
||||
archived = tables.Column(
|
||||
verbose_name=_("Status"),
|
||||
attrs={
|
||||
'th': {'class': 'text-center'},
|
||||
'td': {'class': 'text-center'}
|
||||
}
|
||||
)
|
||||
device_count = tables.Column(
|
||||
verbose_name=_("Devices"),
|
||||
accessor='device_count',
|
||||
attrs={
|
||||
'th': {'class': 'text-center'},
|
||||
'td': {'class': 'text-center'}
|
||||
}
|
||||
)
|
||||
created = tables.DateColumn(
|
||||
format="Y-m-d",
|
||||
verbose_name=_("Created On"),
|
||||
attrs={
|
||||
'th': {'class': 'text-end'},
|
||||
'td': {'class': 'text-end'}
|
||||
}
|
||||
)
|
||||
user = tables.Column(
|
||||
verbose_name=_("Created By"),
|
||||
default=_("Unknown"),
|
||||
attrs={
|
||||
'th': {'class': 'text-end'},
|
||||
'td': {'class': 'text-muted text-end'}
|
||||
}
|
||||
)
|
||||
actions = tables.TemplateColumn(
|
||||
template_name="lot_actions.html",
|
||||
verbose_name=_(""),
|
||||
attrs={
|
||||
'th': {'class': 'text-end'},
|
||||
'td': {'class': 'text-end'}
|
||||
}
|
||||
)
|
||||
|
||||
def render_archived(self, value):
|
||||
if value:
|
||||
return mark_safe('<span class="badge bg-warning"><i class="bi bi-archive-fill"></i></span>')
|
||||
return mark_safe('<span class="badge bg-success"><i class="bi bi-folder-fill"></i></span>')
|
||||
|
||||
class Meta:
|
||||
model = Lot
|
||||
fields = ("select", "archived", "name", "description", "device_count", "created", "user", "actions")
|
||||
attrs = {
|
||||
"class": "table table-hover align-middle",
|
||||
"thead": {"class": "table-light"}
|
||||
}
|
||||
order_by = ("-created",)
|
||||
|
||||
|
||||
class LotsTagsView(DashboardView, tables.SingleTableView):
|
||||
class LotsTagsView(DashboardView, SingleTableView):
|
||||
template_name = "lots.html"
|
||||
title = _("Lot group")
|
||||
breadcrumb = _("lots") + " /"
|
||||
|
|
Loading…
Reference in a new issue