From 7b40a146f5431ba1b341a52c7201b4b9d0c6b397 Mon Sep 17 00:00:00 2001 From: Horilla Date: Wed, 10 Sep 2025 15:36:36 +0530 Subject: [PATCH] [UPDT] ASSET: Change existing style to the latest style --- asset/cbv/asset.py | 68 ++++++++++ asset/cbv/asset_batch_no.py | 95 ++++---------- asset/cbv/asset_category.py | 122 ++++++------------ asset/models.py | 24 +++- asset/templates/asset/action_column.html | 60 +++++++++ asset/templates/cbv/asset/detail_action.html | 26 ++++ .../cbv/asset_batch_no/detail_actions.html | 27 ++++ asset/urls.py | 6 +- 8 files changed, 271 insertions(+), 157 deletions(-) create mode 100644 asset/cbv/asset.py create mode 100644 asset/templates/asset/action_column.html create mode 100644 asset/templates/cbv/asset/detail_action.html create mode 100644 asset/templates/cbv/asset_batch_no/detail_actions.html diff --git a/asset/cbv/asset.py b/asset/cbv/asset.py new file mode 100644 index 000000000..c9e36d7ab --- /dev/null +++ b/asset/cbv/asset.py @@ -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", + ] diff --git a/asset/cbv/asset_batch_no.py b/asset/cbv/asset_batch_no.py index b7bd59f2d..e4319e9ff 100644 --- a/asset/cbv/asset_batch_no.py +++ b/asset/cbv/asset_batch_no.py @@ -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" diff --git a/asset/cbv/asset_category.py b/asset/cbv/asset_category.py index d3079cb18..4142d7846 100644 --- a/asset/cbv/asset_category.py +++ b/asset/cbv/asset_category.py @@ -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;" """, - }, - ] + } + ) diff --git a/asset/models.py b/asset/models.py index 4473c7e73..e5fff7cee 100644 --- a/asset/models.py +++ b/asset/models.py @@ -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 diff --git a/asset/templates/asset/action_column.html b/asset/templates/asset/action_column.html new file mode 100644 index 000000000..9cb2851b2 --- /dev/null +++ b/asset/templates/asset/action_column.html @@ -0,0 +1,60 @@ +{% load static i18n %} +
+ {% if perms.asset.change_asset %} + {% if asset_under == 'asset_filter' %} + + + + {% else %} + + + + {% endif %} + {% endif %} + {% if perms.asset.add_asset %} + + + + {% endif %} + {% if asset.assetassignment_set.all %} + + + + {% else %} + + + + {% endif %} + {% if perms.asset.delete_asset %} + {% if asset_under == 'asset_filter' %} +
+ {% csrf_token %} + +
+ {% else %} +
+ {% csrf_token %} + +
+ {% endif %} + {% endif %} +
diff --git a/asset/templates/cbv/asset/detail_action.html b/asset/templates/cbv/asset/detail_action.html new file mode 100644 index 000000000..191f9014e --- /dev/null +++ b/asset/templates/cbv/asset/detail_action.html @@ -0,0 +1,26 @@ +{% load i18n %} +{% if perms.asset.change_asset or perms.asset.delete_asset %} +
+
+ {% if perms.asset.change_asset %} + + + {% trans "Edit" %} + + {% endif %} + {% if perms.asset.delete_asset %} +
+ {% csrf_token %} + +
+ {% endif %} +
+
+{% endif %} \ No newline at end of file diff --git a/asset/templates/cbv/asset_batch_no/detail_actions.html b/asset/templates/cbv/asset_batch_no/detail_actions.html new file mode 100644 index 000000000..c81d94f9b --- /dev/null +++ b/asset/templates/cbv/asset_batch_no/detail_actions.html @@ -0,0 +1,27 @@ +{% load static i18n %} +{% if perms.asset.change_assetlot %} + + + +{% endif %} + +{% if perms.asset.delete_assetlot %} + +
+ {% csrf_token %} + +
+ +{% endif %} \ No newline at end of file diff --git a/asset/urls.py b/asset/urls.py index 532f9543b..15e268e9b 100644 --- a/asset/urls.py +++ b/asset/urls.py @@ -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/", views.asset_list, name="asset-list"), + # path("asset-list/", views.asset_list, name="asset-list"), + path("asset-list/", asset.AssetListView.as_view(), name="asset-list"), # path("asset-update//", views.asset_update, name="asset-update"), path( "asset-update//", @@ -79,7 +81,7 @@ urlpatterns = [ # ), path( "asset-information//", - asset_category.AssetCategoryDetailView.as_view(), + asset.AssetInformationView.as_view(), name="asset-information", ), path("asset-category-view/", views.asset_category_view, name="asset-category-view"),