Source

muyhomepage2 / muyhomepage2 / pagehandlers / tagsummary.py


from muyhomepage2.pagehandlers import handler

class TagSummaryHandler(handler.PageHandler):
    def content(self):
        return self.gettag()

    def template(self):
        return 'tagsummary.html'

    def extension(self, website, config):
        tp = self._taggedpages(self.gettag(), website)
        return {
            'tagcount': len(tp),
            'taggedpages': tp
            }

    def gettag(self):
        return self.page.title.split(':', 1)[-1]

    def _taggedpages(self, tag, website):
        tl = []
        for page in website.tagmap[tag]:
            url = './%s' % handler.PageHandler(page).finalname()
            tl.append((url, page.title))
        return sorted(tl, key=lambda v: v[1])