14731 merge

This commit is contained in:
Arthur Hanson 2024-07-18 15:47:05 +07:00
commit 1f588afe02
2 changed files with 15 additions and 27 deletions

View File

@ -1,8 +1,7 @@
from datetime import datetime
import django_tables2 as tables import django_tables2 as tables
from django.contrib.humanize.templatetags.humanize import naturalday
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from netbox.tables import BaseTable
from netbox.tables import BaseTable, columns
__all__ = ( __all__ = (
'CatalogPluginTable', 'CatalogPluginTable',
@ -14,8 +13,9 @@ class PluginVersionTable(BaseTable):
version = tables.Column( version = tables.Column(
verbose_name=_('Version') verbose_name=_('Version')
) )
last_updated = tables.Column( last_updated = columns.DateTimeColumn(
accessor=tables.A('date'), accessor=tables.A('date'),
timespec='minutes',
verbose_name=_('Last Updated') verbose_name=_('Last Updated')
) )
min_version = tables.Column( min_version = tables.Column(
@ -37,9 +37,6 @@ class PluginVersionTable(BaseTable):
) )
orderable = False orderable = False
def render_last_updated(self, value, record):
return naturalday(value)
class CatalogPluginTable(BaseTable): class CatalogPluginTable(BaseTable):
title_short = tables.Column( title_short = tables.Column(
@ -50,19 +47,19 @@ class CatalogPluginTable(BaseTable):
accessor=tables.A('author.name'), accessor=tables.A('author.name'),
verbose_name=_('Author') verbose_name=_('Author')
) )
is_local = tables.BooleanColumn( is_local = columns.BooleanColumn(
verbose_name=_('Local') verbose_name=_('Local')
) )
is_installed = tables.BooleanColumn( is_installed = columns.BooleanColumn(
verbose_name=_('Installed') verbose_name=_('Installed')
) )
is_certified = tables.BooleanColumn( is_certified = columns.BooleanColumn(
verbose_name=_('Certified') verbose_name=_('Certified')
) )
created_at = tables.Column( created_at = columns.DateTimeColumn(
verbose_name=_('Published') verbose_name=_('Published')
) )
updated_at = tables.Column( updated_at = columns.DateTimeColumn(
verbose_name=_('Updated') verbose_name=_('Updated')
) )
@ -74,3 +71,6 @@ class CatalogPluginTable(BaseTable):
default_columns = ( default_columns = (
'title_short', 'author', 'is_local', 'is_installed', 'is_certified', 'created_at', 'updated_at', 'title_short', 'author', 'is_local', 'is_installed', 'is_certified', 'created_at', 'updated_at',
) )
# List installed plugins first, then certified plugins, then
# everything else (with each tranche ordered alphabetically)
order_by = ('-is_installed', '-is_certified', 'name')

View File

@ -2,7 +2,6 @@ import json
import platform import platform
from django import __version__ as DJANGO_VERSION from django import __version__ as DJANGO_VERSION
from django.apps import apps
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.mixins import UserPassesTestMixin from django.contrib.auth.mixins import UserPassesTestMixin
@ -26,7 +25,6 @@ from rq.worker import Worker
from rq.worker_registration import clean_worker_registry from rq.worker_registration import clean_worker_registry
from netbox.config import get_config, PARAMS from netbox.config import get_config, PARAMS
from netbox.plugins import PluginConfig
from netbox.views import generic from netbox.views import generic
from netbox.views.generic.base import BaseObjectView from netbox.views.generic.base import BaseObjectView
from netbox.views.generic.mixins import TableMixin from netbox.views.generic.mixins import TableMixin
@ -584,7 +582,7 @@ class WorkerView(BaseRQView):
# #
# Plugins # System
# #
class SystemView(UserPassesTestMixin, View): class SystemView(UserPassesTestMixin, View):
@ -649,25 +647,15 @@ class SystemView(UserPassesTestMixin, View):
class PluginListView(UserPassesTestMixin, View): class PluginListView(UserPassesTestMixin, View):
def test_func(self): def test_func(self):
return self.request.user.is_superuser return self.request.user.is_staff
def get(self, request): def get(self, request):
q = request.GET.get('q', None) q = request.GET.get('q', None)
plugins = get_plugins() plugins = get_plugins().values()
plugins = plugins.values()
if q: if q:
plugins = [obj for obj in plugins if q.casefold() in obj.name.casefold()] plugins = [obj for obj in plugins if q.casefold() in obj.name.casefold()]
# Sort order should be:
# Installed plugins
# Certified catalog plugins
# Remaining catalog plugins
# With alphabetical sort within each traunch.
plugins = sorted(plugins, key=lambda x: x.title_short, reverse=False)
plugins = sorted(plugins, key=lambda x: x.is_certified, reverse=True)
plugins = sorted(plugins, key=lambda x: x.is_installed, reverse=True)
table = CatalogPluginTable(plugins, user=request.user) table = CatalogPluginTable(plugins, user=request.user)
table.configure(request) table.configure(request)