Re: A simple question about ordering of posts

Chris G <[email protected]> Wed, 3 Feb 2010 10:12:25 +0000
Newsgroups gmane.comp.web.pyblosxom.user
Message-ID <20100203101225.GA21410@chris>
On Tue, Feb 02, 2010 at 10:20:10AM +0000, chombee wrote:
> On Mon, Feb 01, 2010 at 06:14:50PM -0500, will kahn-greene wrote:
> > 
> > Say I only wanted to do this if PyBlosxom is rendering a category index 
> > and not a specific entry.  I'd do something like this:
> > 
> >     def cb_prepare(args):
> >         # only thing in the args dict is the request object
> >         request = args["request"]
> > 
> >         # the entry list is in the data section
> >         data = request.get_data()
> > 
> >         entrylist = data["entry_list"]
> > 
> >         if data["bl_type"] = "dir" and len(entrylist) > 0:
> >             first_entry = entrylist[0]
> >             first_entry["template_name"] = "story_big_size"
> >
> 
> So it looks like to change the template for every entry that is about to
> be rendered you'd have to iterate over entries, something like:
> 
>     def cb_prepare(args):
>         request = args['request']
>         data = request.get_data()
>         if data['bl_type'] == 'dir':
>             entrylist = data['entry_list']
>             for entry in entrylist:
>                 entry['template_name'] = 'story-index'
> 
> (Assuming the entries come as dictionaries like that, but you get the
> idea.)  
> 
This is where I'm going.

I guess/suspect too that one can only change the story template this
way, having looked at the renderer code there's a strange variable
'override' which seems to apply the template_name only when it's
handling a story template.

Here's my actual code:-

    def cb_prepare(args):

        logger = tools.get_logger()
        logger.info("In cb_prepare()")

        request = args['request']
        data = request.get_data()
        entrylist = data['entry_list']

        if len(entrylist) > 0:
            logger.info("entrylist is > 0")                               
              
            if data['bl_type'] == "dir":
                logger.info("It's a 'dir' so set the template_name to 'story-index'")
                for e in entrylist:
                    e["template_name"] = "story_index"

.... and, after fixing the name of my template so that it matched the
value I was putting into the entry above, it works!  Hurrah!

Thanks for all the help everyone, I now have the basis of what I want.

-- 
Chris Green


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com