changeset 2021:36d51bad06b3

add userprofiles namespace, constants for NSes
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 02 Mar 2013 23:27:40 +0100
parents 56e38b884e87
children 2bab30fa0309
files MoinMoin/constants/namespaces.py MoinMoin/storage/__init__.py MoinMoin/storage/middleware/_tests/test_indexing.py MoinMoin/storage/middleware/_tests/test_serialization.py MoinMoin/storage/middleware/indexing.py MoinMoin/storage/middleware/routing.py MoinMoin/user.py
diffstat 7 files changed, 33 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/constants/namespaces.py	Sat Mar 02 23:27:40 2013 +0100
@@ -0,0 +1,9 @@
+# Copyright: 2013 MoinMoin:CheerXiao
+# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
+
+"""
+MoinMoin - namespaces related constants
+"""
+
+NAMESPACE_DEFAULT = u''
+NAMESPACE_USERPROFILES = u'userprofiles'
--- a/MoinMoin/storage/__init__.py	Sat Mar 02 18:23:08 2013 +0100
+++ b/MoinMoin/storage/__init__.py	Sat Mar 02 23:27:40 2013 +0100
@@ -22,9 +22,11 @@
 """
 
 
-CONTENT, USERPROFILES = u'content', u'userprofiles'
+BACKENDS_PACKAGE = 'MoinMoin.storage.backends'
 
-BACKENDS_PACKAGE = 'MoinMoin.storage.backends'
+from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT, NAMESPACE_USERPROFILES
+
+BACKEND_DEFAULT, BACKEND_USERPROFILES = u'default', u'userprofiles'
 
 
 def backend_from_uri(uri):
@@ -82,15 +84,15 @@
     if not user_profile_acl:
         user_profile_acl = dict(before=u'All:', default=u'', after=u'', hierarchic=False)
     namespaces = {
-        u'': CONTENT,
-        u'userprofiles:': USERPROFILES,
+        NAMESPACE_DEFAULT: BACKEND_DEFAULT,
+        NAMESPACE_USERPROFILES + ':': BACKEND_USERPROFILES,
     }
     backends = {
-        CONTENT: None,
-        USERPROFILES: None,
+        BACKEND_DEFAULT: None,
+        BACKEND_USERPROFILES: None,
     }
     acls = {
-        'userprofiles:': user_profile_acl,
-        '': content_acl,
+        NAMESPACE_USERPROFILES + ':': user_profile_acl,
+        NAMESPACE_DEFAULT: content_acl,
     }
     return create_mapping(uri, namespaces, backends, acls)
--- a/MoinMoin/storage/middleware/_tests/test_indexing.py	Sat Mar 02 18:23:08 2013 +0100
+++ b/MoinMoin/storage/middleware/_tests/test_indexing.py	Sat Mar 02 23:27:40 2013 +0100
@@ -17,6 +17,7 @@
 
 from MoinMoin.constants.keys import (NAME, SIZE, ITEMID, REVID, DATAID, HASH_ALGORITHM, CONTENT, COMMENT,
                                      LATEST_REVS, ALL_REVS, NAMESPACE)
+from MoinMoin.constants.namespaces import NAMESPACE_USERPROFILES
 
 from MoinMoin.auth import GivenAuth
 from MoinMoin._tests import wikiconfig
@@ -371,7 +372,7 @@
         item = self.imw[item_name_n]
         rev_n = item.store_revision(dict(name=[item_name_n, ], contenttype=u'text/plain'),
                                     StringIO(str(item_name_n)), return_rev=True)
-        item_name_u = u'userprofiles:userprofile'
+        item_name_u = u'%s:userprofile' % NAMESPACE_USERPROFILES
         item = self.imw[item_name_u]
         rev_u = item.store_revision(dict(name=[item_name_u, ], contenttype=u'text/plain'),
                                     StringIO(str(item_name_u)), return_rev=True)
@@ -381,7 +382,7 @@
         assert rev_n.meta[NAME] == [item_name_n, ]
         item = self.imw[item_name_u]
         rev_u = item.get_revision(rev_u.revid)
-        assert rev_u.meta[NAMESPACE] == u'userprofiles'
+        assert rev_u.meta[NAMESPACE] == NAMESPACE_USERPROFILES
         assert rev_u.meta[NAME] == [item_name_u.split(':')[1]]
 
     def test_parentnames(self):
--- a/MoinMoin/storage/middleware/_tests/test_serialization.py	Sat Mar 02 18:23:08 2013 +0100
+++ b/MoinMoin/storage/middleware/_tests/test_serialization.py	Sat Mar 02 23:27:40 2013 +0100
@@ -15,6 +15,7 @@
 from ..serialization import serialize, deserialize
 
 from MoinMoin.constants.keys import NAME, CONTENTTYPE
+from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT
 
 from MoinMoin.storage.backends.stores import MutableBackend
 from MoinMoin.storage.stores.memory import BytesStore, FileStore
@@ -56,7 +57,7 @@
     meta_store = BytesStore()
     data_store = FileStore()
     _backend = MutableBackend(meta_store, data_store)
-    namespaces = [('', u'backend')]
+    namespaces = [(NAMESPACE_DEFAULT, u'backend')]
     backends = {u'backend': _backend}
     backend = RoutingBackend(namespaces, backends)
     backend.create()
--- a/MoinMoin/storage/middleware/indexing.py	Sat Mar 02 18:23:08 2013 +0100
+++ b/MoinMoin/storage/middleware/indexing.py	Sat Mar 02 23:27:40 2013 +0100
@@ -77,6 +77,7 @@
                                      EXTERNALLINKS, ITEMLINKS, ITEMTRANSCLUSIONS, ACL, EMAIL, OPENID,
                                      ITEMID, REVID, CURRENT, PARENTID, PTIME, LATEST_REVS, ALL_REVS, BACKENDNAME)
 from MoinMoin.constants.contenttypes import CONTENTTYPE_USER
+from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT
 from MoinMoin.constants import keys
 from MoinMoin.constants.keys import ITEMTYPE
 
@@ -253,6 +254,8 @@
         common_fields = {
             # wikiname so we can have a shared index in a wiki farm, always check this!
             WIKINAME: ID(stored=True),
+            # namespace, so we can have different namespaces within a wiki, always check this!
+            NAMESPACE: ID(stored=True),
             # tokenized NAME from metadata - use this for manual searching from UI
             NAME: TEXT(stored=True, multitoken_query="and", analyzer=item_name_analyzer(), field_boost=2.0),
             # unmodified NAME from metadata - use this for precise lookup by the code.
--- a/MoinMoin/storage/middleware/routing.py	Sat Mar 02 18:23:08 2013 +0100
+++ b/MoinMoin/storage/middleware/routing.py	Sat Mar 02 23:27:40 2013 +0100
@@ -51,6 +51,9 @@
         """
         self.namespaces = namespaces
         self.backends = backends
