From bec258af618649bab021788ec230089da5c7158f Mon Sep 17 00:00:00 2001 From: Andrew Whalan Date: Wed, 16 Mar 2016 14:45:10 +1100 Subject: [PATCH] Updates to support attachments as per Walter's comments https://trello.com/c/5L574YgX/4-add-attachments-to-card --- trello/card.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/trello/card.py b/trello/card.py index 225c0e73..6c1e963a 100644 --- a/trello/card.py +++ b/trello/card.py @@ -81,6 +81,18 @@ def checklists(self): self._checklists = None return self._checklists + @property + def attachments(self): + """ + Lazily loads and returns the attachments + """ + try: + if self._attachments is None: + self._attachments = self.fetch_attachments() + except AttributeError: + self._attachments = None + return self._attachments + def __init__(self, parent, card_id, name=''): """ :trello_list: reference to the parent list @@ -154,6 +166,7 @@ def fetch(self, eager=True): self._checklists = self.fetch_checklists() if eager else None self._comments = self.fetch_comments() if eager else None + self._attachments = self.fetch_attachments() if eager else None def fetch_comments(self, force=False): comments = [] @@ -184,6 +197,19 @@ def fetch_checklists(self): trello_card=self.id)) return checklists + def fetch_attachments(self, force=False): + items = [] + + if (force is True) or (self.badges['attachments'] > 0): + items = self.client.fetch_json( + '/cards/' + self.id + '/attachments', + query_params={'filter':'false'}) + return items + return items + + def get_attachments(self): + return self.fetch_attachments(force=True) + def fetch_actions(self, action_filter='createCard'): """ Fetch actions for this card can give more argv to action_filter,