changeset 2244:ec92e2ded24d

Added multiple and fqname support to misc views.
author Ashutosh Singla <ashu1461@gmail.com>
date Sun, 18 Aug 2013 15:22:52 +0530
parents 880f995b9d0b
children 555d74396ece
files MoinMoin/apps/misc/templates/misc/sitemap.xml MoinMoin/apps/misc/templates/misc/urls_names.txt MoinMoin/apps/misc/views.py
diffstat 3 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/misc/templates/misc/sitemap.xml	Sun Aug 18 14:56:23 2013 +0530
+++ b/MoinMoin/apps/misc/templates/misc/sitemap.xml	Sun Aug 18 15:22:52 2013 +0530
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
-{% for item_name, lastmod, changefreq, priority in sitemap -%}
+{% for fq_name, lastmod, changefreq, priority in sitemap -%}
 <url>
-<loc>{{ url_for('frontend.show_item', item_name=item_name, _external=True)|e }}</loc>
+<loc>{{ url_for('frontend.show_item', item_name=fq_name, _external=True)|e }}</loc>
 <lastmod>{{ lastmod }}</lastmod>
 <changefreq>{{ changefreq }}</changefreq>
 <priority>{{ priority }}</priority>
--- a/MoinMoin/apps/misc/templates/misc/urls_names.txt	Sun Aug 18 14:56:23 2013 +0530
+++ b/MoinMoin/apps/misc/templates/misc/urls_names.txt	Sun Aug 18 15:22:52 2013 +0530
@@ -1,3 +1,3 @@
-{% for item_name in item_names -%}
-{{ url_for('frontend.show_item', item_name=item_name, _external=True) }} {{ item_name }}
+{% for fq_name in fq_names|sort(attribute='value') -%}
+{{ url_for('frontend.show_item', item_name=fq_name, _external=True) }} {{ fq_name.value }}
 {% endfor %}
--- a/MoinMoin/apps/misc/views.py	Sun Aug 18 14:56:23 2013 +0530
+++ b/MoinMoin/apps/misc/views.py	Sun Aug 18 15:22:52 2013 +0530
@@ -32,15 +32,15 @@
 
     sitemap = []
     for rev in flaskg.storage.documents(wikiname=app.cfg.interwikiname):
-        name = rev.name
+        fqnames = rev.fqnames
         mtime = rev.meta[MTIME]
         # these are the content items:
         changefreq = "daily"
         priority = "0.5"
-        sitemap.append((name, format_timestamp(mtime), changefreq, priority))
-    # add an entry for root url
-    root_mapping = app.cfg.root_mapping
-    query = Or([And([Term(NAME_EXACT, root_mapping[namespace]), Term(NAMESPACE, namespace)]) for namespace in root_mapping.keys()])
+        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 flaskg.storage.search(q=query):
         mtime = rev.meta[MTIME]
         sitemap.append((rev.meta[NAMESPACE], format_timestamp(mtime), "hourly", "1.0"))
@@ -59,6 +59,8 @@
     See: http://usemod.com/cgi-bin/mb.pl?SisterSitesImplementationGuide
     """
     # XXX we currently also get deleted items, fix this
-    item_names = sorted([rev.name for rev in flaskg.storage.documents(wikiname=app.cfg.interwikiname)])
-    content = render_template('misc/urls_names.txt', item_names=item_names)
+    fq_names = []
+    for rev in flaskg.storage.documents(wikiname=app.cfg.interwikiname):
+        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')