From 057f108e469a9e0a819dabaa157e1d1ddc354da0 Mon Sep 17 00:00:00 2001 From: Greg Kempe Date: Sun, 23 Jul 2023 15:30:34 +0200 Subject: [PATCH] Use la-table-of-contents-controller for taxonomy tree admin --- peachjam/admin.py | 20 +++++++++++++++++++ .../templates/admin/tree_change_list.html | 11 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 peachjam/templates/admin/tree_change_list.html diff --git a/peachjam/admin.py b/peachjam/admin.py index 0a79f1999..fde3b44d5 100644 --- a/peachjam/admin.py +++ b/peachjam/admin.py @@ -1,4 +1,5 @@ import copy +import json from datetime import date from ckeditor.widgets import CKEditorWidget @@ -532,6 +533,25 @@ class TaxonomyAdmin(TreeAdmin): form = movenodeform_factory(Taxonomy, TaxonomyForm) readonly_fields = ("slug",) inlines = [EntityProfileInline] + # prevent pagination + list_per_page = 1_000_000 + + def changelist_view(self, request, extra_context=None): + resp = super().changelist_view(request, extra_context) + + def fixup(item): + item["title"] = item["data"]["name"] + item["href"] = reverse("admin:peachjam_taxonomy_change", args=[item["id"]]) + for kid in item.get("children", []): + fixup(kid) + + # grab the tree and turn it into something la-table-of-contents-controller understands + tree = self.model.dump_bulk() + for x in tree: + fixup(x) + resp.context_data["tree_json"] = json.dumps(tree) + + return resp class CoreDocumentAdmin(DocumentAdmin): diff --git a/peachjam/templates/admin/tree_change_list.html b/peachjam/templates/admin/tree_change_list.html new file mode 100644 index 000000000..28417a532 --- /dev/null +++ b/peachjam/templates/admin/tree_change_list.html @@ -0,0 +1,11 @@ +{% extends 'admin/tree_change_list.html' %} +{% load static i18n %} +{% block result_list %} + + +{% endblock %}