Skip to content

Commit

Permalink
Merge pull request #1390 from laws-africa/taxonomy-toc
Browse files Browse the repository at this point in the history
Use la-table-of-contents-controller for taxonomy tree admin
  • Loading branch information
longhotsummer authored Aug 4, 2023
2 parents b74045d + 057f108 commit 3bbd1ea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions peachjam/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import json
from datetime import date

from ckeditor.widgets import CKEditorWidget
Expand Down Expand Up @@ -546,6 +547,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):
Expand Down
11 changes: 11 additions & 0 deletions peachjam/templates/admin/tree_change_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends 'admin/tree_change_list.html' %}
{% load static i18n %}
{% block result_list %}
<script defer src="{% static 'js/app-prod.js' %}"></script>
<la-table-of-contents-controller
items="{{ tree_json }}"
title-filter-placeholder="{% trans "Search" %}"
collapse-all-btn-text="{% trans "Collapse all" %}"
expand-all-btn-text="{% trans "Expand all" %}"
></la-table-of-contents-controller>
{% endblock %}

0 comments on commit 3bbd1ea

Please sign in to comment.