Re: setting template variables from plugins/ unkludging code/

Ryan Barrett <pyblosxom-6sb6M7qyT/[email protected]>
Newsgroups gmane.comp.web.pyblosxom.devel
Message-ID <[email protected]>
cool! it'd be great to have a twitter plugin for pyblosxom.

On Fri, 6 Jul 2007, William Cybriwsky wrote:

> Hi, I'm a new user of pyblosxom, and I wanted to know how to set template
> variables from a plugin. I currently have the chunk of python code:

if you want the variables to be available in existing templates, you can set 
them on the request data. for example:

   def cb_prepare(args):
     data = args['request'].getData()
     data['twitterstatus'] = ...

if you're rendering an entry yourself, you can set it directly on the entry. 
for example:

   entry = args['entry']  # or entry = FileEntry(request) or ...
   entry['twitterstatus'] = ...

see http://pyblosxom.sourceforge.net/1.3.1/api/ .


> P.S. : if I wanted to write some simple cache code, how would I just do a
> check for a file age of 60 seconds?

if i understand right, you only want to check your twitter status every 60 
seconds, so on each request, you want to check if tmptwit.xml is over 60 
seconds old? try os.path.getmtime():

http://docs.python.org/lib/module-os.path.html#l2h-2168

-Ryan

--
http://snarfed.org/

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.