Select all - admin change list

544 views
Skip to first unread message

Josh Cartmell

unread,
Apr 20, 2012, 7:53:24 PM4/20/12
to mezzani...@googlegroups.com
On a default Django admin change list page there is a checkbox in the upper left to select all items on the page (clicking it then allows you to click a link which selects all items in the list, not just the current page).

In Mezzanine we do not have either of these.  I am guessing it is related to Grappelli.  Is there anything to be done for this or does anyone know of a workaround?  It would be very useful as I am working on excel data export for a custom app that is integrated with a Mezzanine based site.

Stephen McDonald

unread,
Apr 21, 2012, 2:55:44 AM4/21/12
to mezzani...@googlegroups.com
Not sure what's involved but it'd be great to get this working.

I suppose in the meantime you could create a separate action called "export all" - although I have a vague recollection of the actions not triggering if there aren't any rows selected. If that's the case you could possibly get around it with a bit of JS that selects all on the page when export all is chosen.


On Sat, Apr 21, 2012 at 9:53 AM, Josh Cartmell <joshc...@gmail.com> wrote:
On a default Django admin change list page there is a checkbox in the upper left to select all items on the page (clicking it then allows you to click a link which selects all items in the list, not just the current page).

In Mezzanine we do not have either of these.  I am guessing it is related to Grappelli.  Is there anything to be done for this or does anyone know of a workaround?  It would be very useful as I am working on excel data export for a custom app that is integrated with a Mezzanine based site.



--
Stephen McDonald
http://jupo.org

Josh Cartmell

unread,
Apr 22, 2012, 2:10:17 AM4/22/12
to mezzani...@googlegroups.com
Ill probably look into this a bit more soon here is what I have found so far:
http://code.google.com/p/django-grappelli/issues/detail?id=157 (apparently the select all was added in grappelli 2.1)

Josh Cartmell

unread,
Apr 23, 2012, 8:00:14 PM4/23/12
to mezzani...@googlegroups.com
Ok after further research I think I have figured out what the problems are mostly:

first of all the grappelli-safe change_list.html needs everything from the {% if action_form %} to the {% endif %} here:
https://github.com/sehmaschine/django-grappelli/blob/master/grappelli/templates/admin/change_list.html#L20

then grappelli-safe's actions.html should look like this, although we may need to add the class "actions" to the div:
https://github.com/sehmaschine/django-grappelli/blob/master/grappelli/templates/admin/actions.html

finally actions.min.js should be updated like this:
https://github.com/sehmaschine/django-grappelli/blob/master/grappelli/static/grappelli/js/actions.min.js
I think the really important parts are at the end in $.fn.actions.defaults as the selectors are different since grappelli uses lists instead of spans.

If you do what I have outlined above you are given an option to select all immediately upon loading a change list.  It shouldn't actually show until you check the box that selects all on a page so there is still something not quite right.  If you check that box and then click select all it does work though.  Could somebody else give it a shot and see if they can figure out that problem?  I tested it by adding list_per_page in the BlogPostAdmin to 2 and then creating 3 test blog posts.

One other problem I noticed: when I created a fresh mezzanine project with mezzanine installed using easy_install into a clean virtualenv, change_list.html pulled many static resources from django rather than grappelli_safe.

In the template this:
{{ media }}
produced this:
    <script type="text/javascript" src="/static/admin/js/core.js"></script>
    <script type="text/javascript" src="/static/admin/js/admin/RelatedObjectLookups.js"></script>
    <script type="text/javascript" src="/static/admin/js/jquery.js"></script>
    <script type="text/javascript" src="/static/admin/js/jquery.init.js"></script>
    <script type="text/javascript" src="/static/admin/js/actions.min.js"></script>
so I deleted:
{{ media }}
and put this in its place:
    <script type="text/javascript" src="/static/grappelli/js/core.js"></script>
    <script type="text/javascript" src="/static/grappelli/js/admin/RelatedObjectLookups.js"></script>
    <script type="text/javascript" src="/static/grappelli/js/jquery.js"></script>
    <script type="text/javascript" src="/static/grappelli/js/jquery.init.js"></script>
    <script type="text/javascript" src="/static/grappelli/js/actions.min.js"></script>

That worked for testing out the changes I listed above but is obviously not the best solution moving forward.  Is anyone else seeing that?

That was a bit long so if anything doesn't make sense let me know and I will try to clear things up as best I can.

Josh Cartmell

unread,
Apr 24, 2012, 12:54:05 PM4/24/12
to mezzani...@googlegroups.com
The short of it is here is a repo with changes to grappelli-safe which I believe fix the problem:
https://bitbucket.org/joshcartme/grappelli-safe/changeset/8d4bdf3ff307

One thing to note is that I removed {{ media }} and hardcoded the files that should be there so the media issue should be debugged a bit further to avoid this.

The long of it is this:
So I think I have a complete solution now.  You have to do what I listed above and then add then set the following 3 selectors to display: None:
https://github.com/sehmaschine/django-grappelli/blob/master/grappelli/static/grappelli/css/components.css#L809

