We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi,
I'ld like to bind a sub-menu part to the authenticated user (children).
children
I use a function to build this sub menu, and use the check trick to show / hide menu items according to the connected user.
check
def get_subscription_menu_items() -> list[MenuItem]: """ Get the domain subscription menu items. :return: A list of MenuItem objects representing subscription items. :rtype: list[MenuItem] """ output: list[MenuItem] = [] for idx, subscription in enumerate(models.DomainSubscription.objects.all(), 2): domains = [("domain", domain.pk) for domain in subscription.domains.all()] categories = [("category", category.pk) for category in subscription.categories.all()] # Combine into a single list all_parameters = domains + categories + [("title", subscription.title)] # Generate the query string query_string = urlencode(all_parameters) _url = reverse("publications:notice_list") if query_string: _url += f"?{query_string}" output.append( MenuItem( title=subscription.title, url=_url, icon="list", weight=idx * 10, check=lambda request: request.user == subscription.user, # noqa: B023 ) ) return output Menu.add_item( "main", MenuItem( title=_("Publications"), url=reverse("publications:manage_subscriptions"), icon="book", weight=10, children=[ MenuItem( title=_("Subscriptions"), url=reverse("publications:manage_subscriptions"), icon="book", weight=10, separator=True, ), ] + get_subscription_menu_items(), ), )
The problem with this approach is that I've to query all Foo instances, and filter "on display".
Foo
It could be simpler and nicer I could use directly the request object as parameter on a method / function that generates the menus.
request
Thanks for you great app !
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hi,
I'ld like to bind a sub-menu part to the authenticated user (
children
).I use a function to build this sub menu, and use the
check
trick to show / hide menu items according to the connected user.The problem with this approach is that I've to query all
Foo
instances, and filter "on display".It could be simpler and nicer I could use directly the
request
object as parameter on a method / function that generates the menus.Thanks for you great app !
The text was updated successfully, but these errors were encountered: