Optimise menus by replacing unnecessary lambdas
flavour opened this issue · comments
e.g.
https://github.com/sahana/eden/blob/master/modules/s3menus.py#L1250
departments = lambda i: settings.get_hrm_vol_departments()
M("Department Catalog", f="department", check=departments)(
can be replaced by:
M("Department Catalog", f="department", check=settings.get_hrm_vol_departments)(
The lambda is currently necessary to change the argument signature
>>> M("test", f="test", check=settings.get_hrm_vol_departments).check_hook()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "applications/eden/modules/s3/s3navigation.py", line 498, in check_hook
if callable(condition) and not condition(self):
TypeError: get_hrm_vol_departments() takes exactly 1 argument (2 given)
Is there another refactor that should happen to make the lambdas unnecessary?
That's right - the check-hook does currently receive the menu item itself as argument, which would allow to inspect it, e.g. check the status of its parent|child|sibling nodes.
This is very handy a feature and currently used, e.g. in DRKCM to activate an alternative menu entry when its following-sibling is disabled due to lack of permissions. So I'd want to keep this argument.
That means, we need to keep the lambdas too :/ my bad, I brought up the idea that they could be removed, but now I see that this was wrong. Sorry for that.