unfoldadmin / django-unfold

Modern Django admin theme for seamless interface development
https://unfoldadmin.com
MIT License
1.04k stars 96 forks source link

The sidebar navigation link callback gets called once, and the request probably gets cached #356

Open summerthe opened 3 weeks ago

summerthe commented 3 weeks ago

Hi @lukasvinclav this issue is related to #300 where the request was getting cached.

I have a link callback in the sidebar navigation. The URL path of it changes based on the type of user. But there are possibly two problems:

def reverse_callback(request):
    print("request.user.is_superuser",request.user.is_superuser)
    if request.user.is_superuser:
        return reverse_lazy("admin:formula_driver_changelist")
    else:
        return reverse_lazy("admin:auth_group_changelist")

--------
{
 "title": _("Drivers"),
 "icon": "sports_motorsports",
 "link": reverse_callback,
}

I have reproduced this issue in Formula Fork with latest unfold version 0.22. Check here https://github.com/summerthe/formula/commit/b23d552a3e1d17068aef6bbc105413f682950d43

As a fix, for the superadmin, the callback should return the driver's URL with a print in the terminal. For the staff user group url and print in the terminal on each request.