From f77239181e328ad00a5fa57e2be6c5de03878630 Mon Sep 17 00:00:00 2001 From: diegojromerolopez Date: Fri, 15 Apr 2016 21:01:18 +0200 Subject: [PATCH] List position should not be computed based on list.pos, it should be computed by an external function passed as a parameter --- trello/card.py | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/trello/card.py b/trello/card.py index d710b387..3fe8f671 100644 --- a/trello/card.py +++ b/trello/card.py @@ -283,37 +283,38 @@ def listCardMove_date(self): return self._list_movements(movement_function=Card._movement_as_triplet) - def list_movements(self, lists_dict=None): + def list_movements(self, list_cmp=None): """ Will return the history of transitions of a card from one list to another The lower the index the more resent the historical item It returns a list of dicts in date and time descending order (the first movement is the earliest). - Dicts are of the form source: destination: date: + Dicts are of the form source: destination: datetime: """ movement_as_dict_function = Card._movement_as_dict - if lists_dict: + if list_cmp: def movement_as_dict_function(_source_list, _destination_list, _movement_datetime): _movement = Card._movement_as_dict(_source_list, _destination_list, _movement_datetime) _source_list_id = _source_list["id"] _destination_list_id = _destination_list["id"] - _movement["moving_forward"] = lists_dict[_source_list_id].pos < lists_dict[_destination_list_id].pos + _movement["moving_forward"] = list_cmp(_source_list_id, _destination_list_id) > 0 return _movement return self._list_movements(movement_function=movement_as_dict_function) - def get_stats_by_list(self, tz, lists, done_list=None, time_unit="seconds"): + def get_stats_by_list(self, tz, lists, list_cmp=None, done_list=None, time_unit="seconds"): """ Gets the time that the card has been in each column in seconds (minutes or hours). Returns a dict where the key is list id and value is the time this card has been in that column. If the card has not been in a column, its id will not be in the dict. :param tz: timezone to make comparison timezone-aware :param lists: list of board lists. + :param list_cmp: function that compares two lists a,b given id_a, id_b. If b is in a forward position returns 1 else -1. :param time_unit: default to seconds. Allow specifying time in "minutes" or "hours". :param done_list: Column that implies that the task is done. If present, time measurement will be stopped if is current task list. - :return: dict of the form {list_id: {time:, }} + :return: dict of the form {list_id: {time: