Skip to content

Commit

Permalink
introduce Board.get_last_activity()
Browse files Browse the repository at this point in the history
There is no `dateLastActivity` key anymore in the board JSON. The
official documentation does not speak about the field neither. This
commit introduce the `get_last_activity()` to retrieve the board last
activity. It returns a regular datetime instance.

It also maintains the `Board.date_last_activity` attribute to preserve
the compatibilty with the old code base.

See: https://developers.trello.com/advanced-reference/board
  • Loading branch information
goneri committed May 24, 2017
1 parent ba8787c commit a94a813
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 4 additions & 0 deletions test/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ def test130_get_checklists_board(self):
self.assertEqual(i2['name'], "item2")
self.assertEqual(i2['state'], "incomplete")

def test_last_activity(self):
self.assertIsInstance(self._board.date_last_activity, datetime)
self.assertIsInstance(self._board.get_last_activity(), datetime)

def suite():
# tests = ['test01_list_boards', 'test10_board_attrs', 'test20_add_card']
# return unittest.TestSuite(map(TrelloBoardTestCase, tests))
Expand Down
21 changes: 10 additions & 11 deletions trello/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ def __init__(self, client=None, board_id=None, organization=None, name=''):
self.client = organization.client
self.id = board_id
self.name = name

self.date_last_activity = None
self.date_last_activity = self.get_last_activity()

@classmethod
def from_json(cls, trello_client=None, organization=None, json_obj=None):
Expand All @@ -64,11 +63,6 @@ def from_json(cls, trello_client=None, organization=None, json_obj=None):
board.closed = json_obj['closed']
board.url = json_obj['url']

try:
board.date_last_activity = dateparser.parse(json_obj['dateLastActivity'])
except:
pass

return board

def __repr__(self):
Expand All @@ -81,10 +75,6 @@ def fetch(self):
self.description = json_obj.get('desc', '')
self.closed = json_obj['closed']
self.url = json_obj['url']
try:
self.date_last_activity = dateparser.parse(json_obj['dateLastActivity'])
except:
self.date_last_activity = None

# Saves a Trello Board
def save(self):
Expand Down Expand Up @@ -396,3 +386,12 @@ def fetch_actions(self, action_filter, action_limit=50, before=None, since=None)

self.actions = json_obj
return self.actions

def get_last_activity(self):
"""Return the date of the last action done on the board.
:rtype: datetime.datetime
"""
json_obj = self.client.fetch_json(
'/boards/{0}/dateLastActivity'.format(self.id))
return dateparser.parse(json_obj['_value'])

0 comments on commit a94a813

Please sign in to comment.