Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #854 (closed enhancement: worksforme)

Opened 13 years ago

Last modified 12 years ago

Request - Startup Hook

Reported by: jvanasco@… Owned by: anonymous
Priority: normal Milestone:
Component: CherryPy Version: 0.9a5
Severity: normal Keywords:
Cc:

Description

It would be nice if TG supported some user defined startup code that can be called from startup.startTurboGears()

i think it might support it already - but there are no docs for it

It'd be nice, because then we can set certain variables and/or add some cherrypy filters to access the filter API

Attachments

startup.diff Download (1.2 KB) - added by anonymous 13 years ago.

Change History

Changed 13 years ago by anonymous

comment:1 Changed 13 years ago by jvanasco@…

OK. I patched startup.py myself

this now supports 3 arguments in app.cfg

# filter to preprend to the list
tg.udf_cpfilter_pre = 'appname.module.filtername'

# filter to append to the list
tg.udf_cpfilter_post = 'appname.module.filtername'

# function to call on startup
tg.udf_startup = 'appname.module.functionname'

if someone can do a better job, please do. this was the only way i could push stuff into cherrypy though - before startup is called in start-appname.py, cherrypy.root isn't declared. elsewhere in the app , we're a request only phase

the filters seem good where they are, but there might be a better place for the udf (user defined function) startup function - perhaps later in the request , right before we enter the reactor loop - not sure where that happens though

comment:2 Changed 13 years ago by alberto

I think there's no need to patch startup for this. You can register any callable to be run at TG startup already:

from turbogears.startup import call_on_startup

def insert_your_filters():
    ...

call_on_startup.append(insert_your_filters)

HTH, Alberto

comment:3 Changed 13 years ago by jvanasco@…

  • Status changed from new to closed
  • Resolution set to worksforme

i really wish that someone would have tossed that into the docs.

I'm adding a wiki page for the next person.

comment:4 Changed 13 years ago by alberto

Cool, Thanks! :) Alberto

Note: See TracTickets for help on using tickets.