A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Add a smarter work-around for the change-list-results hack
Daniel Quinn35004f434b90
diff --git a/src/documents/templates/admin/change_list_results.html b/src/documents/templates/admin/change_list_results.htmldeleted file mode 100644index 35288ccd0..000000000--- a/src/documents/templates/admin/change_list_results.html+++ /dev/null@@ -1,6 +0,0 @@-{% load hacks %}--{# See documents.templatetags.hacks.change_list_results for an explanation #}--{% change_list_results %}-diff --git a/src/documents/templates/admin/documents/document/change_list.html b/src/documents/templates/admin/documents/document/change_list.htmlnew file mode 100644index 000000000..dcfb8a979--- /dev/null+++ b/src/documents/templates/admin/documents/document/change_list.html@@ -0,0 +1,12 @@+{% extends 'admin/change_list.html' %}+++{% load admin_actions from admin_list%}+{% load result_list from hacks %}+++{% block result_list %}+ {% if action_form and actions_on_top and cl.show_admin_actions %}{% admin_actions %}{% endif %}+ {% result_list cl %}+ {% if action_form and actions_on_bottom and cl.show_admin_actions %}{% admin_actions %}{% endif %}+{% endblock %}diff --git a/src/documents/templatetags/hacks.py b/src/documents/templatetags/hacks.pyindex c8229cbb9..908e173ee 100644--- a/src/documents/templatetags/hacks.py+++ b/src/documents/templatetags/hacks.py@@ -1,41 +1,28 @@-import os--from django.contrib import admin+from django.contrib.admin.templatetags.admin_list import (+ result_headers,+ result_hidden_fields,+ results+)from django.template import Library-from django.template.loader import get_template--from ..models import Documentregister = Library()[email protected]_tag(takes_context=True)-def change_list_results(context):[email protected]_tag("admin/documents/document/change_list_results.html")+def result_list(cl):"""- Django has a lot of places where you can override defaults, but- unfortunately, `change_list_results.html` is not one of them. In fact,- it's a downright pain in the ass to override this file on a per-model basis- and this is the cleanest way I could come up with.-- Basically all we've done here is defined `change_list_results.html` in an- `admin` directory which globally overrides that file for *every* model.- That template however simply loads this templatetag which determines- whether we're currently looking at a `Document` listing or something else- and loads the appropriate file in each case.-- Better work arounds for this are welcome as I hate this myself, but at the- moment, it's all I could come up with.+ Copy/pasted from django.contrib.admin.templatetags.admin_list just so I can+ modify the value passed to `.inclusion_tag()` in the decorator here. There+ must be a cleaner way... right?"""-- path = os.path.join(- os.path.dirname(admin.__file__),- "templates",- "admin",- "change_list_results.html"- )-- if context["cl"].model == Document:- path = "admin/documents/document/change_list_results.html"-- return get_template(path).render(context)+ headers = list(result_headers(cl))+ num_sorted_fields = 0+ for h in headers:+ if h['sortable'] and h['sorted']:+ num_sorted_fields += 1+ return {'cl': cl,+ 'result_hidden_fields': list(result_hidden_fields(cl)),+ 'result_headers': headers,+ 'num_sorted_fields': num_sorted_fields,+ 'results': list(results(cl))}