[UPDT] ASSET: Change existing style to the latest style
This commit is contained in:
68
asset/cbv/asset.py
Normal file
68
asset/cbv/asset.py
Normal file
@@ -0,0 +1,68 @@
|
||||
from typing import Any
|
||||
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from horilla_views.cbv_methods import login_required, permission_required
|
||||
from horilla_views.generic.cbv.views import HorillaDetailedView, HorillaListView
|
||||
|
||||
from asset.filters import AssetFilter
|
||||
from asset.models import Asset
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@method_decorator(permission_required("asset.view_assetlot"), name="dispatch")
|
||||
class AssetListView(HorillaListView):
|
||||
"""
|
||||
list view for batch number
|
||||
"""
|
||||
|
||||
model = Asset
|
||||
filter_class = AssetFilter
|
||||
columns = ["asset_name", "asset_status", "asset_tracking_id", "asset_lot_number_id"]
|
||||
show_filter_tags = False
|
||||
bulk_select_option = False
|
||||
action_method = "action_column"
|
||||
header_attrs = {"asset_name": "style='width:200px !important;'"}
|
||||
|
||||
def get_queryset(self, queryset=None, filtered=False, *args, **kwargs):
|
||||
return (
|
||||
super()
|
||||
.get_queryset(queryset, filtered, *args, **kwargs)
|
||||
.filter(asset_category_id=self.kwargs["cat_id"])
|
||||
)
|
||||
|
||||
row_attrs = """
|
||||
hx-get='{asset_detail}?instance_ids={ordered_ids}'
|
||||
hx-target="#genericModalBody"
|
||||
data-target="#genericModal"
|
||||
data-toggle="oh-modal-toggle"
|
||||
"""
|
||||
|
||||
|
||||
class AssetInformationView(HorillaDetailedView):
|
||||
"""
|
||||
Detail view of the page
|
||||
"""
|
||||
|
||||
def get_context_data(self, **kwargs: Any):
|
||||
"""
|
||||
Return context data with the title set to the contract's name.
|
||||
"""
|
||||
|
||||
context = super().get_context_data(**kwargs)
|
||||
asset_name = context["asset"].asset_name
|
||||
context["title"] = asset_name
|
||||
return context
|
||||
|
||||
model = Asset
|
||||
header = False
|
||||
action_method = "detail_view_action"
|
||||
body = [
|
||||
"asset_tracking_id",
|
||||
"asset_purchase_date",
|
||||
"asset_purchase_cost",
|
||||
"asset_status",
|
||||
"asset_lot_number_id",
|
||||
"asset_category_id",
|
||||
]
|
||||
@@ -40,34 +40,33 @@ class AssetBatchNoListView(HorillaListView):
|
||||
list view for batch number
|
||||
"""
|
||||
|
||||
model = AssetLot
|
||||
filter_class = AssetBatchNoFilter
|
||||
columns = [
|
||||
"lot_number",
|
||||
"lot_description",
|
||||
(_("Assets"), "assets_column"),
|
||||
]
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.search_url = reverse("asset-batch-list")
|
||||
self.view_id = "AssetBatchList"
|
||||
|
||||
model = AssetLot
|
||||
filter_class = AssetBatchNoFilter
|
||||
|
||||
columns = [
|
||||
(_("Batch Number"), "lot_number"),
|
||||
(_("Description"), "lot_description"),
|
||||
(_("Assets"), "assets_column"),
|
||||
]
|
||||
|
||||
header_attrs = {
|
||||
"action": """
|
||||
style = "width:180px !important"
|
||||
"""
|
||||
style = "width:180px !important"
|
||||
"""
|
||||
}
|
||||
|
||||
action_method = "actions"
|
||||
|
||||
row_attrs = """
|
||||
hx-get='{asset_batch_detail}?instance_ids={ordered_ids}'
|
||||
hx-target="#genericModalBody"
|
||||
data-target="#genericModal"
|
||||
data-toggle="oh-modal-toggle"
|
||||
"""
|
||||
hx-get='{asset_batch_detail}?instance_ids={ordered_ids}'
|
||||
hx-target="#genericModalBody"
|
||||
data-target="#genericModal"
|
||||
data-toggle="oh-modal-toggle"
|
||||
"""
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@@ -77,21 +76,21 @@ class AssetBatchNoNav(HorillaNavView):
|
||||
Nav bar
|
||||
"""
|
||||
|
||||
nav_title = _("Asset Batch Number")
|
||||
filter_instance = AssetBatchNoFilter()
|
||||
search_swap_target = "#listContainer"
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.search_url = reverse("asset-batch-list")
|
||||
|
||||
if self.request.user.has_perm("asset.view_assetlot"):
|
||||
self.create_attrs = f"""
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#genericModal"
|
||||
hx-target="#genericModalBody"
|
||||
hx-get="{reverse('asset-batch-number-creation')}"
|
||||
"""
|
||||
|
||||
nav_title = _("Asset Batch Number")
|
||||
filter_instance = AssetBatchNoFilter()
|
||||
search_swap_target = "#listContainer"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#genericModal"
|
||||
hx-target="#genericModalBody"
|
||||
hx-get="{reverse('asset-batch-number-creation')}"
|
||||
"""
|
||||
|
||||
|
||||
@method_decorator(login_required, name="dispatch")
|
||||
@@ -139,46 +138,8 @@ class AssetBatchDetailView(HorillaDetailedView):
|
||||
detail view of the page
|
||||
"""
|
||||
|
||||
def get_context_data(self, **kwargs: Any):
|
||||
"""
|
||||
Return context data with the title set to the contract's name.
|
||||
"""
|
||||
|
||||
context = super().get_context_data(**kwargs)
|
||||
lot_number = context["assetlot"].lot_number
|
||||
context["title"] = "Asset Batch:" + lot_number
|
||||
return context
|
||||
|
||||
model = AssetLot
|
||||
title = _("Details")
|
||||
header = False
|
||||
|
||||
cols = {"assets_column": 12, "lot_description": 12, "lot_number": 12}
|
||||
body = {
|
||||
(_("Assets"), "assets_column"),
|
||||
(_("Description"), "lot_description"),
|
||||
(_("Batch Number"), "lot_number"),
|
||||
}
|
||||
|
||||
actions = [
|
||||
{
|
||||
"action": _("Edit"),
|
||||
"icon": "create-outline",
|
||||
"attrs": """
|
||||
class="oh-btn oh-btn--info w-100"
|
||||
hx-get='{get_update_url}?instance_ids={ordered_ids}'
|
||||
hx-target="#genericModalBody"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#genericModal"
|
||||
""",
|
||||
},
|
||||
{
|
||||
"action": _("Delete"),
|
||||
"icon": "trash-outline",
|
||||
"attrs": """
|
||||
class="oh-btn oh-btn--danger w-100"
|
||||
hx-confirm="Do you want to delete this batch number?"
|
||||
hx-post="{get_delete_url}?instance_ids={ordered_ids}"
|
||||
hx-target="#AssetBatchList"
|
||||
""",
|
||||
},
|
||||
]
|
||||
model = AssetLot
|
||||
body = ["lot_number", (_("Asset"), "assets_column"), "lot_description"]
|
||||
action_method = "detail_actions"
|
||||
|
||||
@@ -208,97 +208,51 @@ class AssetReportFormView(HorillaFormView):
|
||||
@method_decorator(permission_required("asset.view_asset"), name="dispatch")
|
||||
class AssetCategoryNav(HorillaNavView):
|
||||
"""
|
||||
nav bar
|
||||
nav bar for asset category
|
||||
"""
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.search_url = reverse("asset-category-view-search-filter")
|
||||
self.create_attrs = f"""
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#genericModal"
|
||||
hx-get="{reverse('asset-category-creation')}"
|
||||
hx-target="#genericModalBody"
|
||||
"""
|
||||
# if self.request.user.has_perm(
|
||||
# "attendance.add_attendanceovertime"
|
||||
# ) or is_reportingmanager(self.request):
|
||||
|
||||
# self.actions = [
|
||||
# {
|
||||
# "action": _("Import"),
|
||||
# "attrs": """
|
||||
# onclick="
|
||||
# reqAttendanceBulkApprove();
|
||||
# "
|
||||
# style="cursor: pointer;"
|
||||
# """,
|
||||
# },
|
||||
# {
|
||||
# "action": _("Export"),
|
||||
# "attrs": """
|
||||
# onclick="reqAttendanceBulkReject();"
|
||||
# style="color:red !important"
|
||||
# """,
|
||||
# },
|
||||
# ]
|
||||
# else:
|
||||
# self.actions = None
|
||||
|
||||
nav_title = _("Asset Category")
|
||||
filter_body_template = "cbv/asset_category/filter.html"
|
||||
filter_instance = AssetFilter()
|
||||
filter_form_context_name = "form"
|
||||
search_swap_target = "#assetCategoryList"
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.search_url = reverse("asset-category-view-search-filter")
|
||||
self.actions = []
|
||||
if self.request.user.has_perm("add_assetcategory"):
|
||||
self.create_attrs = f"""
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#genericModal"
|
||||
hx-get="{reverse('asset-category-creation')}"
|
||||
hx-target="#genericModalBody"
|
||||
"""
|
||||
if self.request.user.has_perm("add_assetcategory"):
|
||||
self.actions.append(
|
||||
{
|
||||
"action": _("Import"),
|
||||
"attrs": f"""
|
||||
onclick="getAssetImportTemplate();"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#objectCreateModal"
|
||||
hx-get="{reverse('asset-import')}"
|
||||
hx-target="#objectCreateModalTarget"
|
||||
style="cursor: pointer;"
|
||||
""",
|
||||
},
|
||||
)
|
||||
|
||||
class AssetCategoryDetailView(HorillaDetailedView):
|
||||
"""
|
||||
Detail view of the page
|
||||
"""
|
||||
|
||||
def get_context_data(self, **kwargs: Any):
|
||||
"""
|
||||
Return context data with the title set to the contract's name.
|
||||
"""
|
||||
|
||||
context = super().get_context_data(**kwargs)
|
||||
asset_name = context["asset"].asset_name
|
||||
context["title"] = asset_name
|
||||
return context
|
||||
|
||||
model = Asset
|
||||
header = False
|
||||
template_name = "cbv/asset_category/detail_view_action.html"
|
||||
body = [
|
||||
(_("Tracking Id"), "asset_tracking_id"),
|
||||
(_("Purchase Date"), "asset_purchase_date"),
|
||||
(_("Cost"), "asset_purchase_cost"),
|
||||
(_("Status"), "get_status_display"),
|
||||
(_("Batch No"), "asset_lot_number_id__lot_number"),
|
||||
(_("Category"), "asset_category_id"),
|
||||
]
|
||||
|
||||
actions = [
|
||||
{
|
||||
"action": _("Edit"),
|
||||
"icon": "create-outline",
|
||||
"attrs": """
|
||||
class="oh-btn oh-btn--info w-100"
|
||||
hx-get='{get_update_url}?instance_ids={ordered_ids}'
|
||||
hx-target="#genericModalBody"
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#genericModal"
|
||||
""",
|
||||
},
|
||||
{
|
||||
"action": _("Delete"),
|
||||
"icon": "trash-outline",
|
||||
"attrs": """
|
||||
class="oh-btn oh-btn--danger w-100"
|
||||
hx-confirm="Do you want to delete this asset?"
|
||||
hx-post="{get_delete_url}?instance_ids={ordered_ids}"
|
||||
hx-target="#genericModalBody"
|
||||
if self.request.user.has_perm("view_asset"):
|
||||
self.actions.append(
|
||||
{
|
||||
"action": _("Export"),
|
||||
"attrs": f"""
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#objectCreateModal"
|
||||
hx-get="{reverse('asset-export-excel')}"
|
||||
hx-target="#objectCreateModalTarget"
|
||||
style="cursor: pointer;"
|
||||
""",
|
||||
},
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
@@ -104,6 +104,12 @@ class AssetLot(HorillaModel):
|
||||
context={"instance": self},
|
||||
)
|
||||
|
||||
def detail_actions(self):
|
||||
return render_template(
|
||||
path="cbv/asset_batch_no/detail_actions.html",
|
||||
context={"instance": self},
|
||||
)
|
||||
|
||||
def get_update_url(self):
|
||||
"""
|
||||
This method to get update url
|
||||
@@ -177,11 +183,13 @@ class Asset(HorillaModel):
|
||||
def __str__(self):
|
||||
return f"{self.asset_name}-{self.asset_tracking_id}"
|
||||
|
||||
def get_status_display(self):
|
||||
def action_column(self):
|
||||
"""
|
||||
Display status
|
||||
Action column for asset
|
||||
"""
|
||||
return dict(self.ASSET_STATUS).get(self.asset_status)
|
||||
return render_template(
|
||||
path="asset/action_column.html", context={"instance": self}
|
||||
)
|
||||
|
||||
def detail_view_action(self):
|
||||
"""
|
||||
@@ -189,10 +197,18 @@ class Asset(HorillaModel):
|
||||
"""
|
||||
|
||||
return render_template(
|
||||
path="cbv/asset_category/detail_view_action.html",
|
||||
path="cbv/asset/detail_action.html",
|
||||
context={"instance": self},
|
||||
)
|
||||
|
||||
def asset_detail(self):
|
||||
"""
|
||||
detail view url
|
||||
"""
|
||||
|
||||
url = reverse_lazy("asset-information", kwargs={"pk": self.pk})
|
||||
return url
|
||||
|
||||
def get_update_url(self):
|
||||
"""
|
||||
This method to get update url
|
||||
|
||||
60
asset/templates/asset/action_column.html
Normal file
60
asset/templates/asset/action_column.html
Normal file
@@ -0,0 +1,60 @@
|
||||
{% load static i18n %}
|
||||
<div class="oh-btn-group">
|
||||
{% if perms.asset.change_asset %}
|
||||
{% if asset_under == 'asset_filter' %}
|
||||
<a class="oh-btn oh-btn--light-bkg w-100" data-toggle="oh-modal-toggle" data-target="#objectUpdateModal"
|
||||
hx-get="{{ instance.get_update_url }}?{% if asset_under == 'asset_filter' %}asset_under=asset_filter&{% endif %}{{ pg }}"
|
||||
title="{% trans 'Update' %}" hx-target="#objectUpdateModalTarget" onclick="event.stopPropagation()"
|
||||
id="oh-btn-asset-update-modal">
|
||||
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
</a>
|
||||
{% else %}
|
||||
<a class="oh-btn oh-btn--light-bkg w-100" data-toggle="oh-modal-toggle" data-target="#objectUpdateModal"
|
||||
hx-get="{{ instance.get_update_url }}?{% if asset_under == 'asset_filter' %}asset_under=asset_filter&{% endif %}{{ pg }}" title="{% trans 'Update' %}"
|
||||
hx-target="#objectUpdateModalTarget" onclick="event.stopPropagation()" id="oh-btn-asset-update-modal">
|
||||
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if perms.asset.add_asset %}
|
||||
<a class="oh-btn oh-btn--light-bkg w-100" data-toggle="oh-modal-toggle" data-target="#objectCreateModal"
|
||||
hx-get="{% url 'duplicate-asset' instance.id %}?{{pg}}" hx-target="#objectCreateModalTarget"
|
||||
title="{% trans 'Duplicate' %}" onclick="event.stopPropagation()" style="cursor: pointer">
|
||||
<ion-icon name="copy-outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if asset.assetassignment_set.all %}
|
||||
<a class="oh-btn oh-btn--light-bkg w-100" onclick="event.preventDefault();event.stopPropagation()"
|
||||
data-toggle="oh-modal-toggle" data-target="#dynamicCreateModal"
|
||||
hx-get="{% url 'add-asset-report' instance.id %}?asset_list=true" hx-target="#dynamicCreateModalTarget"
|
||||
id="oh-btn-asset-update-modal" title="{% trans 'Asset Report' %}">
|
||||
<ion-icon name="document-attach-outline"></ion-icon>
|
||||
</a>
|
||||
{% else %}
|
||||
<a class="oh-btn oh-btn--light-bkg w-100 oh-btn--disabled" onclick="event.stopPropagation()"
|
||||
id="oh-btn-asset-update-modal" title="{% trans 'Asset Report' %}">
|
||||
<ion-icon name="document-attach-outline"></ion-icon>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if perms.asset.delete_asset %}
|
||||
{% if asset_under == 'asset_filter' %}
|
||||
<form action="{% url 'asset-delete' instance.id %}?asset_list=asset_filter&{{request.GET.urlencode}}"
|
||||
onsubmit="return confirm('{% trans "Do you want to delete this asset?" %}')" method="post" style="width:100%">
|
||||
{% csrf_token %}
|
||||
<button class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100" onclick="event.stopPropagation()"
|
||||
title="{% trans 'Delete' %}">
|
||||
<ion-icon name="trash-outline" role="img" class="md hydrated" aria-label="trash outline"></ion-icon>
|
||||
</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<form hx-confirm="{% trans 'Do you want to delete this asset?' %}"
|
||||
hx-post="{{instance.get_delete_url}}?{% if asset_under == 'asset_filter' %}asset_under=asset_filter&{% endif %}{{ request.GET.urlencode }}"
|
||||
hx-target="#assetCategory{{asset.asset_category_id.id}}" onclick="event.stopPropagation()" style="width:100%">
|
||||
{% csrf_token %}
|
||||
<button class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-100" title="{% trans 'Delete' %}">
|
||||
<ion-icon name="trash-outline" role="img" class="md hydrated" aria-label="trash outline"></ion-icon>
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
26
asset/templates/cbv/asset/detail_action.html
Normal file
26
asset/templates/cbv/asset/detail_action.html
Normal file
@@ -0,0 +1,26 @@
|
||||
{% load i18n %}
|
||||
{% if perms.asset.change_asset or perms.asset.delete_asset %}
|
||||
<div class="oh-modal__button-container text-center mt-3">
|
||||
<div class="oh-btn-group">
|
||||
{% if perms.asset.change_asset %}
|
||||
<a hx-get="{{ instance.get_update_url }}?instance_ids={{ instance.ordered_ids }}"
|
||||
data-toggle="oh-modal-toggle" data-target="#genericModal" hx-target="#genericModalBody"
|
||||
class="oh-btn oh-btn--info w-100">
|
||||
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
{% trans "Edit" %}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if perms.asset.delete_asset %}
|
||||
<form hx-confirm="{% trans 'Do you want to delete this asset?' %}"
|
||||
hx-post="{{ instance.get_delete_url }}?instance_ids={{ instance.ordered_ids }}"
|
||||
hx-target="#objectDetailsModalTarget" onclick="event.stopPropagation()" class="w-100">
|
||||
{% csrf_token %}
|
||||
<button type='submit' class="oh-btn oh-btn--danger w-100" data-action="delete">
|
||||
<ion-icon name="trash-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
{% trans "Delete" %}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
27
asset/templates/cbv/asset_batch_no/detail_actions.html
Normal file
27
asset/templates/cbv/asset_batch_no/detail_actions.html
Normal file
@@ -0,0 +1,27 @@
|
||||
{% load static i18n %}
|
||||
{% if perms.asset.change_assetlot %}
|
||||
<!-- Start of Edit Button -->
|
||||
<button data-toggle="oh-modal-toggle" data-target="#genericModal"
|
||||
hx-get="{{ instance.get_update_url }}?instance_ids={{ instance.ordered_ids }}" hx-target="#genericModalBody"
|
||||
class="oh-btn oh-btn--info w-100"
|
||||
>
|
||||
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
{% trans 'Edit' %}
|
||||
</button>
|
||||
<!-- End of Edit Button -->
|
||||
{% endif %}
|
||||
|
||||
{% if perms.asset.delete_assetlot %}
|
||||
<!-- Start of Delete Form -->
|
||||
<form hx-confirm="{% trans 'Do you want to delete this batch number ?' %}" class="w-100"
|
||||
hx-post="{{ instance.get_delete_url }}?instance_ids={{ instance.ordered_ids }}" hx-target="#AssetBatchList">
|
||||
{% csrf_token %}
|
||||
<button data-action="delete" type="submit"
|
||||
class="oh-btn oh-btn--danger w-100"
|
||||
>
|
||||
<ion-icon name="trash-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
{% trans 'Delete' %}
|
||||
</button>
|
||||
</form>
|
||||
<!-- End of Delete Form -->
|
||||
{% endif %}
|
||||
@@ -6,6 +6,7 @@ from django import views
|
||||
from django.urls import path
|
||||
|
||||
from asset.cbv import (
|
||||
asset,
|
||||
asset_batch_no,
|
||||
asset_category,
|
||||
asset_history,
|
||||
@@ -48,7 +49,8 @@ urlpatterns = [
|
||||
asset_category.AssetFormView.as_view(),
|
||||
name="asset-creation",
|
||||
),
|
||||
path("asset-list/<int:cat_id>", views.asset_list, name="asset-list"),
|
||||
# path("asset-list/<int:cat_id>", views.asset_list, name="asset-list"),
|
||||
path("asset-list/<int:cat_id>", asset.AssetListView.as_view(), name="asset-list"),
|
||||
# path("asset-update/<int:asset_id>/", views.asset_update, name="asset-update"),
|
||||
path(
|
||||
"asset-update/<int:pk>/",
|
||||
@@ -79,7 +81,7 @@ urlpatterns = [
|
||||
# ),
|
||||
path(
|
||||
"asset-information/<int:pk>/",
|
||||
asset_category.AssetCategoryDetailView.as_view(),
|
||||
asset.AssetInformationView.as_view(),
|
||||
name="asset-information",
|
||||
),
|
||||
path("asset-category-view/", views.asset_category_view, name="asset-category-view"),
|
||||
|
||||
Reference in New Issue
Block a user