sarumont / py-trello

Python API wrapper around Trello's API
BSD 3-Clause "New" or "Revised" License
945 stars 329 forks source link

Creating card with labels and updating card's labels use different data structure #279

Open unformatt opened 5 years ago

unformatt commented 5 years ago

add_card doc string says

:labels: a list of label IDs to be added

However, doesn't seem to be true because it expects objects with id property:

for label in labels:
                labels_str += label.id + ","

This makes it noodley to generalize code around managing labels via Trello API.

Mind if I submit a PR that supports both list of labels as ids and as objects with id property? Else a "fix" would not be backwards compatible.

e.g.

add_card(title, desc=desc, labels=['id1','id2'])
add_card(title, desc=desc, labels=[dict(id='id1'), dict(id='id2'))
unformatt commented 5 years ago

As a workaround, I created a unicode subclass with an id property that will work with both create and update card methods:


class TrelloLabel(unicode):

    @property
    def id(self):
        return unicode(self)

labels = [TrelloLabel('foo'), TrelloLabel('bar')]
# for creating card
print ','.join(labels)
# for updating card
print ','.join(t.id for t in labels)