view MoinMoin/apps/misc/ @ 2960:b2417a0dd48f tip

trivial change to prevent traceback when 0 is passed to TableOfContents macro
author RogerHaase <>
date Thu, 18 Jun 2015 15:31:51 -0700
parents aa093f88e018
line wrap: on
line source
# Copyright: 2010 MoinMoin:ThomasWaldmann
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

    MoinMoin - miscellaneous views

    Misc. stuff that doesn't fit into another view category.

import time

from flask import Response
from flask import current_app as app
from flask import g as flaskg

from whoosh.query import Term, Or, And

from MoinMoin.apps.misc import misc

from MoinMoin.constants.keys import MTIME, NAME_EXACT, NAMESPACE
from MoinMoin.themes import render_template

def sitemap():
    Google (and others) XML sitemap
    def format_timestamp(t):
        tm = time.gmtime(t)
        return time.strftime("%Y-%m-%dT%H:%M:%S+00:00", tm)

    sitemap = []
    for rev in
        fqnames = rev.fqnames
        mtime = rev.meta[MTIME]
        # these are the content items:
        changefreq = "daily"
        priority = "0.5"
        sitemap += [(fqname, format_timestamp(mtime), changefreq, priority) for fqname in fqnames]
    # add entries for root urls
    root_mapping = [(namespace, app.cfg.root_mapping.get(namespace, app.cfg.default_root)) for namespace, _ in app.cfg.namespace_mapping]
    query = Or([And([Term(NAME_EXACT, root), Term(NAMESPACE, namespace)]) for namespace, root in root_mapping])
    for rev in
        mtime = rev.meta[MTIME]
        sitemap.append((rev.meta[NAMESPACE], format_timestamp(mtime), "hourly", "1.0"))
    content = render_template('misc/sitemap.xml', sitemap=sitemap)
    return Response(content, mimetype='text/xml')

def urls_names():
    List of all item URLs and names, e.g. for sisteritems.

    This view generates a list of item URLs and item names, so that other wikis
    can implement SisterWiki functionality easily.
    # XXX we currently also get deleted items, fix this
    fq_names = []
    for rev in
        fq_names += [fqname for fqname in rev.fqnames]
    content = render_template('misc/urls_names.txt', fq_names=fq_names)
    return Response(content, mimetype='text/plain')