Esempio n. 1
0
    def _log_update_card(self, data, **kwargs):
        board = kwargs.get('board', None)
        try:
            list_id = data['action']['data']['card']['idList']
        except:
            list_id = data['action']['data']['list']['id']
        l = board.get_list(list_id)
        card = Card(l, data['action']['data']['card']['id'])
        card.fetch()

        entry = {
            "actor": data['action']['memberCreator'],
            "action": {
                "type": data['action']['type'],
                "translation_key": data['action']['display']['translationKey'],
            },
            "data": data['action']['data'],
            "complaint": {
                'id':
                card.id,
                'name':
                card.name,
                'desc':
                card.desc,
                'closed':
                card.closed,
                'url':
                card.url,
                'shortUrl':
                card.shortUrl,
                'idMembers':
                card.idMembers,
                'idShort':
                card.idShort,
                'idList':
                card.idList,
                'idBoard':
                card.idBoard,
                'idLabels':
                card.idLabels,
                'labels':
                [label.name for label in card.labels] if card.labels else None,
                'badges':
                card.badges,
                'pos':
                card.pos,
                'due':
                card.due,
                'checked':
                card.checked,
                'dateLastActivity':
                card.dateLastActivity,
                'comments':
                card._comments,
            },
            "action_date": dateutil.parser.parse(data['action']['date'])
        }
        return entry
Esempio n. 2
0
    def get_card(self, card_id):
        '''Get card

        :rtype: Card
        '''
        card_json = self.fetch_json('/cards/' + card_id)
        list_json = self.fetch_json('/lists/' + card_json['idList'])
        board = self.get_board(card_json['idBoard'])
        return Card.from_json(List.from_json(board, list_json), card_json)
Esempio n. 3
0
    def get_card(self, card_id):
        """Get card

        :rtype: Card
        """
        card_json = self.fetch_json('/cards/' + card_id)
        list_json = self.fetch_json('/lists/' + card_json['idList'])
        board = self.get_board(card_json['idBoard'])
        return Card.from_json(List.from_json(board, list_json), card_json)
Esempio n. 4
0
    def get_card(self, card_id):
        """Get card

        :rtype: Card
        """
        card_json = self.fetch_json('/cards/' + card_id, query_params={'customFieldItems': 'true'})
        list_json = self.fetch_json('/lists/' + card_json['idList'])
        board = self.get_board(card_json['idBoard'])
        return Card.from_json(List.from_json(board, list_json), card_json)
Esempio n. 5
0
    def get_cards(self, filters=None):
        """
        :card_filter: filters on card status ('open', 'closed', 'all')
        :query_params: dict containing query parameters. Eg. {'fields': 'all'}

        More info on card queries:
        https://trello.com/docs/api/board/index.html#get-1-boards-board-id-cards

        :rtype: Card
        """
        json_obj = self.client.fetch_json('/boards/' + self.id + '/cards',
                                          query_params=filters)

        return list([Card.from_json(self, json) for json in json_obj])
Esempio n. 6
0
File: list.py Progetto: i077/trcli
def list_cards(list_id):
    cards_response = request.get('1/lists/{}/cards'.format(list_id),
                                 {'filter': 'open'})
    cards = []

    for card_data in cards_response:
        cards.append(Card(card_data))

    print('Cards in {}{}{}:'.format(
        attr(1),
        request.get('1/lists/{}'.format(list_id), {'fields': 'name'})['name'],
        attr(0)))
    for card in cards:
        with indent():
            card.short_print()
Esempio n. 7
0
    def get_cards(self):
        """ Get all cards for this list """
        json_obj = self.client.fetch_json("/lists/" + self.id + "/cards")

        cards = []
        for obj in json_obj:
            name = obj["name"]
            dateLastActivity = obj["dateLastActivity"]
            cards.append(
                Card(self.client,
                     obj["id"],
                     name=name,
                     dateLastActivity=dateLastActivity))

        return cards
Esempio n. 8
0
    def get_cards(self, filters=None, card_filter=""):
        """
        :card_filter: filters on card status ('open', 'closed', 'all')
        :query_params: dict containing query parameters. Eg. {'fields': 'all'}

        More info on card queries:
        https://trello.com/docs/api/board/index.html#get-1-boards-board-id-cards

        :rtype: list of Card
        """
        json_obj = self.client.fetch_json(
            '/boards/' + self.id + '/cards/' + card_filter,
            query_params=filters
        )

        return list([Card.from_json(self, json) for json in json_obj])
