automatic menu link generation for model names in forms/tables not working

3 views
Skip to first unread message

alind

unread,
Feb 5, 2012, 3:21:26 AM2/5/12
to TurboGears
This technique for menu link generation is not working as the mount
point is changed and it is not necessary to provide plural form of
the table name as mount point.
For example if i put my mount point as all_movies instead of movies
when by model name is movie, then the links will not work as the they
still point to movies.

models = {}
for m in dir(model):
m = getattr(model, m)
if not inspect.isclass(m):
continue
try:
mapper = class_mapper(m)
models[m.__name__.lower()] = m
except:
pass

ref :
http://www.turbogears.org/2.1/docs/main/Extensions/Crud/index.html#menu-items

Alessandro Molina

unread,
Feb 5, 2012, 5:47:55 AM2/5/12
to turbo...@googlegroups.com
Menu autogeneration expects all the items to be plural and named on
the model itself, if you want to customize this behavior you need to
provide an empty menu_items and create the menu yourself inside the
master.html for example.

In this specific case as you named the controller 'all_movies' instead
of 'movies' you can simply solve the issue by using 'all_movie' as the
key of the menu items dictionary.

I can see that this is a limit, so I'll try to propose a fix for this
in tgext.crud that can be compatible with old behavior.

> --
> You received this message because you are subscribed to the Google Groups "TurboGears" group.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.
>

Alessandro Molina

unread,
Feb 5, 2012, 8:58:30 AM2/5/12
to turbo...@googlegroups.com
I did a change to tgext.crud to support custom menu_items links.
This should be a good solution to your issue as it makes possible to
create menu_items with custom links.

http://code.google.com/p/tgtools/source/detail?r=306c7bc4b75c030d097519300786244a7d4877fb&repo=tgext-crud

PS: I would like to have a review from Chris Perkins as he is the main
author of Crud extension, maybe there is a better way to achieve this
and I don't know it.

alind

unread,
Feb 10, 2012, 1:38:25 AM2/10/12
to TurboGears
Thanks Alessandro,
I am hoping for the changes to be in the main TG branch.

On Feb 5, 6:58 pm, Alessandro Molina <alessandro.mol...@gmail.com>
wrote:
> I did a change to tgext.crud to support custom menu_items links.
> This should be a good solution to your issue as it makes possible to
> create menu_items with custom links.
>
> http://code.google.com/p/tgtools/source/detail?r=306c7bc4b75c030d0975...
Reply all
Reply to author
Forward
0 new messages