add userprofiles namespace, constants for NSes
authorThomas Waldmann <tw AT waldmann-edv DOT de>
Sat, 02 Mar 2013 23:27:40 +0100
changeset 202136d51bad06b3
parent 2020 56e38b884e87
child 2022 2bab30fa0309
add userprofiles namespace, constants for NSes
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
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/MoinMoin/constants/namespaces.py	Sat Mar 02 23:27:40 2013 +0100
     1.3 @@ -0,0 +1,9 @@
     1.4 +# Copyright: 2013 MoinMoin:CheerXiao
     1.5 +# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
     1.6 +
     1.7 +"""
     1.8 +MoinMoin - namespaces related constants
     1.9 +"""
    1.10 +
    1.11 +NAMESPACE_DEFAULT = u''
    1.12 +NAMESPACE_USERPROFILES = u'userprofiles'
     2.1 --- a/MoinMoin/storage/__init__.py	Sat Mar 02 18:23:08 2013 +0100
     2.2 +++ b/MoinMoin/storage/__init__.py	Sat Mar 02 23:27:40 2013 +0100
     2.3 @@ -22,9 +22,11 @@
     2.4  """
     2.5  
     2.6  
     2.7 -CONTENT, USERPROFILES = u'content', u'userprofiles'
     2.8 +BACKENDS_PACKAGE = 'MoinMoin.storage.backends'
     2.9  
    2.10 -BACKENDS_PACKAGE = 'MoinMoin.storage.backends'
    2.11 +from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT, NAMESPACE_USERPROFILES
    2.12 +
    2.13 +BACKEND_DEFAULT, BACKEND_USERPROFILES = u'default', u'userprofiles'
    2.14  
    2.15  
    2.16  def backend_from_uri(uri):
    2.17 @@ -82,15 +84,15 @@
    2.18      if not user_profile_acl:
    2.19          user_profile_acl = dict(before=u'All:', default=u'', after=u'', hierarchic=False)
    2.20      namespaces = {
    2.21 -        u'': CONTENT,
    2.22 -        u'userprofiles:': USERPROFILES,
    2.23 +        NAMESPACE_DEFAULT: BACKEND_DEFAULT,
    2.24 +        NAMESPACE_USERPROFILES + ':': BACKEND_USERPROFILES,
    2.25      }
    2.26      backends = {
    2.27 -        CONTENT: None,
    2.28 -        USERPROFILES: None,
    2.29 +        BACKEND_DEFAULT: None,
    2.30 +        BACKEND_USERPROFILES: None,
    2.31      }
    2.32      acls = {
    2.33 -        'userprofiles:': user_profile_acl,
    2.34 -        '': content_acl,
    2.35 +        NAMESPACE_USERPROFILES + ':': user_profile_acl,
    2.36 +        NAMESPACE_DEFAULT: content_acl,
    2.37      }
    2.38      return create_mapping(uri, namespaces, backends, acls)
     3.1 --- a/MoinMoin/storage/middleware/_tests/test_indexing.py	Sat Mar 02 18:23:08 2013 +0100
     3.2 +++ b/MoinMoin/storage/middleware/_tests/test_indexing.py	Sat Mar 02 23:27:40 2013 +0100
     3.3 @@ -17,6 +17,7 @@
     3.4  
     3.5  from MoinMoin.constants.keys import (NAME, SIZE, ITEMID, REVID, DATAID, HASH_ALGORITHM, CONTENT, COMMENT,
     3.6                                       LATEST_REVS, ALL_REVS, NAMESPACE)
     3.7 +from MoinMoin.constants.namespaces import NAMESPACE_USERPROFILES
     3.8  
     3.9  from MoinMoin.auth import GivenAuth
    3.10  from MoinMoin._tests import wikiconfig
    3.11 @@ -371,7 +372,7 @@
    3.12          item = self.imw[item_name_n]
    3.13          rev_n = item.store_revision(dict(name=[item_name_n, ], contenttype=u'text/plain'),
    3.14                                      StringIO(str(item_name_n)), return_rev=True)
    3.15 -        item_name_u = u'userprofiles:userprofile'
    3.16 +        item_name_u = u'%s:userprofile' % NAMESPACE_USERPROFILES
    3.17          item = self.imw[item_name_u]
    3.18          rev_u = item.store_revision(dict(name=[item_name_u, ], contenttype=u'text/plain'),
    3.19                                      StringIO(str(item_name_u)), return_rev=True)
    3.20 @@ -381,7 +382,7 @@
    3.21          assert rev_n.meta[NAME] == [item_name_n, ]
    3.22          item = self.imw[item_name_u]
    3.23          rev_u = item.get_revision(rev_u.revid)
    3.24 -        assert rev_u.meta[NAMESPACE] == u'userprofiles'
    3.25 +        assert rev_u.meta[NAMESPACE] == NAMESPACE_USERPROFILES
    3.26          assert rev_u.meta[NAME] == [item_name_u.split(':')[1]]
    3.27  
    3.28      def test_parentnames(self):
     4.1 --- a/MoinMoin/storage/middleware/_tests/test_serialization.py	Sat Mar 02 18:23:08 2013 +0100
     4.2 +++ b/MoinMoin/storage/middleware/_tests/test_serialization.py	Sat Mar 02 23:27:40 2013 +0100
     4.3 @@ -15,6 +15,7 @@
     4.4  from ..serialization import serialize, deserialize
     4.5  
     4.6  from MoinMoin.constants.keys import NAME, CONTENTTYPE
     4.7 +from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT
     4.8  
     4.9  from MoinMoin.storage.backends.stores import MutableBackend
    4.10  from MoinMoin.storage.stores.memory import BytesStore, FileStore
    4.11 @@ -56,7 +57,7 @@
    4.12      meta_store = BytesStore()
    4.13      data_store = FileStore()
    4.14      _backend = MutableBackend(meta_store, data_store)
    4.15 -    namespaces = [('', u'backend')]
    4.16 +    namespaces = [(NAMESPACE_DEFAULT, u'backend')]
    4.17      backends = {u'backend': _backend}
    4.18      backend = RoutingBackend(namespaces, backends)
    4.19      backend.create()
     5.1 --- a/MoinMoin/storage/middleware/indexing.py	Sat Mar 02 18:23:08 2013 +0100
     5.2 +++ b/MoinMoin/storage/middleware/indexing.py	Sat Mar 02 23:27:40 2013 +0100
     5.3 @@ -77,6 +77,7 @@
     5.4                                       EXTERNALLINKS, ITEMLINKS, ITEMTRANSCLUSIONS, ACL, EMAIL, OPENID,
     5.5                                       ITEMID, REVID, CURRENT, PARENTID, PTIME, LATEST_REVS, ALL_REVS, BACKENDNAME)
     5.6  from MoinMoin.constants.contenttypes import CONTENTTYPE_USER
     5.7 +from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT
     5.8  from MoinMoin.constants import keys
     5.9  from MoinMoin.constants.keys import ITEMTYPE
    5.10  
    5.11 @@ -253,6 +254,8 @@
    5.12          common_fields = {
    5.13              # wikiname so we can have a shared index in a wiki farm, always check this!
    5.14              WIKINAME: ID(stored=True),
    5.15 +            # namespace, so we can have different namespaces within a wiki, always check this!
    5.16 +            NAMESPACE: ID(stored=True),
    5.17              # tokenized NAME from metadata - use this for manual searching from UI
    5.18              NAME: TEXT(stored=True, multitoken_query="and", analyzer=item_name_analyzer(), field_boost=2.0),
    5.19              # unmodified NAME from metadata - use this for precise lookup by the code.
     6.1 --- a/MoinMoin/storage/middleware/routing.py	Sat Mar 02 18:23:08 2013 +0100
     6.2 +++ b/MoinMoin/storage/middleware/routing.py	Sat Mar 02 23:27:40 2013 +0100
     6.3 @@ -51,6 +51,9 @@
     6.4          """
     6.5          self.namespaces = namespaces
     6.6          self.backends = backends
     6.7 +        for namespace, backend_name in namespaces:
     6.8 +            assert isinstance(namespace, unicode)
     6.9 +            assert backend_name in backends
    6.10  
    6.11      def open(self):
    6.12          for backend in self.backends.values():
     7.1 --- a/MoinMoin/user.py	Sat Mar 02 18:23:08 2013 +0100
     7.2 +++ b/MoinMoin/user.py	Sat Mar 02 23:27:40 2013 +0100
     7.3 @@ -36,6 +36,7 @@
     7.4  
     7.5  from MoinMoin import wikiutil
     7.6  from MoinMoin.constants.contenttypes import CONTENTTYPE_USER
     7.7 +from MoinMoin.constants.namespaces import NAMESPACE_USERPROFILES
     7.8  from MoinMoin.constants.keys import *
     7.9  from MoinMoin.constants.misc import ANON
    7.10  from MoinMoin.i18n import _, L_, N_
    7.11 @@ -101,6 +102,7 @@
    7.12  
    7.13  def update_user_query(**q):
    7.14      USER_QUERY_STDARGS = {
    7.15 +        NAMESPACE: NAMESPACE_USERPROFILES,
    7.16          CONTENTTYPE: CONTENTTYPE_USER,
    7.17          WIKINAME: app.cfg.interwikiname,  # XXX for now, search only users of THIS wiki
    7.18                                            # maybe add option to not index wiki users
    7.19 @@ -244,6 +246,7 @@
    7.20                force=True because these changes are not detected!
    7.21          """
    7.22          if self._changed or force:
    7.23 +            self[NAMESPACE] = NAMESPACE_USERPROFILES
    7.24              self[CONTENTTYPE] = CONTENTTYPE_USER
    7.25              q = {ITEMID: self[ITEMID]}
    7.26              q = update_user_query(**q)