當前位置: 首頁>>代碼示例>>Python>>正文


Python interfaces.IWorkspace類代碼示例

本文整理匯總了Python中collective.workspace.interfaces.IWorkspace的典型用法代碼示例。如果您正苦於以下問題:Python IWorkspace類的具體用法?Python IWorkspace怎麽用?Python IWorkspace使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了IWorkspace類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: existing_users

def existing_users(context):
    """
    Look up the full user details for current workspace members
    """
    members = IWorkspace(context).members
    info = []
    for userid, details in members.items():
        user = api.user.get(userid)
        if user is None:
            continue
        user = user.getUser()
        title = user.getProperty("fullname") or user.getId() or userid
        # XXX tbd, we don't know what a persons description is, yet
        description = _(u"Here we could have a nice status of this person")
        classes = description and "has-description" or "has-no-description"
        portal = api.portal.get()
        portrait = "%s/portal_memberdata/portraits/%s" % (portal.absolute_url(), userid)
        info.append(
            dict(
                id=userid,
                title=title,
                description=description,
                portrait=portrait,
                cls=classes,
                member=True,
                admin="Admins" in details["groups"],
            )
        )

    return info
開發者ID:ploneintranet,項目名稱:ploneintranet.workspace,代碼行數:30,代碼來源:utils.py

示例2: existing_users

def existing_users(context):
    """
    Look up the full user details for current workspace members
    """
    members = IWorkspace(context).members
    info = []
    for userid, details in members.items():
        user = api.user.get(userid)
        if user is None:
            continue
        user = user.getUser()
        title = user.getProperty('fullname') or user.getId() or userid
        # XXX tbd, we don't know what a persons description is, yet
        description = ''
        classes = description and 'has-description' or 'has-no-description'
        portal = api.portal.get()
        portrait = '%s/@@avatars/%s' % \
                   (portal.absolute_url(), userid)
        info.append(
            dict(
                id=userid,
                title=title,
                description=description,
                portrait=portrait,
                cls=classes,
                member=True,
                admin='Admins' in details['groups'],
            )
        )

    return info
開發者ID:sudhan77,項目名稱:ploneintranet,代碼行數:31,代碼來源:utils.py

示例3: existing_users

    def existing_users(self):
        """
        Look up the full user details for current workspace members
        """
        members = IWorkspace(self).members
        info = []
        for userid, details in members.items():
            user = api.user.get(userid)
            if user is None:
                continue
            user = user.getUser()
            title = user.getProperty('fullname') or user.getId() or userid
            # XXX tbd, we don't know what a persons description is, yet
            description = MessageFactory(u'Here we could have a nice status of'
                                         u' this person')
            classes = description and 'has-description' or 'has-no-description'
            portrait = pi_api.userprofile.avatar_url(userid)
            info.append(
                dict(
                    id=userid,
                    title=title,
                    description=description,
                    portrait=portrait,
                    cls=classes,
                    member=True,
                    admin='Admins' in details['groups'],
                )
            )

        return info
開發者ID:smcmahon,項目名稱:ploneintranet,代碼行數:30,代碼來源:workspacefolder.py

示例4: invitation_accepted

def invitation_accepted(event):
    """
    When an invitation is accepted, add the user to the team
    """
    request = getRequest()
    storage = get_storage()
    if event.token_id not in storage:
        return

    ws_uid, username = storage[event.token_id]
    storage[event.token_id]
    acl_users = api.portal.get_tool("acl_users")
    acl_users.updateCredentials(request, request.response, username, None)
    catalog = api.portal.get_tool(name="portal_catalog")
    brain = catalog.unrestrictedSearchResults(UID=ws_uid)[0]
    with api.env.adopt_roles(["Manager"]):
        ws = IWorkspace(brain.getObject())
        for name in ws.members:
            member = api.user.get(username=name)
            if member is not None:
                if member.getUserName() == username:
                    api.portal.show_message(_("Oh boy, oh boy, you are already a member"), request)
                    break
        else:
            ws.add_to_team(user=username)
            api.portal.show_message(_("Welcome to our family, Stranger"), request)
開發者ID:smcmahon,項目名稱:ploneintranet,代碼行數:26,代碼來源:subscribers.py

示例5: participation_policy_changed

