Ejemplo n.º 1
0
 def _render(self, formatter, cols, name_pat, size, header, limit):
     #noinspection PyArgumentList
     icon = Icons(self.env)
     icon_dir = icon.icon_location(size)[1]
     files = fnmatch.filter(os.listdir(icon_dir), '%s.png' % name_pat)
     icon_names = [os.path.splitext(p)[0] for p in files]
     if limit:
         displayed_icon_names = reduce_names(icon_names, limit)
     else:
         displayed_icon_names = icon_names
     icon_table = render_table(
         displayed_icon_names, cols,
         lambda name: icon._render_icon(formatter, name, size))
     if not len(icon_names):
         message = 'No %s icon matches %s' % (SIZE_DESCR[size], name_pat)
     elif len(icon_names) == 1:
         message = 'Showing the only %s icon matching %s' % \
                   (SIZE_DESCR[size], name_pat)
     elif len(displayed_icon_names) == len(icon_names):
         message = 'Showing all %d %s icons matching %s' % \
                   (len(icon_names), SIZE_DESCR[size], name_pat)
     else:
         message = 'Showing %d of %d %s icons matching %s' % \
                   (len(displayed_icon_names), len(icon_names),
                    SIZE_DESCR[size], name_pat)
     return tag.div(tag.p(tag.small(message)) if header else '', icon_table)
Ejemplo n.º 2
0
    def expand_macro(self, formatter, name, content):
        args, kw = parse_args(content)
        prefix = args[0].strip() if args else None
        limit = _arg_as_int(args[1].strip(), min=1) if len(args) > 1 else None
        group = kw.get('group', 'date')

        sql = """SELECT name, max(version) AS max_version,
                        max(time) AS max_time FROM wiki"""
        args = []
        if prefix:
            with self.env.db_query as db:
                sql += " WHERE name %s" % db.prefix_match()
                args.append(db.prefix_match_value(prefix))
        sql += " GROUP BY name ORDER BY max_time DESC"
        if limit:
            sql += " LIMIT %s"
            args.append(limit)

        entries_per_date = []
        prevdate = None
        for name, version, ts in self.env.db_query(sql, args):
            if 'WIKI_VIEW' not in formatter.perm('wiki', name, version):
                continue
            req = formatter.req
            date = user_time(req, format_date, from_utimestamp(ts))
            if date != prevdate:
                prevdate = date
                entries_per_date.append((date, []))
            version = int(version)
            diff_href = None
            if version > 1:
                diff_href = formatter.href.wiki(name, action='diff',
                                                version=version)
            page_name = formatter.wiki.format_page_name(name)
            entries_per_date[-1][1].append((page_name, name, version,
                                            diff_href))

        items_per_date = (
            (date, (tag.li(tag.a(page, href=formatter.href.wiki(name)),
                           tag.small(' (', tag.a(_("diff"), href=diff_href),
                                     ')') if diff_href else None,
                           '\n')
                    for page, name, version, diff_href in entries))
            for date, entries in entries_per_date)

        if group == 'date':
            out = ((tag.h3(date, class_='section'), tag.ul(entries))
                   for date, entries in items_per_date)
        else:
            out = tag.ul(entries for date, entries in items_per_date)
        return tag.div(out, class_="wikipage")