I putting together an interface where users can add pages to a site and have these pages indistinguishable from "hard-coded" pages/functions. However, I would have the best of both worlds and have very clean urls. Thus, I'm trying to avoid things like:
/application/controller/catchall_function/page/1/12 /application/controller/catchall_function?_page=books?title=12 And have something like: /application/controller/books/12 I know I could use routes to send everything to a function to process the response, but I was wondering about doing this with closures. Thanks, Miguel On Wed, Jul 6, 2011 at 1:57 PM, Massimo Di Pierro < massimo.dipie...@gmail.com> wrote: > Can you explain the goal? > > On Jul 6, 3:23 am, Miguel Lopes <mig.e.lo...@gmail.com> wrote: > > I'm experimenting with dynamically generating functions, aka 'actions' in > > controllers. However, I've been unsuccessful. I can use exec and closures > > successfully in regular Python code, but I can't make it work with > web2py. > > Any thoughts on how to achieve this? > > > > A closure example - FAILS in web2py: > > > > top_pages = db(db.page.id > 0).select() > > > > def add_actions(top_pages): > > > > for page in top_pages: > > > > def inneraction(msg): > > > > sidebar = None > > > > return dict(message=msg, sidebar=sidebar) > > > > inneraction.__name__ = page.link_name > > > > globals()[page.link_name] = inneraction > > > > add_actions(top_pages) > > > > A exec example - FAILS in web2py: > > > > ACTION_TEMPLATE = """ > > > > def NEW_ACTION(): > > > > sidebar = None > > > > return dict(message='s', sidebar=sidebar) > > > > """ > > > > top_pages = db(db.page.id > 0).select() > > > > def makePages(pages): > > > > for page in top_pages: > > > > exec ACTION_TEMPLATE > > > > NEW_ACTION.__name__ = page.link_name > > > > globals()[page.link_name] = NEW_ACTION > > > > makePages(pages) > > > > Miguel >