mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 08:38:16 -06:00
14731 sort / status
This commit is contained in:
parent
61106113db
commit
36e268300f
@ -81,3 +81,29 @@ class ObjectChangeActionChoices(ChoiceSet):
|
||||
(ACTION_UPDATE, _('Updated'), 'blue'),
|
||||
(ACTION_DELETE, _('Deleted'), 'red'),
|
||||
)
|
||||
|
||||
|
||||
class PluginSortChoices(ChoiceSet):
|
||||
|
||||
SORT_NAME_AZ = 'az'
|
||||
SORT_NAME_ZA = 'za'
|
||||
SORT_UPDATED = 'updated'
|
||||
SORT_PUBLISHED = 'published'
|
||||
|
||||
CHOICES = (
|
||||
(SORT_NAME_AZ, _('By Name (A-Z)'), 'az'),
|
||||
(SORT_NAME_ZA, _('By Name (Z-A)'), 'za'),
|
||||
(SORT_UPDATED, _('By updated date'), 'updated'),
|
||||
(SORT_PUBLISHED, _('By published date'), 'published'),
|
||||
)
|
||||
|
||||
|
||||
class PluginStatusChoices(ChoiceSet):
|
||||
|
||||
STATUS_ALL = 'all'
|
||||
STATUS_INSTALLED = 'installed'
|
||||
|
||||
CHOICES = (
|
||||
(STATUS_ALL, _('All'), 'all'),
|
||||
(STATUS_INSTALLED, _('Installed'), 'installed'),
|
||||
)
|
||||
|
@ -2,8 +2,10 @@ import importlib
|
||||
import importlib.util
|
||||
import json
|
||||
import platform
|
||||
import pytz
|
||||
import requests
|
||||
|
||||
from datetime import datetime
|
||||
from django import __version__ as DJANGO_VERSION
|
||||
from django.apps import apps
|
||||
from django.conf import settings
|
||||
@ -38,6 +40,7 @@ from utilities.htmx import htmx_partial
|
||||
from utilities.query import count_related
|
||||
from utilities.views import ContentTypePermissionRequiredMixin, GetRelatedModelsMixin, register_model_view
|
||||
from . import filtersets, forms, tables
|
||||
from .choices import PluginSortChoices, PluginStatusChoices
|
||||
from .models import *
|
||||
from .tables import CertifiedPluginTable
|
||||
|
||||
@ -673,8 +676,8 @@ def get_local_plugins(plugins):
|
||||
'tag_line': plugin_config.description,
|
||||
'description_short': plugin_config.description,
|
||||
'author': plugin_config.author or _('Unknown Author'),
|
||||
'version': plugin_config.version,
|
||||
'icon': None,
|
||||
'created': datetime.min.replace(tzinfo=pytz.UTC),
|
||||
'updated': datetime.min.replace(tzinfo=pytz.UTC),
|
||||
'is_local': True,
|
||||
'is_installed': True,
|
||||
'is_certified': False,
|
||||
@ -753,8 +756,8 @@ def get_catalog_plugins(plugins):
|
||||
'tag_line': data['tag_line'],
|
||||
'description_short': data['description_short'],
|
||||
'author': data['author']['name'] or _('Unknown Author'),
|
||||
'version': 'x',
|
||||
'icon': None,
|
||||
'created': datetime.fromisoformat(data['created_at']),
|
||||
'updated': datetime.fromisoformat(data['updated_at']),
|
||||
'is_local': False,
|
||||
'is_installed': False,
|
||||
'is_certified': data['release_latest']['is_certified'],
|
||||
@ -783,11 +786,23 @@ class PluginListView(UserPassesTestMixin, View):
|
||||
return self.request.user.is_staff
|
||||
|
||||
def get(self, request):
|
||||
sort = request.GET.get('sort', PluginSortChoices.SORT_NAME_AZ)
|
||||
status = request.GET.get('status', PluginStatusChoices.STATUS_ALL)
|
||||
q = request.GET.get('q', None)
|
||||
|
||||
# Plugins
|
||||
plugins = get_plugins()
|
||||
plugins = [v for k, v in plugins.items()]
|
||||
plugins = sorted(plugins, key=lambda d: d['name'])
|
||||
if status == PluginStatusChoices.STATUS_INSTALLED:
|
||||
plugins = [v for k, v in plugins.items() if v['is_installed']]
|
||||
else:
|
||||
plugins = [v for k, v in plugins.items()]
|
||||
if sort == PluginSortChoices.SORT_NAME_ZA:
|
||||
plugins = sorted(plugins, key=lambda d: d['name'], reverse=True)
|
||||
elif sort == PluginSortChoices.SORT_UPDATED:
|
||||
plugins = sorted(plugins, key=lambda d: d['updated'])
|
||||
elif sort == PluginSortChoices.SORT_PUBLISHED:
|
||||
plugins = sorted(plugins, key=lambda d: d['created'])
|
||||
else:
|
||||
plugins = sorted(plugins, key=lambda d: d['name'])
|
||||
|
||||
return render(request, 'core/plugin_list.html', {
|
||||
'plugins': plugins,
|
||||
|
@ -36,13 +36,18 @@
|
||||
<div class="row">
|
||||
<div class="col-auto">
|
||||
<div class="px-2 d-print-none">
|
||||
{% trans "Status" %}
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{% trans "Status" %}
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item d-flex justify-content-between" href="{% url 'core:plugin_list' %}?status=all">
|
||||
{% trans "All" %}
|
||||
{% if status == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
|
||||
</a>
|
||||
<a class="dropdown-item d-flex justify-content-between" href="{% url 'core:plugin_list' %}?status=installed">
|
||||
{% trans "Installed & Available" %}
|
||||
{% trans "Installed" %}
|
||||
{% if status == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
|
||||
</a>
|
||||
</div>
|
||||
@ -52,19 +57,28 @@
|
||||
|
||||
<div class="col-auto">
|
||||
<div class="px-2 d-print-none">
|
||||
{% trans "Sort" %}
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{% trans "Sort" %}
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item d-flex justify-content-between" href="{% url 'core:plugin_list' %}?status=x">
|
||||
<a class="dropdown-item d-flex justify-content-between" href="{% url 'core:plugin_list' %}?sort=az">
|
||||
{% trans "By Name (A-Z)" %}
|
||||
{% if sort == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
|
||||
</a>
|
||||
<a class="dropdown-item d-flex justify-content-between" href="{% url 'core:plugin_list' %}?sort=x">
|
||||
<a class="dropdown-item d-flex justify-content-between" href="{% url 'core:plugin_list' %}?sort=za">
|
||||
{% trans "By Name (Z-A)" %}
|
||||
{% if sort == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
|
||||
</a>
|
||||
<a class="dropdown-item d-flex justify-content-between" href="{% url 'core:plugin_list' %}?sort=updated">
|
||||
{% trans "By updated date" %}
|
||||
{% if sort == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
|
||||
</a>
|
||||
<a class="dropdown-item d-flex justify-content-between" href="{% url 'core:plugin_list' %}?sort=published">
|
||||
{% trans "By published date" %}
|
||||
{% if sort == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user