changeset 4799:fde7471cb2a3

Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Wed, 10 Jun 2009 20:32:37 +0200
parents ed977dd981ce
children 3b05bf18c0d1
files MoinMoin/_tests/wikiconfig_groups.py MoinMoin/groups/backends/__init__.py MoinMoin/groups/backends/config_group.py MoinMoin/groups/backends/wiki_group.py
diffstat 4 files changed, 60 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/wikiconfig_groups.py	Wed Jun 10 19:10:50 2009 +0200
+++ b/MoinMoin/_tests/wikiconfig_groups.py	Wed Jun 10 20:32:37 2009 +0200
@@ -12,4 +12,5 @@
 
 class Config(LocalConfig):
     group_manager_init = lambda self, request: GroupManager([wiki_group.Backend(request)])
+    config_groups = {}
 
--- a/MoinMoin/groups/backends/__init__.py	Wed Jun 10 19:10:50 2009 +0200
+++ b/MoinMoin/groups/backends/__init__.py	Wed Jun 10 20:32:37 2009 +0200
@@ -19,7 +19,7 @@
         """
         self.request = request
         self.name = name
-        self.backend = backend
+        self._backend = backend
 
         self.to_backend_name = backend.to_backend_name
         self.to_group_name = backend.to_group_name
@@ -107,6 +107,8 @@
 
     def __init__(self, request):
         self.request = request
+        self.page_group_regex = request.cfg.cache.page_group_regexact
+
 
     def __contains__(self, group_name):
         """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/groups/backends/config_group.py	Wed Jun 10 20:32:37 2009 +0200
@@ -0,0 +1,55 @@
+# -*- coding: iso-8859-1 -*-
+"""
+MoinMoin - config group backend
+
+The wiki group backend enables you to define groups in a configuration file.
+
+@copyright: 2009 MoinMoin:DmitrijsMilajevs
+@license: GPL, see COPYING for details
+"""
+
+from MoinMoin.groups.backends import BaseGroup, BaseBackend
+
+class Group(BaseGroup):
+    def _load_group(self):
+        request = self.request
+        backend_group_name = self.to_backend_name(self.name)
+
+        members_final = set()
+        member_groups = set()
+
+        for member in self._backend._groups[backend_group_name]:
+            if member in self._backend:
+                member_groups.add(self.to_group_name(member))
+            else:
+                members_final.add(member)
+
+        self.members = members_final
+        self.member_groups = member_groups
+
+class Backend(BaseBackend):
+
+    def __init__(self, request, groups=None):
+        """
+        @param groups: Dictionary of groups where key is group name,
+        and value is list of members of that group.
+
+        If <groups> is not defined request.cfg.config_groups is used.
+        """
+        super(Backend, self).__init__(request)
+
+        if groups is not None:
+            self._groups = groups
+        else:
+            self._groups = request.cfg.config_groups
+
+    def __contains__(self, group_name):
+        backend_group_name = self.to_backend_name(group_name)
+        return self.page_group_regex.match(group_name) and backend_group_name in self._groups
+
+    def __iter__(self):
+        backend_group_names = self._groups.keys()
+        return (self.to_group_name(backend_group_name) for backend_group_name in backend_group_names)
+
+    def __getitem__(self, group_name):
+        return Group(request=self.request, name=group_name, backend=self)
--- a/MoinMoin/groups/backends/wiki_group.py	Wed Jun 10 19:10:50 2009 +0200
+++ b/MoinMoin/groups/backends/wiki_group.py	Wed Jun 10 20:32:37 2009 +0200
@@ -64,7 +64,7 @@
         member_groups = set()
 
         for member in text_members:
-            if self.request.cfg.cache.page_group_regexact.match(member):
+            if self._backend.page_group_regex.match(member):
                 member_groups.add(self.to_group_name(member))
             else:
                 members_final.add(member)
@@ -74,11 +74,6 @@
 
 class Backend(BaseBackend):
 
-    def __init__(self, request):
-        super(Backend, self).__init__(request)
-
-        self.page_group_regex = request.cfg.cache.page_group_regexact
-
     def __contains__(self, group_name):
         backend_group_name = self.to_backend_name(group_name)
         return self.page_group_regex.match(group_name) and Page(self.request, backend_group_name).exists()