changeset 2236:5f2fb2d7ed87

Replaced a single item_root to namespace-root mapping to add support for namespace specific redirecting.
author Ashutosh Singla <ashu1461@gmail.com>
date Tue, 06 Aug 2013 17:36:48 +0530
parents 9e0bbeb7c5c3
children 93080255a927
files MoinMoin/apps/frontend/views.py MoinMoin/apps/misc/views.py MoinMoin/config/default.py MoinMoin/items/__init__.py MoinMoin/templates/layout.html MoinMoin/themes/__init__.py MoinMoin/themes/foobar/templates/layout.html MoinMoin/util/interwiki.py wikiconfig.py
diffstat 9 files changed, 31 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/frontend/views.py	Sun Aug 04 01:05:33 2013 +0530
+++ b/MoinMoin/apps/frontend/views.py	Tue Aug 06 17:36:48 2013 +0530
@@ -76,7 +76,7 @@
 
 @frontend.route('/')
 def show_root():
-    item_name = app.cfg.item_root
+    item_name = app.cfg.root_mapping.get(NAMESPACE_DEFAULT, app.cfg.default_root)
     return redirect(url_for_item(item_name))
 
 
--- a/MoinMoin/apps/misc/views.py	Sun Aug 04 01:05:33 2013 +0530
+++ b/MoinMoin/apps/misc/views.py	Tue Aug 06 17:36:48 2013 +0530
@@ -13,9 +13,11 @@
 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
+from MoinMoin.constants.keys import MTIME, NAME_EXACT, NAMESPACE
 from MoinMoin.themes import render_template
 
 
@@ -37,11 +39,11 @@
         priority = "0.5"
         sitemap.append((name, format_timestamp(mtime), changefreq, priority))
     # add an entry for root url
-    root_item = app.cfg.item_root
-    revs = list(flaskg.storage.documents(wikiname=app.cfg.interwikiname, name=root_item))
-    if revs:
-        mtime = revs[0].meta[MTIME]
-        sitemap.append((u'', format_timestamp(mtime), "hourly", "1.0"))
+    root_mapping = app.cfg.root_mapping
+    query = Or([And([Term(NAME_EXACT, root_mapping[namespace]), Term(NAMESPACE, namespace)]) for namespace in root_mapping.keys()])
+    for rev in flaskg.storage.search(q=query):
+        mtime = rev.meta[MTIME]
+        sitemap.append((rev.meta[NAMESPACE], format_timestamp(mtime), "hourly", "1.0"))
     sitemap.sort()
     content = render_template('misc/sitemap.xml', sitemap=sitemap)
     return Response(content, mimetype='text/xml')
--- a/MoinMoin/config/default.py	Sun Aug 04 01:05:33 2013 +0530
+++ b/MoinMoin/config/default.py	Tue Aug 06 17:36:48 2013 +0530
@@ -23,6 +23,7 @@
 from MoinMoin import error
 from MoinMoin.constants.rights import ACL_RIGHTS_CONTENTS, ACL_RIGHTS_FUNCTIONS
 from MoinMoin.constants.keys import *
+from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT
 from MoinMoin import datastruct
 from MoinMoin.auth import MoinAuth
 from MoinMoin.util import plugins
