Bookmarks functionality goes away with custom menu

Issue #28 resolved
Mark Cahill
created an issue

When using a custom menu, bookmarks functionality goes away. I tried adding

{{{

!python

self.children.append(BookmarkMenuItem()) }}}

to the menu.py, but was only able to show existing bookmarks. There is no star to create or remove bookmarks.

Comments (12)

  1. Mark Cahill reporter

    Python 2.6.5, Django 1.1.1, and development django-admin-tools. To repeat, simply run the admin command to create a new custom menu. The necessary code to create the bookmarks functionality is not included.

  2. David Jean Louis repo owner

    Hm, you are describing a different problem here: "the bookmark item is not included in the default custom menu.py".

    But if you added "self.children.append(BookmarkMenuItem())" the bookmark functionality should work as expected, right ?

    Also, the management commands are currently broken (I have a "template not found" error, this will be fixed soon) which makes me wonder what version you actually use ?

  3. Mark Cahill reporter

    I was able to get the management commands working by making the following change:

    In menu/management/commands/custommenu.py on line 18:

            open(dst, 'w').write(render_to_string('admin_tools/menu/menu.txt', {
    

    after appending the BookmarkMenuItem, I get a bookmarks menu, but no star appears. No bookmarks can be added or removed.

  4. David Jean Louis repo owner

    after appending the BookmarkMenuItem, I get a bookmarks menu, but no star appears.

    No bookmarks can be added or removed.

    Hmm, I cannot reproduce this problem :( It works for me.

    It would be great if you could look at this and come with a patch.

    Regards,

    -- David

  5. Mark Cahill reporter

    Maybe. Can you point me at the code in the core that handles the generation of that star (add/remove functionality)? Is it supposed to show up when the bookmarks menu is added?

  6. David Jean Louis repo owner

    Sure.

    The star should show up as long as the menu contains a BookmarkMenuItem (now renamed items.Bookmarks), the relevant code is in:

    admin_tools/menu/templatetags/admin_tools_menu_tags.py

    line 32.

  7. Mark Cahill reporter

    My menu (menu.children) looks like this: [<PyReports.admin_tools.menu.models.MenuItem object at 0x01689430>, <PyReports.admin_tools.menu.models.BookmarkMenuItem object at 0x01689E90>, <PyReports.admin_tools.menu.models.MenuItem object at 0x01689E10>, <PyReports.admin_tools.menu.models.MenuItem object at 0x01689C10>, <PyReports.admin_tools.menu.models.MenuItem object at 0x01689DB0>, <PyReports.admin_tools.menu.models.AppListMenuItem object at 0x01689970>, <PyReports.admin_tools.menu.models.AppListMenuItem object at 0x016896D0>]

    However, when I run that loop against it (c for c in menu.children if isinstance(c, BookmarkMenuItem)), I get an empty list. So somehow this line of code is not picking up custom instances somehow.

    If I change line 31 to the following, it works:

    if len([c for c in menu.children if type(c).__name__ == 'BookmarkMenuItem']) > 0:
    

    Now obviously this isn't a realistic or desirable solution, but it should help you narrow down why it's not working. I'm not familiar with isinstance and the caveats thereof. Is there a way to ensure that objects are recognized as instances of that class?

  8. David Jean Louis repo owner

    Oh ! well then it's normal. You seem to have modified the admin_tools namespace somehow, so : PyReports.admin_tools.menu.models.BookmarkMenuItem != admin_tools.menu.models.BookmarkMenuItem

    Just import admin_tools without no parent namespace, and everything should work again.

    Regards,

    -- David

  9. Mark Cahill reporter

    OK. I see. I had admin_tools installed within my application directory, so it was being imported within that namespace. I moved the admin_tools directory to my python path, and the star appeared. Thanks for helping me figure that out. At least this is documented for anyone else who runs into that problem.

  10. Log in to comment