Commits

Thomas Waldmann committed 73409db

whooshify sitemap and urls_names

Comments (0)

Files changed (1)

MoinMoin/apps/misc/views.py

 """
 
 
-import time
-
 from flask import Response
 from flask import current_app as app
 from flask import g as flaskg
 
 from MoinMoin.apps.misc import misc
 
+from MoinMoin.config import NAME, MTIME
 from MoinMoin.themes import render_template
 from MoinMoin import wikiutil
-from MoinMoin.storage.error import NoSuchRevisionError, NoSuchItemError
 
 SITEMAP_HAS_SYSTEM_ITEMS = True
 
     """
     Google (and others) XML sitemap
     """
-    def format_timestamp(ts):
-        return time.strftime("%Y-%m-%dT%H:%M:%S+00:00", time.gmtime(ts))
+    def format_timestamp(dt):
+        return dt.strftime("%Y-%m-%dT%H:%M:%S+00:00")
 
     sitemap = []
-    for item in flaskg.storage.iteritems():
-        try:
-            rev = item.get_revision(-1)
-        except NoSuchRevisionError:
-            # XXX we currently also get user items, they have no revisions -
-            # but in the end, they should not be readable by the user anyways
-            continue
-        if wikiutil.isSystemItem(item.name):
+    for doc in flaskg.storage.documents(all_revs=False, wikiname=app.cfg.interwikiname):
+        name = doc[NAME]
+        mtime = doc[MTIME]
+        if False: # was: wikiutil.isSystemItem(name)   XXX add back later, when we have that in the index
             if not SITEMAP_HAS_SYSTEM_ITEMS:
                 continue
             # system items are rather boring
             # these are the content items:
             changefreq = "daily"
             priority = "0.5"
-        sitemap.append((item.name, format_timestamp(rev.timestamp), changefreq, priority))
+        sitemap.append((name, format_timestamp(mtime), changefreq, priority))
     # add an entry for root url
-    try:
-        item = flaskg.storage.get_item(app.cfg.item_root)
-        rev = item.get_revision(-1)
-        sitemap.append((u'', format_timestamp(rev.timestamp), "hourly", "1.0"))
-    except NoSuchItemError:
-        pass
+    root_item = app.cfg.item_root
+    docs = list(flaskg.storage.documents(all_revs=False, wikiname=app.cfg.interwikiname, name=root_item))
+    if docs:
+        mtime = docs[0][MTIME]
+        sitemap.append((u'', format_timestamp(mtime), "hourly", "1.0"))
     sitemap.sort()
     content = render_template('misc/sitemap.xml', sitemap=sitemap)
     return Response(content, mimetype='text/xml')
     can implement SisterWiki functionality easily.
     See: http://usemod.com/cgi-bin/mb.pl?SisterSitesImplementationGuide
     """
-    # XXX we currently also get user items, fix this
-    item_names = sorted([item.name for item in flaskg.storage.iteritems()])
+    # XXX we currently also get trash items, fix this
+    item_names = sorted([doc[NAME] for doc in flaskg.storage.documents(all_revs=False, wikiname=app.cfg.interwikiname)])
     content = render_template('misc/urls_names.txt', item_names=item_names)
     return Response(content, mimetype='text/plain')