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

Changes between Version 4 and Version 5 of ExtendingVisitFramework


Ignore:
Timestamp:
02/05/06 09:25:37 (13 years ago)
Author:
plewis
Comment:

Added checks for config variables

Legend:

Unmodified
Added
Removed
Modified
  • ExtendingVisitFramework

    v4 v5  
    2828from model import VisitIP 
    2929 
    30 # Interface for the TurboGears extension 
     30def ip_tracking_is_on(): 
     31    "Returns True if ip tracking is properly enabled, False otherwise." 
     32    return cherrypy.config.get('visit.on', False) and cherrypy.config.get('visit.ip_tracking.on', False) 
     33 
     34#Interface for the TurboGears extension 
    3135def start_extension(): 
    32          
     36    if not ip_tracking_is_on(): 
     37        return 
    3338    cherrypy.log( "Visit ip tracker starting" ) 
    3439 
    35     # Register the plugin for the Visit Tracking framework 
     40    #Register the plugin for the Visit Tracking framework 
    3641    visit.enable_visit_plugin( IPVisitPlugin() ) 
    3742     
    3843def shutdown_extension(): 
     44    if not ip_tracking_is_on(): 
     45        return 
    3946    cherrypy.log( "Visit ip tracker shutting down" ) 
    40      
    4147     
    4248class IPVisitPlugin(object): 
     
    6167}}} 
    6268 
    63 The first two methods are called by turbogears when starting up and shutting down.  The key is the visit.enable_visit_plugin call, which registers your plugin with the visit framework. 
     69The start_extension and shutdown_extension functions are called by turbogears when starting up and shutting down (imagine that).  The key is this process is the visit.enable_visit_plugin call, which registers your plugin with the visit framework. 
     70 
    6471 
    6572== Step Three: Tie in the extension in setup.py == 
     
    8188My project name is ip_plugin, so you will need to edit this a bit make this point to the right module in your project.  (Aside: I'm not sure that [turbogears.extensions] is the right place to put this entry point.  If there is a better area to place this in, please edit as appropriate.  But, the above does work). 
    8289 
    83 == Step Four: Update egg info == 
     90== Step Four: Update Config File == 
     91 
     92Add a configuration variable so that the tracking can be turned on and off.  Somewhere in config.py, add the line 
     93 
     94{{{ 
     95visit.ip_tracking.on=True 
     96}}} 
     97 
     98== Step Five: Update egg info == 
    8499 
    85100This step just re-generates the egg information for your project so that the extension actually gets called at runtime.  From the command line, at the root level of your project run 'python setup.py egg_info'.