예제 #1
0
    def add_board(self,
                  board_name,
                  source_board=None,
                  organization_id=None,
                  permission_level='private',
                  default_lists=True):
        """Create board
        :param board_name: Name of the board to create
        :param source_board: Optional Board to copy
        :param permission_level: Permission level, defaults to private
        :rtype: Board
        """
        post_args = {
            'name': board_name,
            'prefs_permissionLevel': permission_level
        }
        if source_board is not None:
            post_args['idBoardSource'] = source_board.id
        if organization_id is not None:
            post_args['idOrganization'] = organization_id
        if not default_lists:
            post_args['defaultLists'] = False

        obj = self.fetch_json('/boards',
                              http_method='POST',
                              post_args=post_args)
        return Board.from_json(self, json_obj=obj)
예제 #2
0
    def get_board(self, board_id):
        """Get board

        :rtype: Board
        """
        obj = self.fetch_json('/boards/' + board_id)
        return Board.from_json(self, json_obj=obj)
예제 #3
0
    def get_board(self, board_id):
        '''Get board

        :rtype: Board
        '''
        obj = self.fetch_json('/boards/' + board_id)
        return Board.from_json(self, json_obj=obj)
예제 #4
0
    def add_board(self, board_name):
        '''Create board

        :rtype: Board
        '''
        obj = self.fetch_json('/boards', http_method='POST',
                              post_args={'name': board_name})
        return Board.from_json(self, json_obj=obj)
예제 #5
0
    def get_board(self, field_name):
        """Get board

        :rtype: list of Board
        """
        # error checking
        json_obj = self.client.fetch_json(
            '/organizations/' + self.id + '/boards',
            query_params={'filter': 'open', 'fields': field_name})
        return [Board.from_json(organization=self, json_obj=obj) for obj in json_obj]
예제 #6
0
    def get_boards(self, list_filter):
        """Get boards using filter

        :rtype: list of Board
        """
        # error checking
        json_obj = self.client.fetch_json(
            '/organizations/' + self.id + '/boards',
            query_params={'lists': 'none', 'filter': list_filter})
        return [Board.from_json(organization=self, json_obj=obj) for obj in json_obj]
예제 #7
0
    def get_boards(self, list_filter):
        """Get boards using filter

        :rtype: list of Board
        """
        from trello.board import Board
        json_obj = self.client.fetch_json(
            '/organizations/' + self.id + '/boards',
            query_params={'lists': 'none', 'filter': list_filter})
        return [Board.from_json(organization=self, json_obj=obj) for obj in json_obj]
예제 #8
0
    def add_board(self, board_name, organization_id=None):
        '''Create board

        :rtype: Board
        '''
        post_args = {'name': board_name}
        if organization_id:
            post_args['idOrganization'] = organization_id
        obj = self.fetch_json('/boards', http_method='POST', post_args=post_args)
        return Board.from_json(self, json_obj=obj)
예제 #9
0
    def get_board(self, field_name):
        """Get board

        :rtype: list of Board
        """
        from trello.board import Board
        json_obj = self.client.fetch_json(
            '/organizations/' + self.id + '/boards',
            query_params={'filter': 'open', 'fields': field_name})
        return [Board.from_json(organization=self, json_obj=obj) for obj in json_obj]
예제 #10
0
    def add_board(self, board_name, source_board=None):
        '''Create board
        :param board_name: Name of the board to create
        :param source_board: Optional Board to copy
        :rtype: Board
        '''
        post_args = {'name': board_name}
        if source_board is not None:
            post_args['idBoardSource'] = source_board.id

        obj = self.fetch_json('/boards',
                              http_method='POST',
                              post_args=post_args)
        return Board.from_json(self, json_obj=obj)
예제 #11
0
    def add_board(self, board_name, source_board=None, organization_id=None):
        '''Create board
        :param board_name: Name of the board to create
        :param source_board: Optional Board to copy
        :rtype: Board
        '''
        post_args={'name': board_name}
        if source_board is not None:
            post_args['idBoardSource'] = source_board.id
        if organization_id is not None:
            post_args['idOrganization'] = organization_id

        obj = self.fetch_json('/boards', http_method='POST',
                              post_args=post_args)
        return Board.from_json(self, json_obj=obj)
