Source code for trello.trellolist

# -*- coding: utf-8 -*-
from __future__ import with_statement, print_function, absolute_import

from trello import TrelloBase
from trello.compat import force_str


[docs]class List(TrelloBase): """ Class representing a Trello list. List attributes are stored on the object, but access to sub-objects (Cards) require an API call """ def __init__(self, board, list_id, name=''): """Constructor :board: reference to the parent board :list_id: ID for this list """ super(List, self).__init__() self.board = board self.client = board.client self.id = list_id self.name = name self.closed = None self.pos = None @classmethod
[docs] def from_json(cls, board, json_obj): """ Deserialize the list json object to a List object :board: the board object that the list belongs to :json_obj: the json list object """ list = List(board, json_obj['id'], name=json_obj['name']) list.closed = json_obj['closed'] list.pos = json_obj['pos'] return list
def __repr__(self): return force_str(u'<List %s>' % self.name)
[docs] def fetch(self): """Fetch all attributes for this list""" json_obj = self.client.fetch_json('/lists/' + self.id) self.name = json_obj['name'] self.closed = json_obj['closed'] self.pos = json_obj['pos']
[docs] def list_cards(self, card_filter="open", actions=None): """Lists all cards in this list""" query_params = {} if card_filter: query_params['filter'] = card_filter if actions: query_params['actions'] = actions json_obj = self.client.fetch_json('/lists/' + self.id + '/cards', query_params=query_params) return [Card.from_json(self, c) for c in json_obj]
[docs] def add_card(self, name, desc=None, labels=None, due="null", source=None, position=None, assign=None): """Add a card to this list :name: name for the card :desc: the description of the card :labels: a list of label IDs to be added :due: due date for the card :source: card ID from which to clone from :position: position of the card in the list. Must be "top", "bottom" or a positive number. :return: the card """ labels_str = "" if labels: for label in labels: labels_str += label.id + "," members_str = "" if assign: for assignee in assign: members_str += assignee.id + "," post_args = { 'name': name, 'idList': self.id, 'desc': desc, 'idLabels': labels_str[:-1], 'due': due, 'idMembers': members_str[:-1], 'idCardSource': source, } if position is not None: post_args["pos"] = position json_obj = self.client.fetch_json( '/cards', http_method='POST', post_args=post_args) return Card.from_json(self, json_obj)
[docs] def archive_all_cards(self): self.client.fetch_json( '/lists/' + self.id + '/archiveAllCards', http_method='POST')
[docs] def move_all_cards(self, destination_list): """ Move all cards of this list to another list. The list can be in the same board (or not). """ self.client.fetch_json( '/lists/' + self.id + '/moveAllCards', http_method='POST', post_args = { "idBoard": destination_list.board.id, "idList": destination_list.id, })
[docs] def fetch_actions(self, action_filter): """ Fetch actions for this list can give more argv to action_filter, split for ',' json_obj is list """ json_obj = self.client.fetch_json( '/lists/' + self.id + '/actions', query_params={'filter': action_filter}) self.actions = json_obj return self.actions
def _set_remote_attribute(self, attribute, value): self.client.fetch_json( '/lists/' + self.id + '/' + attribute, http_method='PUT', post_args={'value': value, }, )
[docs] def close(self): self.client.fetch_json( '/lists/' + self.id + '/closed', http_method='PUT', post_args={'value': 'true', }, ) self.closed = True
[docs] def open(self): self.client.fetch_json( '/lists/' + self.id + '/closed', http_method='PUT', post_args={'value': 'false', }, ) self.closed = False
# Move this list
[docs] def move(self, position): self.client.fetch_json( '/lists/' + self.id + '/pos', http_method='PUT', post_args={'value': position, }, ) self.pos = position
[docs] def cardsCnt(self): return len(self.list_cards())
# Change the name of the list
[docs] def set_name(self, name): self.client.fetch_json( '/lists/{list_id}/name'.format(list_id=self.id), http_method='PUT', post_args={'value': name}) self.name = name
# Change the position of the list
[docs] def set_pos(self, position): self.move(position)
from trello.card import Card