Skip to content

Commit

Permalink
Added the Label class and fixed the labels property to cards
Browse files Browse the repository at this point in the history
  • Loading branch information
larssorenson committed May 3, 2015
1 parent 4e29cd2 commit 8f10e13
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions trello/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,20 @@ def date_last_activity(self):
def description(self, value):
self.desc = value

@property
def idLabels(self):
return self.label_ids

@idLabels.setter
def idLabels(self, values):
self.label_ids = values

@property
def list_labels(self):
if self.labels:
return self.labels
return None

@property
def comments(self):
"""
Expand Down Expand Up @@ -660,6 +674,8 @@ def from_json(cls, trello_list, json_obj):
card.closed = json_obj['closed']
card.url = json_obj['url']
card.member_ids = json_obj['idMembers']
card.idLabels = json_obj['idLabels']
card.labels = json_obj['labels']
return card

def __repr__(self):
Expand All @@ -682,6 +698,7 @@ def fetch(self, eager=True):
self.idShort = json_obj['idShort']
self.idList = json_obj['idList']
self.idBoard = json_obj['idBoard']
self.idLabels = json_obj['idLabels']
self.labels = json_obj['labels']
self.badges = json_obj['badges']
# For consistency, due date is in YYYY-MM-DD format
Expand Down Expand Up @@ -901,6 +918,26 @@ def _post_remote_data(self, attribute, files=None, **kwargs):
files=files,
post_args=kwargs )

class Label(object):
"""
Class representing a Trello Label.
"""
def __init__(self, client, label_id, name, color=""):
self.client = client
self.id = label_id
self.name = name
self.color = color

def __repr__(self):
return '<Label %s>' % self.name

def fetch(self):
"""Fetch all attributes for this label"""
json_obj = self.client.fetch_json(
'/labels/' + self.id)
self.name = json_obj['name'].encode('utf-8')
self.color = json_obj['color']
return self

class Member(object):
"""
Expand Down

0 comments on commit 8f10e13

Please sign in to comment.