django-sitetree icon indicating copy to clipboard operation
django-sitetree copied to clipboard

Dynamic Trees - missing something?

Open dwasyl opened this issue 4 years ago • 5 comments

Hey there,

First off, this seems like a really comprehensive tool, but I've run into some trouble with dynamic menus.

I have a django app, divided into two or three subapps. What I'd like to do is set up a menu in each of those (using the sitetrees.py file), which I've done. Then, in my main urls.py I've setup a basic:

register_dynamic_trees(
    compose_dynamic_tree('mainapp.subapp1', target_tree_alias="tree"),
    compose_dynamic_tree('mainapp.subapp2', target_tree_alias="tree"),
)

This is great and all, but how do I get the menu context in my template? I finally stumbled across sitetree_resync_apps which moved my dynamic menu into the database (I was trying to avoid that and keep everything in code), and it seems to have created each of my subapp sitetrees as separate menus. The docs speak to this in general, but I wasn't seeing how it came together.

Any tips on what I was missing or how I can create these as 'submenus'?

dwasyl avatar Apr 01 '20 23:04 dwasyl

Hi,

You may want to try to attach your submenus to some parent tree items with the help of parent_tree_item_alias. See: https://github.com/idlesign/django-sitetree/blob/c932cd35869913ad611d0c31c244f8a4ce61dea2/sitetree/tests/test_dynamic.py#L74

idlesign avatar Apr 02 '20 03:04 idlesign

Thanks @idlesign I hadn't gone through all the tests. As a suggestion on the docs, it would be really handy to see more of the 'full picture', i.e. Shipping sitetrees with your apps gets into dynmaic trees a bit, but the code examples have references to other objects (like main) and seeing it all together would have been helpful.

In the end I didn't manage to get it picking up dynamic trees from the sub apps and attaching them, but I just defined it all in my main app tree.

I know this is the wrong spot for it, but is it possible to have items that only appear when you are on the page? I wanted this for pages that have an item name in them (i.e. View {{ model.name }}).

Thanks for pointing me in the right direction.

dwasyl avatar Apr 14 '20 18:04 dwasyl

  1. Thank you for the hint on docs. WIll improve it when I had time.
  2. Yes, if I understand you need correctly. First make your main menu shallow (render only certain level or levels, excluding levels with tree items for models). Second make additional menu rendering only subitems of current item (that would be models' tree items). But if you want a tree item generation for every model instance, I would advise you against it for the reason of performance.

idlesign avatar Apr 15 '20 01:04 idlesign

Thanks, maybe it wasn't entirely clear, I'm using it for a sidebar with relative position so for example, given this structure:

Home -
           - Section A
               - Section A Sub Section 1
                   - Section A Sub Section 1 List
                   - Section A Sub Section 1 Information
               - Section A Sub Section 2
           - Section B
               - Section B List
               - Section B Information

When I'm on the Section A page, the menu I currently get is:

Section A Sub Section 1
Section A Sub Section 2

When I'm on Section A Sub Section 1 List page, the menu I currently generate is:

Section A Sub Section 1
    - Section A Sub Section 1 List (active)
    - Section A Sub Section 1 Information 
Section A Sub Section 2

I get this from using sitetree_menu with include "this-parent-siblings" which works great. However, I'd like to have some "ghost" items on the menu, for example:

               - Section A Sub Section 1
                   - Section A Sub Section 1 List
                   - Section A Sub Section 1 Item Edit: {{ item.name }}
                   - Section A Sub Section 1 Information

But, this new item, I only want appearing when the page has an item object and I'm on that page, otherwise it's just sitting there improperly rendered and confusing to a user. This way when I'm on Section A Sub Section 1 List this new Item Edit menu item wouldn't appear as part of this-parent-siblings, but when I'm on a Section A Sub Section 1 Item Edit: {{ item.name }} page it would appear.

This seems fairly common so it's likely possible, I just couldn't track it down. Any chance of pointing me in the right direction?

dwasyl avatar Apr 15 '20 22:04 dwasyl

You may try to use a custom template for your submenu which won't render an item if it's url is not resolved.

idlesign avatar Apr 16 '20 00:04 idlesign

Considered closed.

idlesign avatar Dec 22 '23 02:12 idlesign