def add_checklist(self, title, items, itemstates=None): """Add a checklist to this card :title: title of the checklist :items: a list of the item names :itemstates: a list of the state (True/False) of each item :return: the checklist """ if itemstates is None: itemstates = [] json_obj = self.client.fetch_json( '/cards/' + self.id + '/checklists', http_method='POST', post_args={'name': title}, ) cl = Checklist(self.client, [], json_obj, trello_card=self.id) for i, name in enumerate(items): try: checked = itemstates[i] except IndexError: checked = False cl.add_checklist_item(name, checked) self.fetch() return cl
def fetch_checklists(self): checklists = [] json_obj = self.client.fetch_json('/cards/' + self.id + '/checklists', ) # Thanks https://github.com/HuffAndPuff for noticing checklist were not sorted json_obj = sorted(json_obj, key=lambda checklist: checklist['pos']) for cl in json_obj: checklists.append( Checklist(self.client, self.checked, cl, trello_card=self.id)) return checklists
def get_checklists(self, cards='all'): """Get checklists :rtype: list of Checklist """ checklists = [] json_obj = self.client.fetch_json( '/boards/' + self.id + '/checklists', query_params={'cards': cards}) json_obj = sorted(json_obj, key=lambda checklist: checklist['pos']) for cl in json_obj: checklists.append(Checklist(self.client, cl.get('checkItemStates',[]), cl, trello_card=cl.get('idCard'))) return checklists
def fetch_checklists(self): if not hasattr(self, "checked") or self.checked is None: self.fetch(eager=False) checklists = [] json_obj = self.client.fetch_json('/cards/' + self.id + '/checklists', ) # Thanks https://github.com/HuffAndPuff for noticing checklist # were not sorted json_obj = sorted(json_obj, key=lambda checklist: checklist['pos']) for cl in json_obj: checklists.append( Checklist(self.client, self.checked, cl, trello_card=self.id)) return checklists