Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally (defaults to true) add install counts to app list view. #454

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions inventory/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

INVENTORY_PATTERN = server.utils.get_setting('inventory_exclusion_pattern')
FILTER_VIRTUAL = server.utils.get_setting('filter_proxied_virtualization_apps', True)
SHOW_INSTALL_COUNTS = server.utils.get_setting('show_inventory_install_counts', True)

ApplicationTuple = collections.namedtuple(
'Application', ['name', 'bundleid', 'bundlename', 'install_count'])
Expand Down Expand Up @@ -292,6 +293,26 @@ def link_to_detail(self, instance, **kwargs):
url = reverse("application_detail", kwargs=link_kwargs)
return f'<a href="{url}">{instance.name}</a>'

def get_install_count(self, instance, **kwargs):
"""Get the number of app installs filtered by access group"""
# Build a link to InventoryListView for install count badge.
link_kwargs = copy.copy(kwargs['view'].kwargs)
link_kwargs['application_id'] = instance.pk
url = reverse("inventory_list", kwargs=link_kwargs)
anchor = '<a href="{}"><span class="badge">{}</span></a>'.format(
url, instance.inventoryitem_set.count())
return anchor

def get_datatable(self):
datatable = super().get_datatable()
# Add the install count column dynamically.
# There is no conditional way to define class attributes at
# import time, so we add it here in this override.
if SHOW_INSTALL_COUNTS:
datatable.columns["install_count"] = DisplayColumn(
"Install Count", source='install_count', processor='get_install_count')
return datatable

def get_queryset(self):
queryset = self.filter_queryset_by_group(self.model.objects)

Expand Down