def participation_policy_changed(ob, event):
    """ Move all the existing users to a new group """
    workspace = IWorkspace(ob)
    old_group_name = workspace.group_for_policy(event.old_policy)
    old_group = api.group.get(old_group_name)
    for member in old_group.getAllGroupMembers():
        groups = workspace.get(member.getId()).groups
        groups -= set([event.old_policy.title()])
        groups.add(event.new_policy.title())
開發者ID:ploneintranet,項目名稱:ploneintranet.workspace,代碼行數:9,代碼來源:subscribers.py

示例6: test_acquired_roles_from_policy_settings

    def test_acquired_roles_from_policy_settings(self):
        self.login_as_portal_owner()
        policy = "moderators"
        self.workspace.participant_policy = policy
        ws = IWorkspace(self.workspace)
        ws.add_to_team(user=self.user.getUserName())
        roles = ws.available_groups.get(policy.title())
        self.request.form = {'form.button.Search': 'Search',
                             'search_term': 'demo'}
        view = SharingView(self.workspace, self.request)
        results = view.user_search_results()

        self.assertEqual(len(results), 1)
        self.assertTrue(
            all([results[0]["roles"][role] == "acquired" for role in roles]),
            "Acquired roles were not set correctly")
開發者ID:cedricmessiant,項目名稱:ploneintranet,代碼行數:16,代碼來源:test_views.py

示例7: existing_users

    def existing_users(self):
        members = IWorkspace(self.context).members
        info = []
        for userid, details in members.items():
            user = api.user.get(userid).getUser()
            title = user.getProperty('fullname') or user.getId() or userid
            info.append(
                dict(
                    id=userid,
                    title=title,
                    member=True,
                    admin='Admins' in details['groups'],
                )
            )

        return info
開發者ID:zestsoftware,項目名稱:ploneintranet.workspace,代碼行數:16,代碼來源:roster.py

示例8: setUp

 def setUp(self):
     self.app = self.layer["app"]
     self.portal = self.layer["portal"]
     self.request = self.layer["request"]
     z2.login(self.app["acl_users"], SITE_OWNER_NAME)
     self.user1 = api.user.create(email="[email protected]", username="user1", password="123")
     self.workspace = api.content.create(container=self.portal, type="Workspace", id="a-workspace")
     self.ws = IWorkspace(self.workspace)
開發者ID:tud-mit-plone,項目名稱:collective.workspace,代碼行數:8,代碼來源:test_workspace.py

示例9: __call__

    def __call__(self):
        if not self.context.join_policy == "self":
            msg = _(u"Workspace join policy doesn't allow self join")
            raise Unauthorized(msg)

        field = "button.join"
        req_method = self.request.method.lower()
        if req_method == "post" and field in self.request.form:
            user = api.user.get_current()
            workspace = IWorkspace(self.context)
            workspace.add_to_team(user=user.getId())
            msg = _(u"You are a member of this workspace now")
            api.portal.show_message(message=_(msg),
                                    request=self.request)

        referer = self.request.get("HTTP_REFERER", "").strip()
        if not referer:
            referer = self.context.absolute_url()
        return self.request.response.redirect(referer)
開發者ID:smcmahon,項目名稱:ploneintranet,代碼行數:19,代碼來源:views.py

示例10: test_add_admin_to_workspace

    def test_add_admin_to_workspace(self):
        """ check that site admin can add team admin to the workspace """
        self.login_as_portal_owner()
        ws = self.create_unadapted_workspace()
        user = self.create_user()
        groups = api.group.get_groups()
        group_names = [x.getName() for x in groups]
        group_name = 'Admins:%s' % (api.content.get_uuid(ws))
        self.assertIn(
            group_name,
            group_names
        )
        workspace = IWorkspace(ws)
        workspace.add_to_team(user=user.getId(), groups=set([u"Admins"]))

        portal = api.portal.get()
        pgroups = portal.portal_groups.getGroupById(group_name)
        member_ids = pgroups.getGroup().getMemberIds()
        self.assertIn(user.getId(),
                      member_ids)
開發者ID:smcmahon,項目名稱:ploneintranet,代碼行數:20,代碼來源:test_content_type.py

