Skip to content

Matching this when multiple URL matches fails #287

Open
@dwasyl

Description

@dwasyl

In continuing to setup this package I stumbled across a bug in how sitetree matches urls. When there are multiple matches to the same URL, sitetree only tries to match against the first possible url match, not the entire list.

With the code setup below, if I was on a page say: /books/1/ the page would print the side menu setup below just fine, however, if I was on /library/books/1/ the sitetree_menu include for this-parent-siblings doesn't find a match for this (and so displays nothing). When I comment out the first matching URL, the /library/books/1/ matches this just fine.

As a fix, I think sitetree should attempting matching this against all possible urls, not just the first one returned.

Here's the setup:
An url structure something like this:

re_path(r'^books/(?P<pk>\d+)/$', views.book_view, name='book_view'),
re_path(r'^library/books/(?P<pk>\d+)/$', views.book_view, name='book_view'),

A dynamic menu setup like this:

item('Library', 'library_home', children=[
    item("Add Book", "book_add"),
    item("Book List", "book_list"),
    item("{{ obj }}", "book_view obj.pk"),
])

Sidebar menus are display with the menu templatetag:
{% sitetree_menu from "main-tree" include "this-parent-siblings" %}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions