<s> from __future__ import with_statement , print_function , absolute_import <EOL> from dateutil import parser as dateparser <EOL> from trello . checklist import Checklist <EOL> from trello . label import Label <EOL> class Card ( object ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def short_url ( self ) : <EOL> return self . shortUrl <EOL> @ property <EOL> def member_id ( self ) : <EOL> return self . idMembers <EOL> @ property <EOL> def short_id ( self ) : <EOL> return self . idShort <EOL> @ property <EOL> def list_id ( self ) : <EOL> return self . idList <EOL> @ property <EOL> def board_id ( self ) : <EOL> return self . idBoard <EOL> @ property <EOL> def description ( self ) : <EOL> return self . desc <EOL> @ property <EOL> def date_last_activity ( self ) : <EOL> return self . dateLastActivity <EOL> @ description . setter <EOL> def description ( self , value ) : <EOL> self . desc = value <EOL> @ property <EOL> def idLabels ( self ) : <EOL> return self . label_ids <EOL> @ idLabels . setter <EOL> def idLabels ( self , values ) : <EOL> self . label_ids = values <EOL> @ property <EOL> def list_labels ( self ) : <EOL> if self . labels : <EOL> return self . labels <EOL> return None <EOL> @ property <EOL> def comments ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if self . _comments is None : <EOL> self . _comments = self . fetch_comments ( ) <EOL> except AttributeError : <EOL> self . _comments = None <EOL> return self . _comments <EOL> @ property <EOL> def checklists ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if self . _checklists is None : <EOL> self . _checklists = self . fetch_checklists ( ) <EOL> except AttributeError : <EOL> self . _checklists = None <EOL> return self . _checklists <EOL> @ property <EOL> def attachments ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if self . _attachments is None : <EOL> self . _attachments = self . fetch_attachments ( ) <EOL> except AttributeError : <EOL> self . _attachments = None <EOL> return self . _attachments <EOL> def __init__ ( self , parent , card_id , name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( parent , List ) : <EOL> self . trello_list = parent <EOL> self . board = parent . board <EOL> else : <EOL> self . board = parent <EOL> self . client = parent . client <EOL> self . id = card_id <EOL> self . name = name <EOL> @ classmethod <EOL> def from_json ( cls , parent , json_obj ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT:id>' not in json_obj : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> card = cls ( parent , <EOL> json_obj [ '<STR_LIT:id>' ] , <EOL> name = json_obj [ '<STR_LIT:name>' ] . encode ( '<STR_LIT:utf-8>' ) ) <EOL> card . desc = json_obj . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> card . due = json_obj . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> card . closed = json_obj [ '<STR_LIT>' ] <EOL> card . url = json_obj [ '<STR_LIT:url>' ] <EOL> card . member_ids = json_obj [ '<STR_LIT>' ] <EOL> card . idLabels = json_obj [ '<STR_LIT>' ] <EOL> card . idList = json_obj [ '<STR_LIT>' ] <EOL> card . labels = Label . from_json_list ( card . board , json_obj [ '<STR_LIT>' ] ) <EOL> card . dateLastActivity = dateparser . parse ( json_obj [ '<STR_LIT>' ] ) <EOL> return card <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> def fetch ( self , eager = True ) : <EOL> """<STR_LIT>""" <EOL> json_obj = self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id , <EOL> query_params = { '<STR_LIT>' : False } ) <EOL> self . id = json_obj [ '<STR_LIT:id>' ] <EOL> self . name = json_obj [ '<STR_LIT:name>' ] . encode ( '<STR_LIT:utf-8>' ) <EOL> self . desc = json_obj . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . closed = json_obj [ '<STR_LIT>' ] <EOL> self . url = json_obj [ '<STR_LIT:url>' ] <EOL> self . shortUrl = json_obj [ '<STR_LIT>' ] <EOL> self . idMembers = json_obj [ '<STR_LIT>' ] <EOL> self . idShort = json_obj [ '<STR_LIT>' ] <EOL> self . idList = json_obj [ '<STR_LIT>' ] <EOL> self . idBoard = json_obj [ '<STR_LIT>' ] <EOL> self . idLabels = json_obj [ '<STR_LIT>' ] <EOL> self . labels = Label . from_json_list ( self . board , json_obj [ '<STR_LIT>' ] ) <EOL> self . badges = json_obj [ '<STR_LIT>' ] <EOL> self . pos = json_obj [ '<STR_LIT>' ] <EOL> if json_obj . get ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self . due = json_obj . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> else : <EOL> self . due = '<STR_LIT>' <EOL> self . checked = json_obj [ '<STR_LIT>' ] <EOL> self . dateLastActivity = dateparser . parse ( json_obj [ '<STR_LIT>' ] ) <EOL> self . _checklists = self . fetch_checklists ( ) if eager else None <EOL> self . _comments = self . fetch_comments ( ) if eager else None <EOL> self . _attachments = self . fetch_attachments ( ) if eager else None <EOL> def fetch_comments ( self , force = False ) : <EOL> comments = [ ] <EOL> if ( force is True ) or ( self . badges [ '<STR_LIT>' ] > <NUM_LIT:0> ) : <EOL> comments = self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> query_params = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> return sorted ( comments , key = lambda comment : comment [ '<STR_LIT:date>' ] ) <EOL> return comments <EOL> def get_list ( self ) : <EOL> obj = self . client . fetch_json ( '<STR_LIT>' + self . idList ) <EOL> return List . from_json ( board = self , json_obj = obj ) <EOL> def get_comments ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . fetch_comments ( force = True ) <EOL> def fetch_checklists ( self ) : <EOL> checklists = [ ] <EOL> json_obj = self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , ) <EOL> json_obj = sorted ( json_obj , key = lambda checklist : checklist [ '<STR_LIT>' ] ) <EOL> for cl in json_obj : <EOL> checklists . append ( Checklist ( self . client , self . checked , cl , <EOL> trello_card = self . id ) ) <EOL> return checklists <EOL> def fetch_attachments ( self , force = False ) : <EOL> items = [ ] <EOL> if ( force is True ) or ( self . badges [ '<STR_LIT>' ] > <NUM_LIT:0> ) : <EOL> items = self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> query_params = { '<STR_LIT>' : '<STR_LIT:false>' } ) <EOL> return items <EOL> return items <EOL> def get_attachments ( self ) : <EOL> return self . fetch_attachments ( force = True ) <EOL> def fetch_actions ( self , action_filter = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> json_obj = self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> query_params = { '<STR_LIT>' : action_filter } ) <EOL> self . actions = json_obj <EOL> def attriExp ( self , multiple ) : <EOL> """<STR_LIT>""" <EOL> self . fetch_actions ( multiple ) <EOL> return self . actions <EOL> def listCardMove_date ( self ) : <EOL> """<STR_LIT>""" <EOL> self . fetch_actions ( '<STR_LIT>' ) <EOL> res = [ ] <EOL> for idx in self . actions : <EOL> date_str = idx [ '<STR_LIT:date>' ] <EOL> dateDate = dateparser . parse ( date_str ) <EOL> strLst = idx [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> endLst = idx [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] [ '<STR_LIT:name>' ] <EOL> res . append ( [ strLst , endLst , dateDate ] ) <EOL> return res <EOL> @ property <EOL> def latestCardMove_date ( self ) : <EOL> """<STR_LIT>""" <EOL> self . fetch_actions ( '<STR_LIT>' ) <EOL> date_str = self . actions [ <NUM_LIT:0> ] [ '<STR_LIT:date>' ] <EOL> return dateparser . parse ( date_str ) <EOL> @ property <EOL> def create_date ( self ) : <EOL> """<STR_LIT>""" <EOL> self . fetch_actions ( ) <EOL> date_str = self . actions [ <NUM_LIT:0> ] [ '<STR_LIT:date>' ] <EOL> return dateparser . parse ( date_str ) <EOL> @ property <EOL> def due_date ( self ) : <EOL> return dateparser . parse ( self . due ) if self . due else '<STR_LIT>' <EOL> def set_name ( self , new_name ) : <EOL> """<STR_LIT>""" <EOL> self . _set_remote_attribute ( '<STR_LIT:name>' , new_name ) <EOL> self . name = new_name <EOL> def set_description ( self , description ) : <EOL> self . _set_remote_attribute ( '<STR_LIT>' , description ) <EOL> self . desc = description <EOL> def set_due ( self , due ) : <EOL> """<STR_LIT>""" <EOL> datestr = due . strftime ( '<STR_LIT>' ) <EOL> self . _set_remote_attribute ( '<STR_LIT>' , datestr ) <EOL> self . due = datestr <EOL> def set_pos ( self , pos ) : <EOL> """<STR_LIT>""" <EOL> self . _set_remote_attribute ( '<STR_LIT>' , pos ) <EOL> self . pos = pos <EOL> def set_closed ( self , closed ) : <EOL> self . _set_remote_attribute ( '<STR_LIT>' , closed ) <EOL> self . closed = closed <EOL> def delete ( self ) : <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id , <EOL> http_method = '<STR_LIT>' ) <EOL> def assign ( self , member_id ) : <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> http_method = '<STR_LIT:POST>' , <EOL> post_args = { '<STR_LIT:value>' : member_id } ) <EOL> def unassign ( self , member_id ) : <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' + member_id , <EOL> http_method = '<STR_LIT>' ) <EOL> def subscribe ( self ) : <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> http_method = '<STR_LIT>' , <EOL> post_args = { '<STR_LIT:value>' : True } ) <EOL> def comment ( self , comment_text ) : <EOL> """<STR_LIT>""" <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> http_method = '<STR_LIT:POST>' , <EOL> post_args = { '<STR_LIT:text>' : comment_text } ) <EOL> def add_label ( self , label ) : <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> http_method = '<STR_LIT:POST>' , <EOL> post_args = { '<STR_LIT:value>' : label . id } ) <EOL> def remove_label ( self , label ) : <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' + label . id , <EOL> http_method = '<STR_LIT>' ) <EOL> def attach ( self , name = None , mimeType = None , file = None , url = None ) : <EOL> """<STR_LIT>""" <EOL> if ( file and url ) or ( not file and not url ) : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> kwargs = { } <EOL> if file : <EOL> kwargs [ '<STR_LIT>' ] = dict ( file = ( name , file , mimeType ) ) <EOL> else : <EOL> kwargs [ '<STR_LIT:name>' ] = name <EOL> kwargs [ '<STR_LIT>' ] = mimeType <EOL> kwargs [ '<STR_LIT:url>' ] = url <EOL> self . _post_remote_data ( <EOL> '<STR_LIT>' , ** kwargs <EOL> ) <EOL> def change_list ( self , list_id ) : <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> http_method = '<STR_LIT>' , <EOL> post_args = { '<STR_LIT:value>' : list_id } ) <EOL> def change_board ( self , board_id , list_id = None ) : <EOL> args = { '<STR_LIT:value>' : board_id } <EOL> if list_id is not None : <EOL> args [ '<STR_LIT>' ] = list_id <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> http_method = '<STR_LIT>' , <EOL> post_args = args ) <EOL> def add_checklist ( self , title , items , itemstates = None ) : <EOL> """<STR_LIT>""" <EOL> if itemstates is None : <EOL> itemstates = [ ] <EOL> json_obj = self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT>' , <EOL> http_method = '<STR_LIT:POST>' , <EOL> post_args = { '<STR_LIT:name>' : title } , ) <EOL> cl = Checklist ( self . client , [ ] , json_obj , trello_card = self . id ) <EOL> for i , name in enumerate ( items ) : <EOL> try : <EOL> checked = itemstates [ i ] <EOL> except IndexError : <EOL> checked = False <EOL> cl . add_checklist_item ( name , checked ) <EOL> self . fetch ( ) <EOL> return cl <EOL> def _set_remote_attribute ( self , attribute , value ) : <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT:/>' + attribute , <EOL> http_method = '<STR_LIT>' , <EOL> post_args = { '<STR_LIT:value>' : value } , ) <EOL> def _post_remote_data ( self , attribute , files = None , ** kwargs ) : <EOL> self . client . fetch_json ( <EOL> '<STR_LIT>' + self . id + '<STR_LIT:/>' + attribute , <EOL> http_method = '<STR_LIT:POST>' , <EOL> files = files , <EOL> post_args = kwargs ) <EOL> from trello . trellolist import List </s>
