Re: Put a entry in first position
Ross Burton <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 2004-05-14 at 10:19, Pablo Barrera González wrote: > I've got another problem. I would like to put a entry in the top of the > list, without looking its date. It will be some kind of introduction to > the current category like I've made a quick plugin to do this, it's attached. If there is an entry called "body.txt" it is always first in the list. (see www.burtonini.com/blog/computers/sound-juicer for an example) Ross -- Ross Burton mail: [email protected] jabber: [email protected] www: http://www.burtonini.com./ PGP Fingerprint: 1A21 F5B0 D8D0 CFE3 81D4 E25A 2D09 E447 D0B4 33DF
section_body.py
(application/x-python, 2.1 KB)
""" This plugin injects an entry to the beginning of the entry_list (unless the entry_list has no entries in it) that lists some vital information. It requires you to set "section_body_allowed_flavour_list" to the list of flavours that you want this to inject an entry for. ex: py["section_body_flavour_list"] = ["html", "xhtml"] """ __author__ = "Ross Burton <[email protected]>" __version__ = "0.2" from Pyblosxom.entries.fileentry import FileEntry def cb_prepare(args): """ This method gets called in the prepareChain. It gets passed the Request object as the first member of the args tuple. """ request = args["request"] data = request.getData() config = request.getConfiguration() pyhttp = request.getHttp() # if we have no entries, we want to keep it that way so the 404 # message pops up. entry_list = data.get("entry_list", []) if len(entry_list) <= 0: return # Remove any existing body entries for e in ([e for e in entry_list if e['fn']=='body']): entry_list.remove(e) # we only want to inject an entry for certain flavours. for instance # we don't want to do this for rss feeds since it'll make the # feedreaders unhappy. flavour = data.get("flavour", "html") allowed_flavour_list = config.get("section_body_allowed_flavour_list", []) if flavour not in allowed_flavour_list: return try: # ok--if we get here, then we definitely want to insert an entry. entry = FileEntry(config, config["datadir"] + '/' + data['pi_bl'] + "/body.txt", data['root_datadir']) # now we insert this new entry into the beginning of the entry list. entry_list.insert(0, entry) except Exception, e: return # this is interesting since we're actually changing the configuration # data. since the injected entry isn't a "real entry", we want to # make sure that it doesn't bump out a real entry from viewing. maxcount = config.get("num_entries", None) if maxcount: maxcount += 1 config["num_entries"] = maxcount