示例11: user_search_results

    def user_search_results(self):
        """ Add [member] to a user title if user is a member
        of current workspace
        """
        results = super(SharingView, self).user_search_results()
        ws = IWorkspace(self.context)
        roles_mapping = ws.available_groups
        roles = roles_mapping.get(self.context.participant_policy.title())

        for result in results:
            if result["id"] in ws.members:
                groups = ws.get(result["id"]).groups
                for role in roles:
                    result["roles"][role] = "acquired"
                if "Admins" in groups:
                    title = "administrator"
                    result["roles"]["TeamManager"] = "acquired"
                else:
                    title = "member"
                result["title"] = "%s [%s]" % (result["title"], title)

        return results
開發者ID:smcmahon,項目名稱:ploneintranet,代碼行數:22,代碼來源:views.py

示例12: handleApply

    def handleApply(self, action):
        data = self.extractData()[0]

        ws = IWorkspace(self.context)
        other_ws_id = data.get("workspace")
        other_ws = IWorkspace(api.content.get(UID=other_ws_id))
        move = data.get("move", False)
        removable = []
        for member in ws.members:
            user = api.user.get(username=member)
            if user is not None:
                user_id = user.getId()
                other_ws.add_to_team(user=user_id)
            removable.append(member)

        if move:
            func = lambda member: ws.membership_factory(
                ws,
                {"user": member}).remove_from_team()
            map(func, removable)

        self.updateWidgets()
        self.status = "Members transfered."
開發者ID:smcmahon,項目名稱:ploneintranet,代碼行數:23,代碼來源:forms.py

示例13: setUp

 def setUp(self):
     self.app = self.layer['app']
     self.portal = self.layer['portal']
     self.request = self.layer['request']
     z2.login(self.app['acl_users'], SITE_OWNER_NAME)
     self.user1 = api.user.create(
         email='[email protected]',
         username='user1',
         password='123'
     )
     self.workspace = api.content.create(
         container=self.portal,
         type='Workspace',
         id='a-workspace'
     )
     self.ws = IWorkspace(self.workspace)
開發者ID:collective,項目名稱:collective.workspace,代碼行數:16,代碼來源:test_workspace.py

示例14: update_users

    def update_users(self, entries):
        """Update user properties on the roster """
        ws = IWorkspace(self.context)
        members = ws.members

        # check user permissions against join policy
        join_policy = self.context.join_policy
        if (join_policy == "admin"
            and not checkPermission(
                "collective.workspace: Manage roster",
                self.context)):
            raise Unauthorized("You are not allowed to add users here")

        for entry in entries:
            id = entry.get('id')
            is_member = bool(entry.get('member'))
            is_admin = bool(entry.get('admin'))

            # Existing members
            if id in members:
                member = members[id]
                if not is_member:
                    if checkPermission(
                            "ploneintranet.workspace: Manage workspace",
                            self.context):
                        ws.membership_factory(ws, member).remove_from_team()
                    else:
                        raise Unauthorized(
                            "Only team managers can remove members")
                elif not is_admin:
                    ws.membership_factory(ws, member).groups -= {'Admins'}
                else:
                    ws.membership_factory(ws, member).groups |= {'Admins'}

            # New members
            elif id not in members and (is_member or is_admin):
                groups = set()
                if is_admin:
                    groups.add('Admins')
                ws.add_to_team(user=id, groups=groups)
開發者ID:cedricmessiant,項目名稱:ploneintranet,代碼行數:40,代碼來源:roster.py

示例15: TestWorkspace

class TestWorkspace(unittest.TestCase):
    layer = COLLECTIVE_WORKSPACE_INTEGRATION_TESTING

    def setUp(self):
        self.app = self.layer["app"]
        self.portal = self.layer["portal"]
        self.request = self.layer["request"]
        z2.login(self.app["acl_users"], SITE_OWNER_NAME)
        self.user1 = api.user.create(email="[email protected]", username="user1", password="123")
        self.workspace = api.content.create(container=self.portal, type="Workspace", id="a-workspace")
        self.ws = IWorkspace(self.workspace)

    def test_add_to_team(self):
        self.ws.add_to_team(user=self.user1.getId())
        self.assertIn(self.user1.getId(), list(self.ws.members))

    def test_remove_from_team(self):
        self.ws.add_to_team(user=self.user1.getId())
        self.ws.remove_from_team(user=self.user1.getId())
        self.assertNotIn(self.user1.getId(), list(self.ws.members))
開發者ID:tud-mit-plone,項目名稱:collective.workspace,代碼行數:20,代碼來源:test_workspace.py


注:本文中的collective.workspace.interfaces.IWorkspace類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。