mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Add a smarter work-around for the change-list-results hack
This commit is contained in:
		| @@ -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 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 Document | ||||
|  | ||||
|  | ||||
| register = Library() | ||||
|  | ||||
|  | ||||
| @register.simple_tag(takes_context=True) | ||||
| def change_list_results(context): | ||||
| @register.inclusion_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))} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Daniel Quinn
					Daniel Quinn