summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/lib/templatetags/templatetags/admin_reorder.py45
-rw-r--r--app/projects/views.py4
2 files changed, 47 insertions, 2 deletions
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)
diff --git a/app/projects/views.py b/app/projects/views.py
index 39ae781..23500e0 100644
--- a/app/projects/views.py
+++ b/app/projects/views.py
@@ -1,6 +1,6 @@
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
-from django.db.models import get_model
+from django.apps import apps
from projects.shortcuts import render_to_geojson
from projects.models.natparks import NationalParks
@@ -17,7 +17,7 @@ projects = {
def detail(request, slug):
"""Projects by slug"""
name = projects[slug]
- model = get_model('projects', name)
+ model = apps.get_model('projects', name)
if slug == 'national-parks':
qs = model.objects.filter(visited__exact=True).order_by("-date_visited_begin")
else: