Skip to content

Commit

Permalink
Updates to support attachments as per Walter's comments https://trell…
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Whalan committed Mar 16, 2016
1 parent 1325e31 commit bec258a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions trello/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bec258a

Please sign in to comment.