Skip to content

Commit

Permalink
Merge pull request #193 from sgaynetdinov/master
Browse files Browse the repository at this point in the history
close #187
  • Loading branch information
sarumont committed Apr 20, 2017
2 parents 9c939d4 + 736eecc commit 4aa095e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
43 changes: 35 additions & 8 deletions trello/card.py
@@ -1,21 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement, print_function, absolute_import

import datetime

import pytz
from dateutil import parser as dateparser

from trello.attachments import Attachments
from trello.organization import Organization
from trello.compat import force_str
from trello.checklist import Checklist
from trello.compat import force_str
from trello.label import Label

import datetime
import pytz
from trello.organization import Organization


class Card(object):
"""
Class representing a Trello card. Card attributes are stored on
the object
https://developers.trello.com/advanced-reference/card
"""

@property
Expand Down Expand Up @@ -144,6 +147,7 @@ def from_json(cls, parent, json_obj):
name=json_obj['name'])
card.desc = json_obj.get('desc', '')
card.due = json_obj.get('due', '')
card.is_due_complete = json_obj['dueComplete']
card.closed = json_obj['closed']
card.url = json_obj['url']
card.pos = json_obj['pos']
Expand Down Expand Up @@ -461,9 +465,6 @@ def created_date(self):
self.creation_date = localtz.localize(datetime.datetime.fromtimestamp(int(self.id[0: 8], 16)))
return self.creation_date

# backwards compatibility alias; TODO: deprecation message
create_date = created_date

@property
def card_created_date(self):
"""Will return the creation date of the card.
Expand Down Expand Up @@ -507,6 +508,21 @@ def set_due(self, due):
self._set_remote_attribute('due', datestr)
self.due = datestr

def set_due_complete(self):
"""Set due complete
:return: None
"""
self._set_due_complete(True)

def remove_due_complete(self):
"""Remove due complete
:return: None
"""
self._set_due_complete(False)


def remove_due(self):
"""
Remove the due datetime of this card.
Expand Down Expand Up @@ -667,6 +683,17 @@ def add_checklist(self, title, items, itemstates=None):
self.fetch()
return cl

def _set_due_complete(self, is_complete):
"""Set due is complete or not complete
https://developers.trello.com/advanced-reference/card#put-1-cards-card-id-or-shortlink-dueComplete
:param is_complete: boolean
:return: None
"""
self.client.fetch_json('/cards/' + self.id + '/dueComplete',
http_method='PUT',
post_args={'value': is_complete})

def _set_remote_attribute(self, attribute, value):
self.client.fetch_json(
'/cards/' + self.id + '/' + attribute,
Expand Down
9 changes: 9 additions & 0 deletions trello/label.py
Expand Up @@ -40,3 +40,12 @@ def fetch(self):
self.name = json_obj['name']
self.color = json_obj['color']
return self

def __hash__(self):
class_name = type(self).__name__
return hash(class_name) ^ hash(self.id)

def __eq__(self, other):
if isinstance(other, type(self)):
return hash(self) == hash(other)
raise NotImplementedError

0 comments on commit 4aa095e

Please sign in to comment.