예제 #12
0
    def add_board(self, board_name, source_board=None, **arguments):
        '''Create board
        :param board_name: Name of the board to create
        :param source_board: Optional Board to copy
        :param parameters: Arguments to the API call
        :rtype: Board
        '''
        post_args={'name': board_name}
        post_args.update(arguments)
        if source_board is not None:
            post_args['idBoardSource'] = source_board.id

        obj = self.fetch_json('/boards', http_method='POST',
                              post_args=post_args)
        return Board.from_json(self, json_obj=obj)
예제 #13
0
    def get_boards(self, list_filter):
        '''Get boards using filter

        :rtype: Board
        '''
        # error checking
        json_obj = self.client.fetch_json('/organizations/' + self.id +
                                          '/boards',
                                          query_params={
                                              'lists': 'none',
                                              'filter': list_filter
                                          })
        return [
            Board.from_json(organization=self, json_obj=obj)
            for obj in json_obj
        ]
예제 #14
0
    def add_board(self, board_name, source_board=None, organization_id=None, permission_level='private'):
        """Create board
        :param board_name: Name of the board to create
        :param source_board: Optional Board to copy
        :param permission_level: Permission level, defaults to private
        :rtype: Board
        """
        post_args={'name': board_name, 'prefs_permissionLevel': permission_level}
        if source_board is not None:
            post_args['idBoardSource'] = source_board.id
        if organization_id is not None:
            post_args['idOrganization'] = organization_id

        obj = self.fetch_json('/boards', http_method='POST',
                              post_args=post_args)
        return Board.from_json(self, json_obj=obj)
예제 #15
0
    def get_board(self, field_name):
        '''Get board

        :rtype: Board
        '''
        # error checking
        json_obj = self.client.fetch_json('/organizations/' + self.id +
                                          '/boards',
                                          query_params={
                                              'filter': 'open',
                                              'fields': field_name
                                          })
        return [
            Board.from_json(organization=self, json_obj=obj)
            for obj in json_obj
        ]
예제 #16
0
 def post(self, request):
     try:
         data = request.data
         logging.info(data)
         board = Board.from_json(trello_client=g.trello_client,
                                 json_obj=request.data['model'])
         action_type_str = self._get_action_type(data)
         action_type_enum = self._get_enum(e.ActionType, action_type_str)
         if action_type_enum:
             self._map_n_act_n_save_log(action_type_enum, data, board=board)
             logging.info('<LogSaved> for {}'.format(action_type_str))
         else:
             logging.info('<LogNOTSaved> for {}'.format(action_type_str))
         return HttpResponse('OK')
     except:
         return h.error_response(500, "Internal server error")
예제 #17
0
    def list_boards(self, board_filter="all"):
        """
        Returns all boards for your Trello user

        :return: a list of Python objects representing the Trello boards.
        :rtype: Board

        Each board has the following noteworthy attributes:
            - id: the board's identifier
            - name: Name of the board
            - desc: Description of the board (optional - may be missing from the
                    returned JSON)
            - closed: Boolean representing whether this board is closed or not
            - url: URL to the board
        """
        json_obj = self.fetch_json('/members/me/boards/?filter=%s' % board_filter)
        return [Board.from_json(self, json_obj=obj) for obj in json_obj]
예제 #18
0
    def list_boards(self, board_filter="all"):
        """
        Returns all boards for your Trello user

        :return: a list of Python objects representing the Trello boards.
        :rtype: Board

        Each board has the following noteworthy attributes:
            - id: the board's identifier
            - name: Name of the board
            - desc: Description of the board (optional - may be missing from the
                    returned JSON)
            - closed: Boolean representing whether this board is closed or not
            - url: URL to the board
        """
        json_obj = self.fetch_json('/members/me/boards/?filter=%s' % board_filter)
        return [Board.from_json(self, json_obj=obj) for obj in json_obj]
예제 #19
0
    def get_boards(self, list_filter):
        """Get boards using filter

        :rtype: list of Board
        """
        from trello.board import Board
        from trello.organization import Organization
        json_obj = self.client.fetch_json('/members/' + self.id + '/boards',
                                          query_params={
                                              'lists': 'none',
                                              'filter': list_filter
                                          })
        organizations = {
            obj['idOrganization']:
            self.client.get_organization(obj['idOrganization'])
            for obj in json_obj if obj['idOrganization']
        }
        return [
            Board.from_json(trello_client=self.client,
                            organization=organizations.get(
                                obj['idOrganization']),
                            json_obj=obj) for obj in json_obj
        ]
예제 #20
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
예제 #21
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