コード例 #1
0
ファイル: smi.py プロジェクト: silvacms/silva.pas.base
    def __call__(self, form):
        data, errors = form.extractData()
        if errors:
            return silvaforms.FAILURE
        groupname = data.getDefault('group').strip()

        service = component.getUtility(IGroupService)
        groups = set()
        new_groups = set()
        try:
            for group in service.find_groups(groupname, location=form.context):
                groupid = group.groupid()
                groups.add(groupid)
                new_groups.add(groupid)
        except MemberLookupError as error:
            form.send_message(error.args[0], type="error")
            return silvaforms.FAILURE

        store = SessionStore(form.request)
        if new_groups:
            groups = store.get(GROUP_STORE_KEY, set()).union(groups)
            store.set(GROUP_STORE_KEY, groups)
            form.send_message(
                _(u"Found ${count} groups: ${groups}.",
                  mapping={'count': len(new_groups),
                           'groups': u', '.join(new_groups)}),
                type="feedback")
        else:
            form.send_message(
                _(u"No matching groups found."),
                type="error")
            return silvaforms.FAILURE
        return silvaforms.SUCCESS
コード例 #2
0
ファイル: access.py プロジェクト: silvacms/silva.core.smi
    def __call__(self, form):
        data, errors = form.extractData()
        if errors:
            form.send_message(
                _(u"Sorry, there were errors."),
                type="error")
            return silvaforms.FAILURE
        username = data['user'].strip()

        service = component.getUtility(IMemberService)
        users = set()
        new_users = set()
        try:
            for member in service.find_members(username, location=form.context):
                userid = member.userid()
                users.add(userid)
                new_users.add(userid)
        except MemberLookupError as error:
            form.send_message(error.args[0], type="error")
            return silvaforms.FAILURE

        store = SessionStore(form.request)
        if new_users:
            users = store.get(USER_STORE_KEY, set()).union(users)
            store.set(USER_STORE_KEY, users)
            form.send_message(
                _(u"Found ${count} users: ${users}.",
                  mapping={'count': len(new_users),
                           'users': u', '.join(new_users)}),
                type="feedback")
        else:
            form.send_message(
                _(u"No matching users were found."),
                type="error")
            return silvaforms.FAILURE
        return silvaforms.SUCCESS