Commits

Thomas Waldmann committed 36d51ba

add userprofiles namespace, constants for NSes

Comments (0)

Files changed (7)

MoinMoin/constants/namespaces.py

+# 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'

MoinMoin/storage/__init__.py

 """
 
 
-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):
     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)

MoinMoin/storage/middleware/_tests/test_indexing.py

 
 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
         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)
         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):

MoinMoin/storage/middleware/_tests/test_serialization.py

 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
     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()

MoinMoin/storage/middleware/indexing.py

                                      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
 
         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.

MoinMoin/storage/middleware/routing.py

         """
         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():
 
 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_
 
 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
               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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.