[UPDT] ASSET: Dynamic pagination to asset request allocation view
This commit is contained in:
@@ -86,8 +86,7 @@
|
||||
<!-- Sticky Table for own objective-->
|
||||
{% if request_field %}
|
||||
<div class="oh-card">
|
||||
{% dynamic_regroup asset_requests by request_field as request_grouper %}
|
||||
{% for request_list in request_grouper %}
|
||||
{% for request_list in asset_requests %}
|
||||
<div class="oh-accordion-meta">
|
||||
<div class="oh-accordion-meta__item">
|
||||
<div class="oh-accordion-meta__header" onclick='$(this).toggleClass("oh-accordion-meta__header--show");'>
|
||||
@@ -96,7 +95,7 @@
|
||||
<span
|
||||
class="oh-badge oh-badge--secondary oh-badge--small oh-badge--round mr-1"
|
||||
>
|
||||
{{request_list.list|length}}
|
||||
{{request_list.list.paginator.count}}
|
||||
</span>
|
||||
{{request_list.grouper}}
|
||||
</div>
|
||||
@@ -244,6 +243,77 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-pagination">
|
||||
<span class="oh-pagination__page">
|
||||
{% trans "Page" %} {{ request_list.list.number }}
|
||||
{%trans "of" %} {{request_list.list.paginator.num_pages }}.
|
||||
</span>
|
||||
<nav class="oh-pagination__nav">
|
||||
<div class="oh-pagination__input-container me-3">
|
||||
<span class="oh-pagination__label me-1"
|
||||
>{% trans "Page" %}</span
|
||||
>
|
||||
<input
|
||||
type="number"
|
||||
name="{{request_list.dynamic_name}}"
|
||||
class="oh-pagination__input"
|
||||
value="{{request_list.list.number}}"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}"
|
||||
hx-target="#asset_request_allocation_list"
|
||||
min="1"
|
||||
/>
|
||||
<span class="oh-pagination__label"
|
||||
>{% trans "of" %}
|
||||
{{request_list.list.paginator.num_pages}}</span
|
||||
>
|
||||
</div>
|
||||
<ul class="oh-pagination__items">
|
||||
{% if request_list.list.has_previous %}
|
||||
<li
|
||||
class="oh-pagination__item oh-pagination__item--wide"
|
||||
>
|
||||
<a
|
||||
hx-target="#asset_request_allocation_list"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}&{{request_list.dynamic_name}}=1"
|
||||
class="oh-pagination__link"
|
||||
>{% trans "First" %}</a
|
||||
>
|
||||
</li>
|
||||
<li
|
||||
class="oh-pagination__item oh-pagination__item--wide"
|
||||
>
|
||||
<a
|
||||
hx-target="#asset_request_allocation_list"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}&{{request_list.dynamic_name}}={{ request_list.list.previous_page_number }}"
|
||||
class="oh-pagination__link"
|
||||
>{% trans "Previous" %}</a
|
||||
>
|
||||
</li>
|
||||
{% endif %} {% if request_list.list.has_next %}
|
||||
<li
|
||||
class="oh-pagination__item oh-pagination__item--wide"
|
||||
>
|
||||
<a
|
||||
hx-target="#asset_request_allocation_list"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}&{{request_list.dynamic_name}}={{ request_list.list.next_page_number }}"
|
||||
class="oh-pagination__link"
|
||||
>{% trans "Next" %}</a
|
||||
>
|
||||
</li>
|
||||
<li
|
||||
class="oh-pagination__item oh-pagination__item--wide"
|
||||
>
|
||||
<a
|
||||
hx-target="#asset_request_allocation_list"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}&{{request_list.dynamic_name}}={{ request_list.list.paginator.num_pages }}"
|
||||
class="oh-pagination__link"
|
||||
>{% trans "Last" %}</a
|
||||
>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -432,8 +502,7 @@
|
||||
<!-- stivky table for all objectives -->
|
||||
{% if allocation_field %}
|
||||
<div class="oh-card">
|
||||
{% dynamic_regroup asset_allocations by allocation_field as allocation_grouper %}
|
||||
{% for allocation_list in allocation_grouper %}
|
||||
{% for allocation_list in asset_allocations %}
|
||||
<div class="oh-accordion-meta">
|
||||
<div class="oh-accordion-meta__item">
|
||||
<div class="oh-accordion-meta__header" onclick='$(this).toggleClass("oh-accordion-meta__header--show");'>
|
||||
@@ -442,7 +511,7 @@
|
||||
<span
|
||||
class="oh-badge oh-badge--secondary oh-badge--small oh-badge--round mr-1"
|
||||
>
|
||||
{{allocation_list.list|length}}
|
||||
{{allocation_list.list.paginator.count}}
|
||||
</span>
|
||||
{{allocation_list.grouper}}
|
||||
</div>
|
||||
@@ -598,6 +667,77 @@
|
||||
<!-- end asset return form start -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="oh-pagination">
|
||||
<span class="oh-pagination__page">
|
||||
{% trans "Page" %} {{ allocation_list.list.number }}
|
||||
{%trans "of" %} {{allocation_list.list.paginator.num_pages }}.
|
||||
</span>
|
||||
<nav class="oh-pagination__nav">
|
||||
<div class="oh-pagination__input-container me-3">
|
||||
<span class="oh-pagination__label me-1"
|
||||
>{% trans "Page" %}</span
|
||||
>
|
||||
<input
|
||||
type="number"
|
||||
name="{{allocation_list.dynamic_name}}"
|
||||
class="oh-pagination__input"
|
||||
value="{{allocation_list.list.number}}"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}"
|
||||
hx-target="#asset_request_allocation_list"
|
||||
min="1"
|
||||
/>
|
||||
<span class="oh-pagination__label"
|
||||
>{% trans "of" %}
|
||||
{{allocation_list.list.paginator.num_pages}}</span
|
||||
>
|
||||
</div>
|
||||
<ul class="oh-pagination__items">
|
||||
{% if allocation_list.list.has_previous %}
|
||||
<li
|
||||
class="oh-pagination__item oh-pagination__item--wide"
|
||||
>
|
||||
<a
|
||||
hx-target="#asset_request_allocation_list"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}&{{allocation_list.dynamic_name}}=1"
|
||||
class="oh-pagination__link"
|
||||
>{% trans "First" %}</a
|
||||
>
|
||||
</li>
|
||||
<li
|
||||
class="oh-pagination__item oh-pagination__item--wide"
|
||||
>
|
||||
<a
|
||||
hx-target="#asset_request_allocation_list"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}&{{allocation_list.dynamic_name}}={{ allocation_list.list.previous_page_number }}"
|
||||
class="oh-pagination__link"
|
||||
>{% trans "Previous" %}</a
|
||||
>
|
||||
</li>
|
||||
{% endif %} {% if allocation_list.list.has_next %}
|
||||
<li
|
||||
class="oh-pagination__item oh-pagination__item--wide"
|
||||
>
|
||||
<a
|
||||
hx-target="#asset_request_allocation_list"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}&{{allocation_list.dynamic_name}}={{ allocation_list.list.next_page_number }}"
|
||||
class="oh-pagination__link"
|
||||
>{% trans "Next" %}</a
|
||||
>
|
||||
</li>
|
||||
<li
|
||||
class="oh-pagination__item oh-pagination__item--wide"
|
||||
>
|
||||
<a
|
||||
hx-target="#asset_request_allocation_list"
|
||||
hx-get="{% url 'asset-request-allocation-view-search-filter' %}?{{pg}}&{{allocation_list.dynamic_name}}={{ allocation_list.list.paginator.num_pages }}"
|
||||
class="oh-pagination__link"
|
||||
>{% trans "Last" %}</a
|
||||
>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -445,7 +445,7 @@ def filter_pagination_asset_category(request):
|
||||
"asset_filter_form": asset_filter_form.form,
|
||||
"pg": previous_data,
|
||||
"filter_dict": data_dict,
|
||||
"dashboard":request.GET.get("dashboard"),
|
||||
"dashboard": request.GET.get("dashboard"),
|
||||
}
|
||||
|
||||
|
||||
@@ -462,8 +462,7 @@ def asset_category_view(request):
|
||||
Raises:
|
||||
None
|
||||
"""
|
||||
|
||||
|
||||
|
||||
queryset = AssetCategory.objects.all()
|
||||
if queryset.exists():
|
||||
template = "category/asset_category_view.html"
|
||||
@@ -851,17 +850,49 @@ def filter_pagination_asset_request_allocation(request):
|
||||
request.GET, queryset=asset_requests_queryset
|
||||
).qs
|
||||
if request_field != "" and request_field is not None:
|
||||
request_field_copy = request_field.replace(".", "__")
|
||||
asset_request_filtered = asset_request_filtered.order_by(request_field_copy)
|
||||
asset_request_filtered = group_by_queryset(
|
||||
asset_request_filtered, request_field, request.GET.get("page"), "page"
|
||||
)
|
||||
list_values = [entry['list'] for entry in asset_request_filtered]
|
||||
id_list = []
|
||||
for value in list_values:
|
||||
for instance in value.object_list:
|
||||
id_list.append(instance.id)
|
||||
|
||||
requests_ids = json.dumps(list(id_list))
|
||||
|
||||
else:
|
||||
asset_request_filtered = paginator_qry(asset_request_filtered, request.GET.get("page"))
|
||||
requests_ids = json.dumps(
|
||||
[
|
||||
instance.id
|
||||
for instance in asset_request_filtered.object_list
|
||||
]
|
||||
)
|
||||
|
||||
asset_allocation_filtered = AssetAllocationFilter(
|
||||
request.GET, queryset=asset_allocations_queryset
|
||||
).qs
|
||||
|
||||
if allocation_field != "" and allocation_field is not None:
|
||||
allocation_field_copy = allocation_field.replace(".", "__")
|
||||
asset_allocation_filtered = asset_allocation_filtered.order_by(
|
||||
allocation_field_copy
|
||||
asset_allocation_filtered = group_by_queryset(
|
||||
asset_allocation_filtered, allocation_field, request.GET.get("page"), "page"
|
||||
)
|
||||
list_values = [entry['list'] for entry in asset_allocation_filtered]
|
||||
id_list = []
|
||||
for value in list_values:
|
||||
for instance in value.object_list:
|
||||
id_list.append(instance.id)
|
||||
|
||||
allocations_ids = json.dumps(list(id_list))
|
||||
|
||||
else:
|
||||
asset_allocation_filtered = paginator_qry(asset_allocation_filtered, request.GET.get("page"))
|
||||
allocations_ids = json.dumps(
|
||||
[
|
||||
instance.id
|
||||
for instance in asset_allocation_filtered.object_list
|
||||
]
|
||||
)
|
||||
|
||||
asset_paginator = Paginator(assets_filtered.qs, get_pagination())
|
||||
@@ -871,10 +902,10 @@ def filter_pagination_asset_request_allocation(request):
|
||||
assets = asset_paginator.get_page(page_number)
|
||||
asset_requests = asset_request_paginator.get_page(page_number)
|
||||
asset_allocations = asset_allocation_paginator.get_page(page_number)
|
||||
requests_ids = json.dumps([instance.id for instance in asset_requests.object_list])
|
||||
allocations_ids = json.dumps(
|
||||
[instance.id for instance in asset_allocations.object_list]
|
||||
)
|
||||
# requests_ids = json.dumps([instance.id for instance in asset_requests.object_list])
|
||||
# allocations_ids = json.dumps(
|
||||
# [instance.id for instance in asset_allocations.object_list]
|
||||
# )
|
||||
|
||||
data_dict = parse_qs(previous_data)
|
||||
get_key_instances(AssetRequest, data_dict)
|
||||
@@ -1113,7 +1144,9 @@ def asset_export_excel(request):
|
||||
emp_company = company_name.first()
|
||||
|
||||
# Access the date_format attribute directly
|
||||
date_format = emp_company.date_format if emp_company else "MMM. D, YYYY"
|
||||
date_format = (
|
||||
emp_company.date_format if emp_company else "MMM. D, YYYY"
|
||||
)
|
||||
else:
|
||||
date_format = "MMM. D, YYYY"
|
||||
# Define date formats
|
||||
|
||||
Reference in New Issue
Block a user