Skip to content

Commit

Permalink
Add position attribute to TrelloList's add_card method to allow creat…
Browse files Browse the repository at this point in the history
…ing cards in the top, bottom or an specific position of the list
  • Loading branch information
diegojromerolopez committed Jan 29, 2017
1 parent 5600b15 commit 8ef5552
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions trello/trellolist.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,34 @@ def list_cards(self, card_filter="open"):
json_obj = self.client.fetch_json('/lists/' + self.id + '/cards/' + card_filter)
return [Card.from_json(self, c) for c in json_obj]

def add_card(self, name, desc=None, labels=[], due="null", source=None):
def add_card(self, name, desc=None, labels=None, due="null", source=None, position="bottom"):
"""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 = ""
for label in labels:
labels_str += label.id + ","
if labels:
for label in labels:
labels_str += label.id + ","

json_obj = self.client.fetch_json(
'/cards',
http_method='POST',
post_args={'name': name, 'idList': self.id, 'desc': desc, 'idLabels': labels_str[:-1], 'due': due, 'idCardSource': source})
post_args={
'name': name,
'idList': self.id,
'desc': desc,
'idLabels': labels_str[:-1],
'due': due,
'idCardSource': source,
'pos': position
})
return Card.from_json(self, json_obj)

def archive_all_cards(self):
Expand Down

0 comments on commit 8ef5552

Please sign in to comment.