Skip to content

Commit

Permalink
Added the ability to add a label on card creation. Added a call to ad…
Browse files Browse the repository at this point in the history
…d a label to a card directly. Added a call to get all labels for a board
  • Loading branch information
larssorenson committed May 4, 2015
1 parent 016dcc1 commit b080626
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions trello/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ def get_lists(self, list_filter):
query_params={'cards': 'none', 'filter': list_filter})
return [List.from_json(board=self, json_obj=obj) for obj in json_obj]

def get_labels(self, fields='all', limit=50):
json_obj = self.client.fetch_json(
'/boards/' + self.id + '/labels',
query_params={'fields': fields, 'limit': limit})
return [Label.from_json(board=self, json_obj=obj) for obj in json_obj]

def add_list(self, name):
"""Add a list to this board
Expand Down Expand Up @@ -543,16 +549,21 @@ def list_cards(self):
json_obj = self.client.fetch_json('/lists/' + self.id + '/cards')
return [Card.from_json(self, c) for c in json_obj]

def add_card(self, name, desc=None):
def add_card(self, name, desc=None, labels=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
:return: the card
"""
labels_str = None
if labels:
labels_str = ",".join(labels)
json_obj = self.client.fetch_json(
'/lists/' + self.id + '/cards',
http_method='POST',
post_args={'name': name, 'idList': self.id, 'desc': desc}, )
post_args={'name': name, 'idList': self.id, 'desc': desc, 'idLabels': labels_str}, )
return Card.from_json(self, json_obj)

def fetch_actions(self, action_filter):
Expand Down Expand Up @@ -838,6 +849,12 @@ def comment(self, comment_text):
http_method='POST',
post_args={'text': comment_text, })

def add_label(self, label):
self.client.fetch_json(
'/cards/' + self.id +'/idLabels',
http_method='POST',
post_args={'value': label.id})

def attach(self, name=None, mimeType=None, file=None, url=None):
"""
Add an attachment to the card. The attachment can be either a
Expand Down

0 comments on commit b080626

Please sign in to comment.