Skip to content

Commit

Permalink
Now that Django has a getchangelist function, we don't need to hack a…
Browse files Browse the repository at this point in the history
…nymore
  • Loading branch information
Corey Oordt committed Dec 16, 2010
1 parent d1bf06b commit 039ba1f
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions editor/tree_editor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from django.conf import settings as django_settings
from django.contrib import admin
from django.contrib.admin.util import unquote
from django.contrib.admin.views.main import ChangeList
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseBadRequest
from django.utils import simplejson
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _

import settings

class TreeChangeList(ChangeList):
def get_ordering(self):
if isinstance(self.model_admin, TreeEditor):
return '', ''
return super(ChangeList, self).get_ordering()


def django_boolean_icon(field_val, alt_text=None, title=None):
"""
Return HTML code for a nice representation of true/false.
Expand Down Expand Up @@ -237,7 +245,13 @@ def _toggle_boolean(self, request):
d.append(b)

return HttpResponse(simplejson.dumps(d), mimetype="application/json")

#
def get_changelist(self, request, **kwargs):
"""
Returns the ChangeList class for use on the changelist page.
"""
return TreeChangeList

def changelist_view(self, request, extra_context=None, *args, **kwargs):
"""
Handle the changelist view, the django view for the model instances
Expand Down Expand Up @@ -308,19 +322,3 @@ def actions_column(self, page):
return u' '.join(self._actions_column(page))
actions_column.allow_tags = True
actions_column.short_description = _('actions')


# !!!: Hack alert! Patching ChangeList, check whether this still applies post Django 1.1
# Note: Patch lifted from http://code.djangoproject.com/ticket/4926 (ticket_4926_changelist_multifield_ordering.diff)

# By default, django only orders by first ordering field in admin. We patch
# up the ChangeList here so it returns "use default ordering" for any Page
# lookups. That way, we can order by tree_id + lft and get the site's natural
# page structure.
from django.contrib.admin.views import main
class ChangeList(main.ChangeList):
def get_ordering(self):
if isinstance(self.model_admin, TreeEditor):
return '', ''
return super(ChangeList, self).get_ordering()
main.ChangeList = ChangeList

0 comments on commit 039ba1f

Please sign in to comment.