Esempio n. 9
0
    def search(self, query, partial_match=False, models=[],
               board_ids=[], org_ids=[], card_ids=[], cards_limit=10):
        """
        Search trello given a query string.

        :param str query: A query string up to 16K characters
        :param bool partial_match: True means that trello will look for
                content that starts with any of the words in your query.
        :param list models: Comma-separated list of types of objects to search.
                This can be 'actions', 'boards', 'cards', 'members',
                or 'organizations'.  The default is 'all' models.
        :param list board_ids: Comma-separated list of boards to limit search
        :param org_ids: Comma-separated list of organizations to limit search
        :param card_ids: Comma-separated list of cards to limit search
        :param cards_limit: The maximum number of cards to return (up to 1000)

        :return: All objects matching the search criterial.  These can
            be Cards, Boards, Organizations, and Members.  The attributes
            of the objects in the results are minimal; the user must call
            the fetch method on the resulting objects to get a full set
            of attributes populated.
        :rtype list:
        """

        query_params = {'query': query}

        if partial_match:
            query_params['partial'] = 'true'

        # Limit search to one or more object types
        if models:
            query_params['modelTypes'] = models

        # Limit search to a particular subset of objects
        if board_ids:
            query_params['idBoards'] = board_ids
        if org_ids:
            query_params['idOrganizations'] = org_ids
        if card_ids:
            query_params['idCards'] = card_ids
        query_params['cards_limit'] = cards_limit

        # Request result fields required to instantiate class objects
        query_params['board_fields'] = ['name,url,desc,closed']
        query_params['member_fields'] = ['fullName,initials,username']
        query_params['organization_fields'] = ['name,url,desc']

        json_obj = self.fetch_json('/search', query_params=query_params)
        if not json_obj:
            return []

        results = []
        board_cache = {}

        for board_json in json_obj.get('boards', []):
            # Cache board objects
            if board_json['id'] not in board_cache:
                board_cache[board_json['id']] = Board.from_json(
                    self, json_obj=board_json)
            results.append(board_cache[board_json['id']])

        for card_json in json_obj.get('cards', []):
            # Cache board objects
            if card_json['idBoard'] not in board_cache:
                board_cache[card_json['idBoard']] = Board(
                    self, card_json['idBoard'])
                # Fetch the board attributes as the Board object created
                # from the card initially result lacks a URL and name.
                # This Board will be stored in Card.parent
                board_cache[card_json['idBoard']].fetch()
            results.append(Card.from_json(board_cache[card_json['idBoard']],
                                          card_json))

        for member_json in json_obj.get('members', []):
            results.append(Member.from_json(self, member_json))

        for org_json in json_obj.get('organizations', []):
            org = Organization.from_json(self, org_json)
            results.append(org)

        return results
Esempio n. 10
0
    def search(self,
               query,
               partial_match=False,
               models=[],
               board_ids=[],
               org_ids=[],
               card_ids=[]):
        """
        Search trello given a query string.

        :param str query: A query string up to 16K characters
        :param bool partial_match: True means that trello will look for
                content that starts with any of the words in your query.
        :param list models: Comma-separated list of types of objects to search.
                This can be 'actions', 'boards', 'cards', 'members',
                or 'organizations'.  The default is 'all' models.
        :param list board_ids: Comma-separated list of boards to limit search
        :param org_ids: Comma-separated list of organizations to limit search
        :param card_ids: Comma-separated list of cards to limit search

        :return: All objects matching the search criterial.  These can
            be Cards, Boards, Organizations, and Members.  The attributes
            of the objects in the results are minimal; the user must call
            the fetch method on the resulting objects to get a full set
            of attributes populated.
        :rtype list:
        """

        query_params = {'query': query}

        if partial_match:
            query_params['partial'] = 'true'

        # Limit search to one or more object types
        if models:
            query_params['modelTypes'] = models

        # Limit search to a particular subset of objects
        if board_ids:
            query_params['idBoards'] = board_ids
        if org_ids:
            query_params['idOrganizations'] = org_ids
        if card_ids:
            query_params['idCards'] = card_ids

        # Request result fields required to instantiate class objects
        query_params['board_fields'] = ['name,url,desc,closed']
        query_params['member_fields'] = ['fullName,initials,username']
        query_params['organization_fields'] = ['name,url,desc']

        json_obj = self.fetch_json('/search', query_params=query_params)
        if not json_obj:
            return []

        results = []
        board_cache = {}

        for board_json in json_obj.get('boards', []):
            # Cache board objects
            if board_json['id'] not in board_cache:
                board_cache[board_json['id']] = Board.from_json(
                    self, json_obj=board_json)
            results.append(board_cache[board_json['id']])

        for card_json in json_obj.get('cards', []):
            # Cache board objects
            if card_json['idBoard'] not in board_cache:
                board_cache[card_json['idBoard']] = Board(
                    self, card_json['idBoard'])
                # Fetch the board attributes as the Board object created
                # from the card initially result lacks a URL and name.
                # This Board will be stored in Card.parent
                board_cache[card_json['idBoard']].fetch()
            results.append(
                Card.from_json(board_cache[card_json['idBoard']], card_json))

        for member_json in json_obj.get('members', []):
            results.append(Member.from_json(self, member_json))

        for org_json in json_obj.get('organizations', []):
            org = Organization.from_json(self, org_json)
            results.append(org)

        return results