view MoinMoin/datastruct/backends/ @ 1973:286e315935ae

refactor usage of constants don't import from config module, but from constants.* use uppercase for constant names
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 10 Feb 2013 22:50:21 +0100
parents 4ac437141bbe
children 949994a4c3cf
line wrap: on
line source
# Copyright: 2008 MoinMoin:ThomasWaldmann
# Copyright: 2009 MoinMoin:DmitrijsMilajevs
# Copyright: 2010 MoinMoin:ReimarBauer
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

MoinMoin - wiki group backend

The wiki_groups backend allows to define groups on wiki items.

Normally, the name of the group item has to end with Group like
FriendsGroup. This lets MoinMoin recognize it as a group. This default
pattern could be changed (e.g. for non-english languages etc.), see

from flask import g as flaskg

from MoinMoin.constants.keys import CURRENT, USERGROUP
from MoinMoin.datastruct.backends import GreedyGroup, BaseGroupsBackend, GroupDoesNotExistError

class WikiGroup(GreedyGroup):

    def _load_group(self):
        group_name =
        if flaskg.unprotected_storage.has_item(group_name):
            members, member_groups = super(WikiGroup, self)._load_group()
            return members, member_groups
            raise GroupDoesNotExistError(group_name)

class WikiGroups(BaseGroupsBackend):

    def __contains__(self, group_name):
        return self.is_group_name(group_name) and flaskg.unprotected_storage.has_item(group_name)

    def __iter__(self):
        To find group pages, app.cfg.cache.item_group_regexact pattern is used.
        # TODO: use whoosh to search for group_regex matching items
        item_list = [ for rev in flaskg.unprotected_storage.documents()
        return iter(item_list)

    def __getitem__(self, group_name):
        return WikiGroup(name=group_name, backend=self)

    def _retrieve_members(self, group_name):
        item = flaskg.unprotected_storage[group_name]
        rev = item[CURRENT]
        usergroup = rev.meta.get(USERGROUP, [])
        return usergroup