Yes, I think a decorator is supposed to take a function (or callable) as an
argument and return a callable. In general, you should be able to chain
decorators.
Also, I assume you don't actually want to decorate your 'index' function
with your 'is_in_conference' decorator -- otherwise, it looks like it could
generate an infinite loop of redirects when 'current_conference' is not in
the session (because it will keep redirecting back to 'index', which will
prompt another redirect via the decorator).
Anthony
On Sunday, April 3, 2011 3:48:05 PM UTC-4, Massimo Di Pierro wrote:
> I think you want:
>
> def is_in_conference(f):
> if not session.current_conference:
> redirect(URL('default', 'index'))
> return f
>
> @is_in_conference()
> def index():
> """
> INFO: This page takes all the various things of the conference
> on
> to one page.
> """
> return dict()
>
> On Apr 3, 1:20 pm, Jason Brower <[email protected]> wrote:
> > I am making my first decorator and I want to make sure I do it right...
> > def is_in_conference():
> > if not session.current_conference:
> > redirect(URL('default', 'index'))
> >
> > @is_in_conference()
> > def index():
> > """
> > INFO: This page takes all the various things of the conference on
> > to one page.
> > """
> > return dict()
> >
> > Is this correct?
> > Also can I use two docorators?
>
> yes but mind that the order does matter.
>
> > For example:
> >
> > @is_in_conference()
> > @auth.is_logged_in()
> > def index():
> > """
> > INFO: This page takes all the various things of the conference on
> > to one page.
> > """
> > return dict()
> > Best Regards,
> > Jason