annotate MoinMoin/groups/backends/config_group.py @ 4805:6a109416e2b2

Groups2009: cfg.config_groups was removed.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Thu, 11 Jun 2009 14:08:13 +0200
parents 167db6117bb4
children dcbdf7e5660d
rev   line source
4799
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
2 """
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
3 MoinMoin - config group backend
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
4
4803
167db6117bb4 Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4800
diff changeset
5 The config group backend enables you to define groups in a configuration file.
4799
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
6
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
7 @copyright: 2009 MoinMoin:DmitrijsMilajevs
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
8 @license: GPL, see COPYING for details
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
9 """
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
10
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
11 from MoinMoin.groups.backends import BaseGroup, BaseBackend
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
12
4803
167db6117bb4 Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4800
diff changeset
13
4799
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
14 class Group(BaseGroup):
4803
167db6117bb4 Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4800
diff changeset
15
4799
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
16 def _load_group(self):
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
17 request = self.request
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
18 backend_group_name = self.to_backend_name(self.name)
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
19
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
20 members_final = set()
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
21 member_groups = set()
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
22
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
23 for member in self._backend._groups[backend_group_name]:
4800
3b05bf18c0d1 Groups2009: The BackendTest class provides basic test methods for testing backends. It should be inherited to test backends.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4799
diff changeset
24 if member in self._backend._groups:
4799
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
25 member_groups.add(self.to_group_name(member))
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
26 else:
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
27 members_final.add(member)
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
28
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
29 self.members = members_final
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
30 self.member_groups = member_groups
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
31
4803
167db6117bb4 Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4800
diff changeset
32
4799
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
33 class Backend(BaseBackend):
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
34
4805
6a109416e2b2 Groups2009: cfg.config_groups was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4803
diff changeset
35 def __init__(self, request, groups):
4799
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
36 """
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
37 @param groups: Dictionary of groups where key is group name,
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
38 and value is list of members of that group.
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
39 """
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
40 super(Backend, self).__init__(request)
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
41
4805
6a109416e2b2 Groups2009: cfg.config_groups was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents: 4803
diff changeset
42 self._groups = groups
4799
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
43
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
44 def __contains__(self, group_name):
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
45 backend_group_name = self.to_backend_name(group_name)
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
46 return self.page_group_regex.match(group_name) and backend_group_name in self._groups
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
47
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
48 def __iter__(self):
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
49 backend_group_names = self._groups.keys()
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
50 return (self.to_group_name(backend_group_name) for backend_group_name in backend_group_names)
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
51
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
52 def __getitem__(self, group_name):
fde7471cb2a3 Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
diff changeset
53 return Group(request=self.request, name=group_name, backend=self)