[UPDT] ASSET: Update asset app to latest style
This commit is contained in:
67
asset/cbv/asset.py
Normal file
67
asset/cbv/asset.py
Normal file
@@ -0,0 +1,67 @@
|
||||
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"
|
||||
|
||||
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,20 +40,19 @@ 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"
|
||||
@@ -142,34 +141,5 @@ class AssetBatchDetailView(HorillaDetailedView):
|
||||
title = _("Details")
|
||||
header = False
|
||||
model = AssetLot
|
||||
body = {
|
||||
(_("Batch Number"), "lot_number"),
|
||||
(_("Assets"), "assets_column"),
|
||||
(_("Description"), "lot_description"),
|
||||
}
|
||||
action_method = "deatil_actions"
|
||||
# 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"
|
||||
# """,
|
||||
# },
|
||||
# ]
|
||||
body = ["lot_number", (_("Asset"), "assets_column"), "lot_description"]
|
||||
action_method = "detail_actions"
|
||||
|
||||
@@ -214,12 +214,43 @@ class AssetCategoryNav(HorillaNavView):
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.search_url = reverse("asset-category-view-search-filter")
|
||||
self.create_attrs = f"""
|
||||
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;"
|
||||
""",
|
||||
},
|
||||
)
|
||||
|
||||
if self.request.user.has_perm("view_asset"):
|
||||
self.actions.append(
|
||||
{
|
||||
"action": _("Export"),
|
||||
"attrs": f"""
|
||||
data-toggle="oh-modal-toggle"
|
||||
data-target="#genericModal"
|
||||
hx-get="{reverse('asset-category-creation')}"
|
||||
hx-target="#genericModalBody"
|
||||
"""
|
||||
data-target="#objectCreateModal"
|
||||
hx-get="{reverse('asset-export-excel')}"
|
||||
hx-target="#objectCreateModalTarget"
|
||||
style="cursor: pointer;"
|
||||
""",
|
||||
}
|
||||
)
|
||||
|
||||
# if self.request.user.has_perm(
|
||||
# "attendance.add_attendanceovertime"
|
||||
# ) or is_reportingmanager(self.request):
|
||||
@@ -250,55 +281,3 @@ class AssetCategoryNav(HorillaNavView):
|
||||
filter_instance = AssetFilter()
|
||||
filter_form_context_name = "form"
|
||||
search_swap_target = "#assetCategoryList"
|
||||
|
||||
|
||||
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"
|
||||
""",
|
||||
},
|
||||
]
|
||||
|
||||
@@ -104,9 +104,9 @@ class AssetLot(HorillaModel):
|
||||
context={"instance": self},
|
||||
)
|
||||
|
||||
def deatil_actions(self):
|
||||
def detail_actions(self):
|
||||
return render_template(
|
||||
path="cbv/asset_batch_no/deatil_actions.html",
|
||||
path="cbv/asset_batch_no/detail_actions.html",
|
||||
context={"instance": self},
|
||||
)
|
||||
|
||||
@@ -183,11 +183,10 @@ class Asset(HorillaModel):
|
||||
def __str__(self):
|
||||
return f"{self.asset_name}-{self.asset_tracking_id}"
|
||||
|
||||
def get_status_display(self):
|
||||
"""
|
||||
Display status
|
||||
"""
|
||||
return dict(self.ASSET_STATUS).get(self.asset_status)
|
||||
def action_column(self):
|
||||
return render_template(
|
||||
path="asset/action_column.html", context={"instance": self}
|
||||
)
|
||||
|
||||
def detail_view_action(self):
|
||||
"""
|
||||
@@ -195,10 +194,14 @@ 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):
|
||||
url = reverse_lazy("asset-information", kwargs={"pk": self.pk})
|
||||
return url
|
||||
|
||||
def get_update_url(self):
|
||||
"""
|
||||
This method to get update url
|
||||
|
||||
36
asset/templates/asset/action_column.html
Normal file
36
asset/templates/asset/action_column.html
Normal file
@@ -0,0 +1,36 @@
|
||||
{% load static i18n %}
|
||||
{% if perms.asset.change_asset %}
|
||||
<button class="oh-btn oh-btn--light-bkg w-100" data-toggle="oh-modal-toggle" data-target="#genericModal"
|
||||
hx-get="{{ instance.get_update_url }}?{% if asset_under == 'asset_filter' %}asset_under=asset_filter&{% endif %}{{ pg }}"
|
||||
hx-target="#genericModalBody" title="{% trans 'Edit' %}">
|
||||
<ion-icon name="create-outline" role="img" class="md hydrated" aria-label="create outline"></ion-icon>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if perms.asset.add_asset %}
|
||||
<button class="oh-btn oh-btn--light-bkg w-100" data-toggle="oh-modal-toggle" data-target="#genericModal"
|
||||
hx-get="{% url 'duplicate-asset' instance.id %}?{{pg}}" hx-target="#genericModalBody"
|
||||
title="{% trans 'Duplicate' %}">
|
||||
<ion-icon name="copy-outline"></ion-icon>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if asset.assetassignment_set.all %}
|
||||
<button class="oh-btn oh-btn--light-bkg w-100" data-toggle="oh-modal-toggle" data-target="#dynamicCreateModal"
|
||||
hx-get="{% url 'add-asset-report' asset.id %}?asset_list=true" hx-target="#dynamicCreateModalTarget"
|
||||
id="oh-btn-asset-update-modal" title="{% trans 'Report' %}">
|
||||
<ion-icon name="document-attach-outline"></ion-icon>
|
||||
</button>
|
||||
{% else %}
|
||||
<button disabled class="oh-btn oh-btn--light-bkg w-100" id="oh-btn-asset-update-modal" title="{% trans 'Report' %}">
|
||||
<ion-icon name="document-attach-outline"></ion-icon>
|
||||
</button>
|
||||
{% endif %}
|
||||
{% if perms.asset.delete_asset %}
|
||||
<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{{ instance.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 %}
|
||||
27
asset/templates/cbv/asset/detail_action.html
Normal file
27
asset/templates/cbv/asset/detail_action.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="w-24 px-4 py-2 bg-primary-600 text-white rounded-md text-xs flex items-center justify-center gap-2 hover:bg-primary-800 transition duration-300">
|
||||
<img src="{% static 'horilla_theme/assets/img/icons/edit.svg' %}" alt="{% trans 'Edit' %}" width="13"
|
||||
class="filter brightness-0 invert">
|
||||
{% 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 asset ?' %}"
|
||||
hx-post="{{ instance.get_delete_url }}?instance_ids={{ instance.ordered_ids }}" hx-target="#AssetBatchList">
|
||||
{% csrf_token %}
|
||||
<button data-action="delete" type="submit"
|
||||
class="w-24 px-4 py-2 bg-white rounded-md text-xs flex items-center justify-center gap-2 border border-primary-500 hover:border-primary-600 transition duration-300">
|
||||
<img src="{% static 'horilla_theme/assets/img/icons/trash.svg' %}" alt="{% trans 'Delete' %}" width="16"
|
||||
class="mt-[-1px]">
|
||||
{% trans 'Delete' %}
|
||||
</button>
|
||||
</form>
|
||||
<!-- End of Delete Form -->
|
||||
{% endif %}
|
||||
@@ -2,7 +2,7 @@
|
||||
{% 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"
|
||||
hx-get="{{ instance.get_update_url }}?instance_ids={{ instance.ordered_ids }}" hx-target="#genericModalBody"
|
||||
class="w-24 px-4 py-2 bg-primary-600 text-white rounded-md text-xs flex items-center justify-center gap-2 hover:bg-primary-800 transition duration-300">
|
||||
<img src="{% static 'horilla_theme/assets/img/icons/edit.svg' %}" alt="{% trans 'Edit' %}" width="13"
|
||||
class="filter brightness-0 invert">
|
||||
@@ -14,7 +14,7 @@
|
||||
{% if perms.asset.delete_assetlot %}
|
||||
<!-- Start of Delete Form -->
|
||||
<form hx-confirm="{% trans 'Do you want to delete this batch number ?' %}"
|
||||
hx-post="{{ instance.get_delete_url }}instance_ids={{ instance.ordered_ids }}" hx-target="#AssetBatchList">
|
||||
hx-post="{{ instance.get_delete_url }}?instance_ids={{ instance.ordered_ids }}" hx-target="#AssetBatchList">
|
||||
{% csrf_token %}
|
||||
<button data-action="delete" type="submit"
|
||||
class="w-24 px-4 py-2 bg-white rounded-md text-xs flex items-center justify-center gap-2 border border-primary-500 hover:border-primary-600 transition duration-300">
|
||||
@@ -24,4 +24,4 @@
|
||||
</button>
|
||||
</form>
|
||||
<!-- End of Delete Form -->
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
@@ -1,19 +0,0 @@
|
||||
{% load i18n %}
|
||||
{% include 'generic/horilla_detailed_view.html'%}
|
||||
|
||||
{% if messages %}
|
||||
<div class="oh-wrapper">
|
||||
{% for message in messages %}
|
||||
<div class="oh-alert-container">
|
||||
<div class="oh-alert oh-alert--animated {{message.tags}}">
|
||||
{{ message }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{%if message.tags == "oh-alert--success" %}
|
||||
<span class="oh-span__class" hx-trigger="load" hx-get="{%url 'asset-list' cat_id=instance.asset_category_id.id %}?{{pd}}"
|
||||
hx-target="#assetCategory{{instance.asset_category_id.id}}"></span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% 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,7 @@ 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>", 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 +80,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