Beispiel #1
0
    def add_by_group(self, group, statuses):
        """
        Makes all members of a particular group part of this group

        :param group: The group to copy members from
        :type group: :class:`Group`
        :param statuses: Set of statuses to add
        :type statuses: :class:`list` of :class:`str`
        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> grp = acct.groups[1024]
            >>> grp.members.add_by_group(acct.groups[199])
            None
            >>> from emma.enumerations import MemberStatus
            >>> grp.members.add_by_group(acct.groups[200], [MemberStatus.Active])
            None
        """
        if 'member_group_id' not in self.group:
            raise ex.NoGroupIdError()
        if 'member_group_id' not in group:
            raise ex.NoGroupIdError()

        path = '/groups/%s/%s/members/copy' % (
            group['member_group_id'],
            self.group['member_group_id'])
        data = {'member_status_id': statuses} if statuses else {}
        if not self.group.account.adapter.put(path, data):
            raise ex.MemberCopyToGroupError()
Beispiel #2
0
    def remove_all(self, status=None):
        """
        Remove all members from this group

        :param status: A status to remove
        :type status: :class:`str`
        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> from emma.enumerations import MemberStatus
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> grp = acct.groups[1024]
            >>> grp.members.remove_all(MemberStatus.Active)
            None
            >>> grp.members.remove_all()
            None
        """
        if 'member_group_id' not in self.group:
            raise ex.NoGroupIdError()

        path = '/groups/%s/members' % self.group['member_group_id']
        params = {'member_status_id': status} if status else {}
        if self.group.account.adapter.delete(path, params):
            self._dict = {}
Beispiel #3
0
    def remove_by_id(self, member_ids=None):
        """
        Remove given members from this group

        :param member_ids: Set of identifiers to remove
        :type member_ids: :class:`list` of :class:`int`
        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> grp = acct.groups[1024]
            >>> grp.members.remove_by_id([200, 201])
            None
        """
        if 'member_group_id' not in self.group:
            raise ex.NoGroupIdError()
        if not member_ids:
            return None

        path = '/groups/%s/members/remove' % self.group['member_group_id']
        data = {'member_ids': member_ids}
        removed = self.group.account.adapter.put(path, data)
        self._dict = dict(x for x in self._dict.items() if x[0] not in removed)
Beispiel #4
0
    def add_by_status(self, statuses=None):
        """
        Makes all members of a particular status part of this group

        :param statuses: Set of statuses to add
        :type statuses: :class:`list` of :class:`str`
        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> from emma.enumerations import MemberStatus
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> grp = acct.groups[1024]
            >>> grp.members.add_by_status([MemberStatus.Active])
            None
        """
        if 'member_group_id' not in self.group:
            raise ex.NoGroupIdError()
        if not statuses:
            return None

        path = '/members/%s/copy' % self.group['member_group_id']
        data = {'member_status_id': statuses}
        if not self.group.account.adapter.put(path, data):
            raise ex.MemberCopyToGroupError()
Beispiel #5
0
    def fetch_all(self, deleted=False):
        """
        Lazy-loads the set of :class:`Member` objects

        :param deleted: Include deleted members
        :type deleted: :class:`bool`
        :rtype: :class:`dict` of :class:`Member` objects

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> grp = acct.groups[1024]
            >>> grp.members.fetch_all()
            {200: <Member>, 201: <Member>, ...}
        """
        if not 'member_group_id' in self.group:
            raise ex.NoGroupIdError()

        member = emma.model.member
        path = '/groups/%s/members' % self.group['member_group_id']
        params = {'deleted': True} if deleted else {}
        if not self._dict:
            self._dict = dict(
                (x['member_id'], member.Member(self.group.account, x))
                    for x in self.group.account.adapter.paginated_get(path, params))
        return self._dict
Beispiel #6
0
    def delete(self):
        """
        Delete this group

        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> grp = acct.groups[123]
            >>> grp.delete()
            None
        """
        if not 'member_group_id' in self._dict:
            raise ex.NoGroupIdError()
        if self.is_deleted():
            return None

        path = "/groups/%s" % self._dict['member_group_id']
        if self.account.adapter.delete(path):
            self._dict['deleted_at'] = datetime.now()
        if self._dict['member_group_id'] in self.account.groups:
            del(self.account.groups._dict[self._dict['member_group_id']])
Beispiel #7
0
    def add_by_id(self, member_ids=None):
        """
        Makes given members part of this group

        :param member_ids: Set of identifiers to add
        :type member_ids: :class:`list` of :class:`int`
        :rtype: :class:`None`

        Usage::

            >>> from emma.model.account import Account
            >>> acct = Account(1234, "08192a3b4c5d6e7f", "f7e6d5c4b3a29180")
            >>> grp = acct.groups[1024]
            >>> grp.members.add_by_id([200, 201])
            None
        """
        if 'member_group_id' not in self.group:
            raise ex.NoGroupIdError()
        if not member_ids:
            return None

        path = '/groups/%s/members' % self.group['member_group_id']
        data = {'member_ids': member_ids}
        self.group.account.adapter.put(path, data)