mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Add a smarter work-around for the change-list-results hack
This commit is contained in:
parent
75251ad694
commit
35004f434b
@ -1,6 +0,0 @@
|
|||||||
{% load hacks %}
|
|
||||||
|
|
||||||
{# See documents.templatetags.hacks.change_list_results for an explanation #}
|
|
||||||
|
|
||||||
{% change_list_results %}
|
|
||||||
|
|
@ -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 %}
|
@ -1,41 +1,28 @@
|
|||||||
import os
|
from django.contrib.admin.templatetags.admin_list import (
|
||||||
|
result_headers,
|
||||||
from django.contrib import admin
|
result_hidden_fields,
|
||||||
|
results
|
||||||
|
)
|
||||||
from django.template import Library
|
from django.template import Library
|
||||||
from django.template.loader import get_template
|
|
||||||
|
|
||||||
from ..models import Document
|
|
||||||
|
|
||||||
|
|
||||||
register = Library()
|
register = Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.inclusion_tag("admin/documents/document/change_list_results.html")
|
||||||
def change_list_results(context):
|
def result_list(cl):
|
||||||
"""
|
"""
|
||||||
Django has a lot of places where you can override defaults, but
|
Copy/pasted from django.contrib.admin.templatetags.admin_list just so I can
|
||||||
unfortunately, `change_list_results.html` is not one of them. In fact,
|
modify the value passed to `.inclusion_tag()` in the decorator here. There
|
||||||
it's a downright pain in the ass to override this file on a per-model basis
|
must be a cleaner way... right?
|
||||||
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.
|
|
||||||
"""
|
"""
|
||||||
|
headers = list(result_headers(cl))
|
||||||
path = os.path.join(
|
num_sorted_fields = 0
|
||||||
os.path.dirname(admin.__file__),
|
for h in headers:
|
||||||
"templates",
|
if h['sortable'] and h['sorted']:
|
||||||
"admin",
|
num_sorted_fields += 1
|
||||||
"change_list_results.html"
|
return {'cl': cl,
|
||||||
)
|
'result_hidden_fields': list(result_hidden_fields(cl)),
|
||||||
|
'result_headers': headers,
|
||||||
if context["cl"].model == Document:
|
'num_sorted_fields': num_sorted_fields,
|
||||||
path = "admin/documents/document/change_list_results.html"
|
'results': list(results(cl))}
|
||||||
|
|
||||||
return get_template(path).render(context)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user