Skip to content

Commit

Permalink
Add basic support for custom fields
Browse files Browse the repository at this point in the history
Custom fields (text, number, date, list, checkbox) may be read and set
for each card.
  • Loading branch information
JuergenBS committed Apr 28, 2018
1 parent 34e4274 commit f6021e7
Show file tree
Hide file tree
Showing 4 changed files with 372 additions and 1 deletion.
13 changes: 13 additions & 0 deletions trello/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from trello.trellolist import List
from trello.label import Label
from trello.checklist import Checklist
from trello.customfield import CustomFieldDefinition
from dateutil import parser as dateparser


Expand Down Expand Up @@ -38,6 +39,7 @@ def __init__(self, client=None, board_id=None, organization=None, name=''):
self.id = board_id
self.name = name
self.date_last_activity = self.get_last_activity()
self.customFieldDefinitions = None

@classmethod
def from_json(cls, trello_client=None, organization=None, json_obj=None):
Expand Down Expand Up @@ -75,6 +77,7 @@ def fetch(self):
self.description = json_obj.get('desc', '')
self.closed = json_obj['closed']
self.url = json_obj['url']
self.customFieldDefinitions = None

# Saves a Trello Board
def save(self):
Expand Down Expand Up @@ -168,6 +171,16 @@ def list_lists(self, list_filter='all'):
"""
return self.get_lists(list_filter=list_filter)

def get_custom_field_definitions(self):
"""Get all custom field definitions for this board
:rtype: list of CustomFieldDefinition
"""
if self.customFieldDefinitions is None:
json_obj = self.client.fetch_json('/boards/' + self.id + '/customFields')
self.customFieldDefinitions = CustomFieldDefinition.from_json_list(self, json_obj)
return self.customFieldDefinitions

def get_labels(self, fields='all', limit=50):
"""Get label
Expand Down
5 changes: 4 additions & 1 deletion trello/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from trello.compat import force_str
from trello.label import Label
from trello.organization import Organization
from trello.customfield import CustomField


class Card(TrelloBase):
Expand Down Expand Up @@ -153,6 +154,7 @@ def from_json(cls, parent, json_obj):
card.idBoard = json_obj['idBoard']
card.idList = json_obj['idList']
card.idShort = json_obj['idShort']
card.customFields = CustomField.from_json_list(card, json_obj['customFieldItems'])
card.labels = Label.from_json_list(card.board, json_obj['labels'])
card.dateLastActivity = dateparser.parse(json_obj['dateLastActivity'])
if "attachments" in json_obj:
Expand All @@ -174,7 +176,7 @@ def fetch(self, eager=True):
"""
json_obj = self.client.fetch_json(
'/cards/' + self.id,
query_params={'badges': False})
query_params={'badges': False, 'customFieldItems': 'true'})
self.id = json_obj['id']
self.name = json_obj['name']
self.desc = json_obj.get('desc', '')
Expand All @@ -186,6 +188,7 @@ def fetch(self, eager=True):
self.idList = json_obj['idList']
self.idBoard = json_obj['idBoard']
self.idLabels = json_obj['idLabels']
self.customFields = CustomField.from_json_list(self, json_obj['customFieldItems'])
self.labels = Label.from_json_list(self.board, json_obj['labels'])
self.badges = json_obj['badges']
self.pos = json_obj['pos']
Expand Down
Loading

0 comments on commit f6021e7

Please sign in to comment.