Skip to content

Commit 676b8c7

Browse files
author
Dylan
committed
fix bulk_scan button missing
1 parent 1118cd3 commit 676b8c7

6 files changed

Lines changed: 27 additions & 37 deletions

File tree

netbox_inventory/object_actions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.utils.translation import gettext as _
2+
3+
from netbox.object_actions import ObjectAction
4+
5+
6+
class BulkScan(ObjectAction):
7+
"""
8+
Scan or assign barcodes to multiple assets at once.
9+
"""
10+
name = 'bulk_scan'
11+
label = _('Scan')
12+
multi = True
13+
permissions_required = {'change'}
14+
template_name = 'netbox_inventory/buttons/bulk_scan.html'

netbox_inventory/templates/netbox_inventory/asset_list.html

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
{% load i18n %}
2-
{% if url %}
3-
<button type="submit" name="_scan" {% formaction %}="{{ url }}" class="btn btn-blue">
4-
<i class="mdi mdi-barcode-scan" aria-hidden="true"></i> Scan
5-
</button>
6-
{% endif %}
1+
<button type="submit" name="_scan" {% formaction %}="{{ url }}{% if url_params %}?{{ url_params.urlencode }}{% endif %}" class="btn btn-blue">
2+
<i class="mdi mdi-barcode-scan" aria-hidden="true"></i> {{ label }}
3+
</button>

netbox_inventory/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
from django import template
2-
from django.urls import NoReverseMatch, reverse
2+
from django.urls import NoReverseMatch
3+
from django.utils.translation import gettext as _
34

4-
from utilities.views import get_viewname
5-
6-
__all__ = (
7-
'bulk_scan_button',
8-
)
5+
from utilities.views import get_action_url
96

107
register = template.Library()
118

9+
1210
@register.inclusion_tag('netbox_inventory/buttons/bulk_scan.html', takes_context=True)
1311
def bulk_scan_button(context, model, action='bulk_scan', query_params=None):
1412
try:
15-
url = reverse(get_viewname(model, action))
13+
url = get_action_url(model, action=action)
1614
if query_params:
1715
url = f'{url}?{query_params.urlencode()}'
1816
except NoReverseMatch:
1917
url = None
2018

2119
return {
22-
'htmx_navigation': context.get('htmx_navigation'),
20+
'label': _('Scan Selected'),
2321
'url': url,
22+
'htmx_navigation': context.get('htmx_navigation'),
2423
}

netbox_inventory/views/asset.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from utilities.views import register_model_view
1616

1717
from .. import filtersets, forms, models, tables
18+
from ..object_actions import BulkScan
1819
from ..template_content import EOL_PROGRESSBAR, WARRANTY_PROGRESSBAR
1920
from ..utils import (
2021
get_tags_and_edit_protected_asset_fields,
@@ -26,6 +27,7 @@
2627
"AssetListView",
2728
"AssetBulkCreateView",
2829
"AssetEditView",
30+
"AssetBulkScanView",
2931
"AssetDeleteView",
3032
"AssetBulkImportView",
3133
"AssetBulkEditView",
@@ -66,8 +68,7 @@ class AssetListView(generic.ObjectListView):
6668
table = tables.AssetTable
6769
filterset = filtersets.AssetFilterSet
6870
filterset_form = forms.AssetFilterForm
69-
template_name = "netbox_inventory/asset_list.html"
70-
actions = generic.ObjectListView.actions
71+
actions = (*generic.ObjectListView.actions, BulkScan)
7172

7273

7374
@register_model_view(models.Asset, "bulk_add", path="bulk-add", detail=False)

0 commit comments

Comments
 (0)