joshourisman / django-tablib

django-tablib is a helper library for Django that allows Django models to be used to generate tablib datasets with introspection of the fields on the models if no headers are provided. If headers are provided they can reference any attribute, fields, properties, or methods on the model.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changes to support Django 1.4 changes to ChangeList

ryankicks opened this issue · comments

Django 1.4 changes ChangeList to accept self.admin_site as a parameter. Also, 1.4 has ChangeList.get_query_set() take in request.

Simple code fix to support versioning.

IMPORT DJANGO:

import django

CHANGE get_tablib_queryset() AS FOLLOWS:

def get_tablib_queryset(self, request):
    if django.VERSION >= (1, 4):
        cl = ChangeList(request,
            self.model,
            self.list_display,
            self.list_display_links,
            self.list_filter,
            self.date_hierarchy,
            self.search_fields,
            self.list_select_related,
            self.list_per_page,
            self.list_editable,
            self.admin_site,
            self,
        )
        return cl.get_query_set(request)
    else:
        cl = ChangeList(request,
            self.model,
            self.list_display,
            self.list_display_links,
            self.list_filter,
            self.date_hierarchy,
            self.search_fields,
            self.list_select_related,
            self.list_per_page,
            self.list_editable,
            self,
        )
        return cl.get_query_set()

FWIW : You're right that django 1.4 changes the arguments for ChangeList, but I think you got them wrong. I don't see where it receives the admin_site, here is the code in django 1.4:

class ChangeList(object):
    def __init__(self, request, model, list_display, list_display_links,
            list_filter, date_hierarchy, search_fields, list_select_related,
            list_per_page, list_max_show_all, list_editable, model_admin):

The real difference with 1.3 is the inclusion of list_max_show_all after list_per_page.

You're absolutely right. Sorry; still getting familiar with the Django source. Here's the updated fix for django-tablib:

IMPORT DJANGO:

import django

CHANGE get_tablib_queryset() AS FOLLOWS:

def get_tablib_queryset(self, request):
    if django.VERSION >= (1, 4):
        cl = ChangeList(request,
            self.model,
            self.list_display,
            self.list_display_links,
            self.list_filter,
            self.date_hierarchy,
            self.search_fields,
            self.list_select_related,
            self.list_per_page,
            self.list_max_show_all,
            self.list_editable,
            self,
        )
        return cl.get_query_set(request)
    else:
        cl = ChangeList(request,
            self.model,
            self.list_display,
            self.list_display_links,
            self.list_filter,
            self.date_hierarchy,
            self.search_fields,
            self.list_select_related,
            self.list_per_page,
            self.list_editable,
            self,
        )
        return cl.get_query_set()

Would like to see that fixed.

Definitely on my todo list! Been busy with other stuff, and haven't had an excuse to dust off django-tablib for work lately, but I'm hoping to get to this very soon!

Thanks! Really looking forward to it!

Yeah, I'd use django-tablib if it had this simple fix -- when will this go in?