You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As stated in #78, MenuItem's __init__() adds all additionally added kwargs as instance variables. This is great for new args lico icon etc., as long as they are "static", meaning they do not change over time in the template's context.
There are many variables I can think of (even icon!) like
badge (which should return e.g. a number of new emails), or
disabled (which should be true if a certain condition is met)
...
where you would need to add it to MenuItem, and it would be easy with kwargs, but MenuItem doesn't check if it is callable.
So I would propose to
put kwargs in a dict self.kwargs to have a reference later
nstead of making reference vars of them in the first place, do this after 1., to hold the same reference. Please correct me if this is not correct in Python...
(untested, just as idea here)
def__init__(..., **kwargs)
# ...self.kwargs=kwargs# keep a link of all kwargs in the instance, for convenience/template contextforkinself.kwargs:
setattr(self, k, self.kwargs[k])
defprocess(self, request):
# ...# if kwargs are callable, call them and save the results in the actual instance variablesforkey, valueinself.kwargs:
ifcallable(value):
setattr(self, k, self.kwargs[k]())
The text was updated successfully, but these errors were encountered:
I don't want to create another issue: This should also be applied to the url attr, which is a "core" attribute and not dynamicaly generated using kwargs: url should be potentially callable too.
use case: I want to point to a URL like /person/<int:pk/edit/ in a menu item. The only way I can think of is to subclass MenuItem again and add the same functionality like for the title attr, to let users link to /person/{{request.user.id}}/edit, which is generated in a callable.
As stated in #78, MenuItem's
__init__()
adds all additionally added kwargs as instance variables. This is great for new args licoicon
etc., as long as they are "static", meaning they do not change over time in the template's context.There are many variables I can think of (even
icon
!) likebadge
(which should return e.g. a number of new emails), ordisabled
(which should be true if a certain condition is met)where you would need to add it to MenuItem, and it would be easy with
kwargs
, but MenuItem doesn't check if it is callable.So I would propose to
self.kwargs
to have a reference later(untested, just as idea here)
The text was updated successfully, but these errors were encountered: