Skip to content

Commit

Permalink
Fix KAT-alogus table view (#1795)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Klopper <[email protected]>
  • Loading branch information
dekkers and underdarknl authored Sep 18, 2023
1 parent fa952f4 commit 1bc3d2c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
8 changes: 4 additions & 4 deletions rocky/katalogus/templates/partials/katalogus_toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

{% if object_list %}
<div class="horizontal-view horizontal-scroll toolbar">
<a href="{% url 'katalogus' organization_code=organization.code view="gridview" %}"
class="button icon ti-layout-grid {% if view.kwargs.view == "tableview" %}ghost{% endif %}">{% translate "Gridview" %}</a>
<a href="{% url 'katalogus' organization_code=organization.code view="tableview" %}"
class="button icon ti-menu-2 {% if view.kwargs.view != "tableview" %}ghost{% endif %}">{% translate "Tableview" %}</a>
<a href="{% url url_name organization_code=organization.code view_type="grid" %}?{{ request.GET.urlencode }}"
class="button icon ti-layout-grid {% if view_type == "table" %}ghost{% endif %}">{% translate "Gridview" %}</a>
<a href="{% url url_name organization_code=organization.code view_type="table" %}?{{ request.GET.urlencode }}"
class="button icon ti-menu-2 {% if view_type != "table" %}ghost{% endif %}">{% translate "Tableview" %}</a>
</div>
{% endif %}
2 changes: 1 addition & 1 deletion rocky/katalogus/templates/partials/plugins.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% load i18n %}
{% load static %}

{% if view.kwargs.view == "tableview" %}
{% if view_type == "table" %}
<div class="horizontal-scroll">
<table class="plugins">
<caption>{% translate "Plugins overview:" %}</caption>
Expand Down
6 changes: 3 additions & 3 deletions rocky/katalogus/templates/partials/plugins_navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<nav class="tabs" aria-label="{% translate "Plugins Navigation" %}">
<ul>
<li {% if active == "all" %}aria-current="page"{% endif %}>
<a href="{% url 'katalogus' organization.code %}">{% translate "All" %}</a>
<a href="{% url 'katalogus' organization.code view_type %}">{% translate "All" %}</a>
</li>
<li {% if active == "boefjes" %}aria-current="page"{% endif %}>
<a href="{% url 'boefjes_list' organization.code %}">{% translate "Boefjes" %}</a>
<a href="{% url 'boefjes_list' organization.code view_type %}">{% translate "Boefjes" %}</a>
</li>
<li {% if active == "normalizers" %}aria-current="page"{% endif %}>
<a href="{% url 'normalizers_list' organization.code %}">{% translate "Normalizers" %}</a>
<a href="{% url 'normalizers_list' organization.code view_type %}">{% translate "Normalizers" %}</a>
</li>
<li {% if active == "about-plugins" %}aria-current="page"{% endif %}>
<a href="{% url 'about_plugins' organization.code %}">{% translate "About plugins" %}</a>
Expand Down
6 changes: 3 additions & 3 deletions rocky/katalogus/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

urlpatterns = [
path("", KATalogusView.as_view(), name="katalogus"),
path("view/<view>/", KATalogusView.as_view(), name="katalogus"),
path("view/<view_type>/", KATalogusView.as_view(), name="katalogus"),
path(
"settings/",
KATalogusSettingsView.as_view(),
Expand All @@ -27,12 +27,12 @@
name="confirm_clone_settings",
),
path(
"plugins/boefjes/",
"plugins/boefjes/<view_type>/",
BoefjeListView.as_view(),
name="boefjes_list",
),
path(
"plugins/normalizers/",
"plugins/normalizers/<view_type>/",
NormalizerListView.as_view(),
name="normalizers_list",
),
Expand Down
29 changes: 20 additions & 9 deletions rocky/katalogus/views/katalogus.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def setup(self, request, *args, **kwargs):

def get_initial(self) -> Dict[str, Any]:
initial = super().get_initial()
initial["sorting_options"] = self.request.GET.get("sorting_options")
initial["filter_options"] = self.request.GET.get("filter_options")
initial["sorting_options"] = self.request.GET.get("sorting_options", "a-z")
initial["filter_options"] = self.request.GET.get("filter_options", "all")
return initial

def filter_katalogus(self, queryset):
Expand Down Expand Up @@ -54,6 +54,8 @@ def sort_alphabetic_ascending(self, queryset):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["view_type"] = self.kwargs.get("view_type", "grid")
context["url_name"] = self.request.resolver_match.url_name
context["breadcrumbs"] = [
{
"url": reverse("katalogus", kwargs={"organization_code": self.organization.code}),
Expand All @@ -63,17 +65,15 @@ def get_context_data(self, **kwargs):
return context


class PluginListView(BaseKATalogusView):
def get_queryset(self):
queryset = self.sort_alphabetic_ascending(self.katalogus_client.get_plugins())
return self.filter_katalogus(queryset)


class KATalogusView(PluginListView):
class KATalogusView(BaseKATalogusView):
"""View of all plugins in KAT-alogus"""

template_name = "katalogus.html"

def get_queryset(self):
queryset = self.sort_alphabetic_ascending(self.katalogus_client.get_plugins())
return self.filter_katalogus(queryset)


class BoefjeListView(BaseKATalogusView):
"""Showing only Boefjes in KAT-alogus"""
Expand All @@ -97,3 +97,14 @@ def get_queryset(self):

class AboutPluginsView(OrganizationView, TemplateView):
template_name = "about_plugins.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["view_type"] = self.kwargs.get("view_type", "grid")
context["breadcrumbs"] = [
{
"url": reverse("katalogus", kwargs={"organization_code": self.organization.code}),
"text": _("KAT-alogus"),
},
]
return context
5 changes: 4 additions & 1 deletion rocky/tests/katalogus/test_katalogus.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from django.core.exceptions import PermissionDenied
from django.urls import resolve
from katalogus.client import KATalogusClientV1, parse_plugin
from katalogus.views.katalogus import AboutPluginsView, BoefjeListView, KATalogusView, NormalizerListView
from katalogus.views.katalogus_settings import ConfirmCloneSettingsView, KATalogusSettingsView
Expand Down Expand Up @@ -117,8 +118,10 @@ def test_katalogus_plugin_listing_no_enable_disable_perm(rf, client_member, mock
mock_requests.Session().get.return_value = mock_response
mock_response.json.return_value = get_plugins_data()

request = rf.get("/en/test/kat-alogus/")
request.resolver_match = resolve(request.path)
response = KATalogusView.as_view()(
setup_request(rf.get("katalogus"), client_member.user), organization_code=client_member.organization.code
setup_request(request, client_member.user), organization_code=client_member.organization.code
)
assert response.status_code == 200

Expand Down

0 comments on commit 1bc3d2c

Please sign in to comment.