+        for namespace, backend_name in namespaces:
+            assert isinstance(namespace, unicode)
+            assert backend_name in backends
 
     def open(self):
         for backend in self.backends.values():
--- a/MoinMoin/user.py	Sat Mar 02 18:23:08 2013 +0100
+++ b/MoinMoin/user.py	Sat Mar 02 23:27:40 2013 +0100
@@ -36,6 +36,7 @@
 
 from MoinMoin import wikiutil
 from MoinMoin.constants.contenttypes import CONTENTTYPE_USER
+from MoinMoin.constants.namespaces import NAMESPACE_USERPROFILES
 from MoinMoin.constants.keys import *
 from MoinMoin.constants.misc import ANON
 from MoinMoin.i18n import _, L_, N_
@@ -101,6 +102,7 @@
 
 def update_user_query(**q):
     USER_QUERY_STDARGS = {
+        NAMESPACE: NAMESPACE_USERPROFILES,
         CONTENTTYPE: CONTENTTYPE_USER,
         WIKINAME: app.cfg.interwikiname,  # XXX for now, search only users of THIS wiki
                                           # maybe add option to not index wiki users
@@ -244,6 +246,7 @@
               force=True because these changes are not detected!
         """
         if self._changed or force:
+            self[NAMESPACE] = NAMESPACE_USERPROFILES
             self[CONTENTTYPE] = CONTENTTYPE_USER
             q = {ITEMID: self[ITEMID]}
             q = update_user_query(**q)