I stuck it in changelist.css as that seemed the most logical place although as far as I can tell Grappelli has refactored some things and no longer has a changelist.css.  Similar to that I noticed that Grappelli's actions.js is empty and everything is in actions.min.js.  It may be a good idea to do something similar with grappelli_safe, I found it a bit confusing that grappelli_safe contained both and they are not related (i.e. actions.min.js is not a minified version of the actions.js contained in grappelli_safe).

One other change I made to actions.html is to update the forloop to this:
{% for field in action_form %}<label>{{ field }}</label>{% endfor %}

I'm still see the issue where the {{ media }} context variable references django static resources rather than grappelli's.  I have not modified anything in the default project (created using mezzanine_project from Mezzanine pulled from PyPi yesterday) and have only modified grappelli with the changes listed above and mezzanine by adding list_per_page to the blogpost admin.  Any thoughts or reproductions of that would be appreciated.

Comments and thought are welcome and appreciated.

Stephen McDonald

unread,
Apr 24, 2012, 1:04:36 PM4/24/12
to mezzani...@googlegroups.com
Thanks for working on this Josh. I'll look at it tomorrow hopefully and see if I can get it all merged in.

Josh Cartmell

unread,
Apr 24, 2012, 1:37:34 PM4/24/12
to mezzani...@googlegroups.com
Thanks Steve!  And no problem, I'm glad I can contribute back a bit.
I would definitely take a look at the {{ media }} issue mentioned above before merging it.  It could just be my system.  If I get a chance I'll see if I can reproduce it on another computer later on today.

Josh Cartmell

unread,
Apr 25, 2012, 12:33:59 AM4/25/12
to mezzani...@googlegroups.com
Just fyi I'm seeing the {{ media }} issue on another computer as well, it's odd though that I don't see it on the demo site.

Stephen McDonald

unread,
Apr 28, 2012, 11:09:00 PM4/28/12
to mezzani...@googlegroups.com
Works great Josh. I've merged it in and released it in 0.2.4

Thanks!

Josh Cartmell

unread,
Apr 29, 2012, 3:19:16 AM4/29/12
to mezzani...@googlegroups.com
Glad it works!  Did you have any ideas about the issue with the {{ media }} context variable I described?

Stephen McDonald

unread,
Apr 29, 2012, 3:20:45 AM4/29/12
to mezzani...@googlegroups.com
I took a quick look to make sure nothing else made use of it, to ensure we don't end up losing any files, and I didn't come across anything.

Ideally we could get it working, need to deep dive a bit more though. Not too fussed at the moment - main thing is we can select all again.

Josh Cartmell

unread,
Apr 29, 2012, 3:25:26 AM4/29/12
to mezzani...@googlegroups.com
Ok cool, just to be clear you did notice the same thing?

I thought it was interesting that I wasn't seeing the same it on the demo site.  Does removing {{ media }} break things if people specify additional media in their own ModelAdmin class?

Stephen McDonald

unread,
Apr 29, 2012, 3:31:54 AM4/29/12
to mezzani...@googlegroups.com
I didn't try recreating it. I think it will break if people add media files via their admin class.

At a wild guess it might have changed with Django 1.4, and we might just need to access it differently.

Stephen McDonald

unread,
Apr 29, 2012, 3:51:00 AM4/29/12
to mezzani...@googlegroups.com
I just put {{ media }} back in (with all your other changes still intact) and all the JS files are rendered from it.

Stephen McDonald

unread,
Apr 29, 2012, 3:52:18 AM4/29/12
to mezzani...@googlegroups.com
Oh excuse me, they're showing but they're using /admin/ rather than /grappelli/ - so I get the same issue.

Stephen McDonald

unread,
Apr 29, 2012, 4:59:21 PM4/29/12
to mezzani...@googlegroups.com
Just found a spot where it falls apart - Mezzanine's settings app mezzanine.conf

In the admin it uses a form directly in the change list view, with css defined for media, so this is missing now.

Stephen McDonald

unread,
Apr 29, 2012, 5:26:40 PM4/29/12
to mezzani...@googlegroups.com
The difference is definitely between Django 1.3 and 1.4, so your changes didn't cause this.

Josh Cartmell

unread,
Apr 29, 2012, 10:19:25 PM4/29/12
to mezzani...@googlegroups.com
Thanks Steve, I was a bit lost on figuring out where it was breaking down and hadn't thought of 1.3 vs 1.4 issues.

Stephen McDonald

unread,
Apr 29, 2012, 10:23:05 PM4/29/12
to mezzani...@googlegroups.com
I'm not across the changes either, but ADMIN_MEDIA_PREFIX is now deprecated in 1.4, so need to dig in a bit deeper there - not just for this grappelli case but for Mezzanine in general.

Nathan Keller

unread,
May 11, 2013, 1:03:24 AM5/11/13
to mezzani...@googlegroups.com, st...@jupo.org
Did a solution for this make it into master? I'm still running into this issue. Cheers.

Nathan Keller

unread,
May 11, 2013, 4:38:35 AM5/11/13
to mezzani...@googlegroups.com, st...@jupo.org
Looks like dropping this file is solved the problem. 


Note: the current version of the file is not compatible with grappelli_safe, you should use the version from that commit. 
Reply all
Reply to author
Forward
0 new messages