14731 sort / status

This commit is contained in:
Arthur Hanson 2024-07-09 14:23:59 +07:00
parent 61106113db
commit 36e268300f
3 changed files with 65 additions and 10 deletions

View File

@ -81,3 +81,29 @@ class ObjectChangeActionChoices(ChoiceSet):
(ACTION_UPDATE, _('Updated'), 'blue'), (ACTION_UPDATE, _('Updated'), 'blue'),
(ACTION_DELETE, _('Deleted'), 'red'), (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'),
)

View File

@ -2,8 +2,10 @@ import importlib
import importlib.util import importlib.util
import json import json
import platform import platform
import pytz
import requests import requests
from datetime import datetime
from django import __version__ as DJANGO_VERSION from django import __version__ as DJANGO_VERSION
from django.apps import apps from django.apps import apps
from django.conf import settings from django.conf import settings
@ -38,6 +40,7 @@ from utilities.htmx import htmx_partial
from utilities.query import count_related from utilities.query import count_related
from utilities.views import ContentTypePermissionRequiredMixin, GetRelatedModelsMixin, register_model_view from utilities.views import ContentTypePermissionRequiredMixin, GetRelatedModelsMixin, register_model_view
from . import filtersets, forms, tables from . import filtersets, forms, tables
from .choices import PluginSortChoices, PluginStatusChoices
from .models import * from .models import *
from .tables import CertifiedPluginTable from .tables import CertifiedPluginTable
@ -673,8 +676,8 @@ def get_local_plugins(plugins):
'tag_line': plugin_config.description, 'tag_line': plugin_config.description,
'description_short': plugin_config.description, 'description_short': plugin_config.description,
'author': plugin_config.author or _('Unknown Author'), 'author': plugin_config.author or _('Unknown Author'),
'version': plugin_config.version, 'created': datetime.min.replace(tzinfo=pytz.UTC),
'icon': None, 'updated': datetime.min.replace(tzinfo=pytz.UTC),
'is_local': True, 'is_local': True,
'is_installed': True, 'is_installed': True,
'is_certified': False, 'is_certified': False,
@ -753,8 +756,8 @@ def get_catalog_plugins(plugins):
'tag_line': data['tag_line'], 'tag_line': data['tag_line'],
'description_short': data['description_short'], 'description_short': data['description_short'],
'author': data['author']['name'] or _('Unknown Author'), 'author': data['author']['name'] or _('Unknown Author'),
'version': 'x', 'created': datetime.fromisoformat(data['created_at']),
'icon': None, 'updated': datetime.fromisoformat(data['updated_at']),
'is_local': False, 'is_local': False,
'is_installed': False, 'is_installed': False,
'is_certified': data['release_latest']['is_certified'], 'is_certified': data['release_latest']['is_certified'],
@ -783,10 +786,22 @@ class PluginListView(UserPassesTestMixin, View):
return self.request.user.is_staff return self.request.user.is_staff
def get(self, request): 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 = get_plugins()
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()] 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']) plugins = sorted(plugins, key=lambda d: d['name'])
return render(request, 'core/plugin_list.html', { return render(request, 'core/plugin_list.html', {

View File

@ -36,13 +36,18 @@
<div class="row"> <div class="row">
<div class="col-auto"> <div class="col-auto">
<div class="px-2 d-print-none"> <div class="px-2 d-print-none">
{% trans "Status" %}
<div class="dropdown"> <div class="dropdown">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{% trans "Status" %} {% trans "Status" %}
</button> </button>
<div class="dropdown-menu"> <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"> <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 %} {% if status == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
</a> </a>
</div> </div>
@ -52,19 +57,28 @@
<div class="col-auto"> <div class="col-auto">
<div class="px-2 d-print-none"> <div class="px-2 d-print-none">
{% trans "Sort" %}
<div class="dropdown"> <div class="dropdown">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{% trans "Sort" %} {% trans "Sort" %}
</button> </button>
<div class="dropdown-menu"> <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)" %} {% trans "By Name (A-Z)" %}
{% if sort == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %} {% if sort == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
</a> </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)" %} {% trans "By Name (Z-A)" %}
{% if sort == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %} {% if sort == log_threshold %}<span class="badge bg-green ms-auto"></span>{% endif %}
</a> </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> </div>
</div> </div>