@@ -219,7 +220,7 @@
         decode_names = (
             'sitename', 'interwikiname', 'user_homewiki',
             'interwiki_preferred',
-            'item_root', 'item_license', 'mail_from',
+            'item_license', 'mail_from',
             'item_dict_regex', 'item_group_regex',
             'acl_functions', 'supplementation_item_names', 'html_pagetitle',
             'theme_default', 'timezone_default', 'locale_default',
@@ -459,7 +460,8 @@
     )),
     # ==========================================================================
     'items': ('Special Item Names', None, (
-        ('item_root', u'Home', "Name of the root item (aka 'front page'). [Unicode]"),
+        ('default_root', u'Home', "Default root, use this value in case no match is found in root_mapping. [Unicode]"),
+        ('root_mapping', {}, "mapping of namespaces to item_roots."),
 
         # the following regexes should match the complete name when used in free text
         # the group 'all' shall match all, while the group 'key' shall match the key only
--- a/MoinMoin/items/__init__.py	Sun Aug 04 01:05:33 2013 +0530
+++ b/MoinMoin/items/__init__.py	Tue Aug 06 17:36:48 2013 +0530
@@ -41,7 +41,7 @@
 from MoinMoin.i18n import L_
 from MoinMoin.themes import render_template
 from MoinMoin.util.mime import Type
-from MoinMoin.util.interwiki import url_for_item, split_fqname, get_fqname
+from MoinMoin.util.interwiki import url_for_item, split_fqname, get_fqname, CompositeName
 from MoinMoin.util.registry import RegistryBase
 from MoinMoin.util.clock import timed
 from MoinMoin.forms import RequiredText, OptionalText, JSON, Tags
@@ -296,6 +296,9 @@
         fqname = split_fqname(name)
         if fqname.field not in UFIELDS:  # Need a unique key to extract stored item.
             raise FieldNotUniqueError("field {0} is not in UFIELDS".format(fqname.field))
+        if not fqname.value and fqname.field == NAME_EXACT:
+            fqname = fqname.get_root_fqname()
+
         rev = get_storage_revision(fqname, itemtype, contenttype, rev_id, item)
         contenttype = rev.meta.get(CONTENTTYPE) or contenttype
         logging.debug("Item {0!r}, got contenttype {1!r} from revision meta".format(name, contenttype))
--- a/MoinMoin/templates/layout.html	Sun Aug 04 01:05:33 2013 +0530
+++ b/MoinMoin/templates/layout.html	Tue Aug 06 17:36:48 2013 +0530
@@ -24,7 +24,7 @@
 
     {% if logo %}
     <div id="moin-logo">
-        <a href="{{ url_for('frontend.show_item', item_name=cfg.item_root) }}">{{ logo }}</a>
+        <a href="{{ url_for('frontend.show_item', item_name=cfg.root_mapping.get('', cfg.default_root)) }}">{{ logo }}</a>
     </div>
     {% endif %}
 
@@ -62,7 +62,7 @@
     <div id="moin-locationline">
         {% if cfg.show_interwiki -%}
         <span id="moin-interwiki">
-            <a href="{{ url_for('frontend.show_item', item_name=cfg.item_root) }}" rel="nofollow">
+            <a href="{{ url_for('frontend.show_item', item_name=cfg.root_mapping['']) }}" rel="nofollow">
                 {% if cfg.interwikiname %}{{ cfg.interwikiname }}{% else %}Self{% endif %}
             </a>
             <span class="sep">: </span>
--- a/MoinMoin/themes/__init__.py	Sun Aug 04 01:05:33 2013 +0530
+++ b/MoinMoin/themes/__init__.py	Tue Aug 06 17:36:48 2013 +0530
@@ -23,6 +23,7 @@
 from MoinMoin.i18n import _, L_, N_
 from MoinMoin import wikiutil, user
 from MoinMoin.constants.keys import USERID, ADDRESS, HOSTNAME, REVID, ITEMID, NAME_EXACT
+from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT
 from MoinMoin.search import SearchForm
 from MoinMoin.util.interwiki import split_interwiki, getInterwikiHome, is_local_wiki, is_known_wiki, url_for_item, CompositeName, split_fqname
 from MoinMoin.util.crypto import cache_key
@@ -228,7 +229,7 @@
         for cls, endpoint, args, link_text, title in self.cfg.navi_bar:
             if endpoint == "frontend.show_root":
                 endpoint = "frontend.show_item"
-                args['item_name'] = app.cfg.item_root
+                args['item_name'] = app.cfg.root_mapping.get(NAMESPACE_DEFAULT, app.cfg.default_root)
             items.append((cls, url_for(endpoint, **args), link_text, title))
 
         # Add user links to wiki links.
--- a/MoinMoin/themes/foobar/templates/layout.html	Sun Aug 04 01:05:33 2013 +0530
+++ b/MoinMoin/themes/foobar/templates/layout.html	Tue Aug 06 17:36:48 2013 +0530
@@ -17,7 +17,7 @@
 
 {% if logo %}
 <div id="moin-logo">
-    <a style="background-image: url({{ '/static/logos/moinmoin.png' }});" href="{{ url_for('frontend.show_item', item_name=cfg.item_root) }}"></a>
+    <a style="background-image: url({{ '/static/logos/moinmoin.png' }});" href="{{ url_for('frontend.show_item', item_name=cfg.root_mapping.get('',cfg.default_root)) }}"></a>
 </div>
 {% endif %}
 
@@ -110,7 +110,7 @@
     <div id="moin-breadcrumbs-location">
         {% if cfg.show_interwiki -%}
         <span id="moin-interwiki">
-            <a href="{{ url_for('frontend.show_item', item_name=cfg.item_root) }}" rel="nofollow">
+            <a href="{{ url_for('frontend.show_item', item_name=cfg.root_mapping['']) }}" rel="nofollow">
                 {% if cfg.interwikiname %}{{ cfg.interwikiname }}{% else %}Self{% endif %}
             </a>
             <span class="sep">: </span>
--- a/MoinMoin/util/interwiki.py	Sun Aug 04 01:05:33 2013 +0530
+++ b/MoinMoin/util/interwiki.py	Tue Aug 06 17:36:48 2013 +0530
@@ -163,6 +163,14 @@
         field = NAME_EXACT if not self.field else self.field
         return {NAMESPACE: self.namespace, field: self.value}
 
+    def get_root_fqname(self):
+        """
+        Set value to the item_root of that namespace, and return
+        the new CompisteName.
+        """
+        return CompositeName(self.namespace, NAME_EXACT, app.cfg.root_mapping.get(self.namespace, app.cfg.default_root))
+
+
 
 def split_fqname(url):
     """
--- a/wikiconfig.py	Sun Aug 04 01:05:33 2013 +0530
+++ b/wikiconfig.py	Tue Aug 06 17:36:48 2013 +0530
@@ -44,8 +44,6 @@
                               hierarchic=False, ),
     )
 
-    #item_root = u'Home' # front page
-
     # for display purposes:
     sitename = u'My MoinMoin'
     # it is required that you set this to a unique, stable and non-empty name: