From ef9747be6d50d536c149d31e978b61e2381baba3 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Tue, 1 Dec 2015 22:31:52 -0500 Subject: updated site to work with django 1.9's new admin look --- app/lib/templatetags/templatetags/admin_reorder.py | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/lib/templatetags/templatetags/admin_reorder.py (limited to 'app/lib') diff --git a/app/lib/templatetags/templatetags/admin_reorder.py b/app/lib/templatetags/templatetags/admin_reorder.py new file mode 100644 index 0000000..83ccf9e --- /dev/null +++ b/app/lib/templatetags/templatetags/admin_reorder.py @@ -0,0 +1,45 @@ +from django.template.base import Node +from django.conf import settings +from django import template + +# Get template.Library instance +register = template.Library() + + +class AppOrderNode(Node): + """ + Reorders the app_list and child model lists on the admin index page. + """ + def render(self, context): + if 'app_list' in context: + app_list = list(context['app_list']) + ordered = [] + # look at each app in the user order + for app in settings.ADMIN_REORDER: + app_name, app_models = app[0], app[1] + # look at each app in the orig order + for app_def in app_list: + if app_def['name'] == app_name: + model_list = list(app_def['models']) + mord = [] + # look at models in user order + for model_name in app_models: + # look at models in orig order + for model_def in model_list: + if model_def['name'] == model_name: + mord.append(model_def) + model_list.remove(model_def) + break + mord[len(mord):] = model_list + ordered.append({'app_url': app_def['app_url'], + 'models': mord, 'name': app_def['name']}) + app_list.remove(app_def) + break + ordered[len(ordered):] = app_list + context['app_list'] = ordered + return '' + + +def app_order(parser, token): + return AppOrderNode() +var = register.tag(app_order) -- cgit v1.2.3-70-g09d2