idlesign / django-sitetree

Reusable application for Django introducing site tree, menu and breadcrumbs navigation elements.
http://github.com/idlesign/django-sitetree
BSD 3-Clause "New" or "Revised" License
348 stars 130 forks source link

Mapping nested entities to bread crumbs #316

Closed vanderzielj closed 8 months ago

vanderzielj commented 8 months ago

Hi folks,

I am hoping someone can help me with this issue. I would like to know how to represent nested regular expression paths with django-sitetree Breadcrumbs. I have been unable to configure a Tree item that will result in the display of breadcrumbs for the Asset Detail View shown last in the (re_path) URLS below. I've attached a dump of my tree-site JSON to this message.

The following breadcrumbs work: http://localhost:8000/orgs/,http://localhost:8000/orgs/3 and http://localhost:8000/orgs/3/assets/. The breadcrumb for the last url show is displayed as "MyApp > Organizations > Famous Org > Assets"

However, when the get_tree_current_item tries to match against the URL for asset detail - e.g. http://localhost:8000/orgs/4/assets/4 - it finds no match. I would like the breadcrumb to be, for example, "MyApp > Organizations > Onward Trucking > Assets > Peterbilt #4" where the organization with id #4 is "Onward Trucking" and the asset of that organization with the id 4 is "Peterbilt #4"

The URLs for the top three items of my tree (the nesting goes down another couple of levels):

    # Organizations
    path(
        "orgs/",
        my.OrganizationTableView.as_view(),
        name="organization_list",
    ),
    re_path(
        r"^orgs/(?P<pk>[0-9]+)$",
        my.OrganizationDetailView.as_view(),
        name="organization_detail",
    ),
    # Assets
    re_path(
        r"^(?:orgs/(?P<org_id>[0-9]+)/)?assets/$",
        my.AssetTableView.as_view(),
        name="asset_list",
    ),
    re_path(
        r"^(?:orgs/(?P<org_id>[0-9]+)/)?assets/(?P<pk>[0-9]+)$",
        my.AssetDetailView.as_view(),
        name="asset_detail",
    )

As you may observe, the url structure follows something like 'orgs/{org_id}/assets/{asset_id}/systems/{system_id}` where each step further along the URL path represents a child item of the preceding one.

assetstree.json

idlesign commented 8 months ago

Hi,

My guess is that you have no organization variable passed into your template context for asset_detail. Thus neither asset_list nor organization_detail chunks of your breadcrumbs could be resolved.

vanderzielj commented 8 months ago

That makes sense. However, I decided against this package due to it's complexity. Though it seems like the right approach - taking advantage of Django infrastructure - it seems to require too much assumed knowledge for a new Django developer like myself. At least based on the ratings and questions other developers seem to have surmounted their difficulties. A day or so I decided to roll my own based on the context processor of Marcelo's django-dynamic-breadcrumbs package. I already have a working implementation after a day of work.

In any case, thanks for providing this package to the community.