
    3fiw                         d Z ddlZddlZddlmZ ddlmZ ddl	m
Z
mZ  ej                  e      ZdZdZd	Zd
ZdZdZdZdZdZdZdZ G d de
      Z G d de
      Z G d de
      Z G d de
      Zy)z:Methods for accessing MS Tasks/Todos via the MS Graph api.    N)BeautifulSoup)parse   )ApiComponent
TrackerSetchecklistitemchecklistitemsfolderget_checklistget_checklists
get_folderget_task	get_tasksroot_folderstasktask_folderc                        e Zd ZdZedediZddd fd
Zd Zd Z	d	 Z
dd
Zed        Zed        Zed        Zed        Zd Zd Zd Zd Z xZS )ChecklistItemz&A Microsoft To-Do task CheckList Item.z;/todo/lists/{folder_id}/tasks/{task_id}/checklistItems/{id}z6/todo/lists/{folder_id}/tasks/{task_id}/checklistItemsNparentconc                   |r|rt        d      |r|j                  n|| _        |j                  | j                  i       }|j	                  dd      xs |rt        |dd      nd}t        	|   |r|j                  n|j                  d      |       |j	                  dd      xs |rt        |dd      nd}| j                  }t        |      | _        |j                  | _        |j                  d      xs |j                  | _        |j                  | j                  i       }|j                   |d      d      | _        |j                   |d	      |j                  d
d            | _        |j                   |d      i       }| j!                  |      | _        |j                   |d      i       }| j!                  |      | _        |j                   |d      d      | _        y)a  Representation of a Microsoft To-Do task CheckList Item.

        :param parent: parent object
        :type parent: Task
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        :param str task_id: id of the task to add this item in
         (kwargs)
        :param str displayName: display name of the item (kwargs)
        *Need a parent or a connection but not bothmain_resourceNprotocolr   r   casingtask_ididdisplayNamedisplaynamecheckedDateTimecreatedDateTime	isCheckedF)
ValueErrorr   get_cloud_data_keypopgetattrsuper__init__r   _ccr   _track_changes	folder_idr   item_id_ChecklistItem__displayname_parse_date_time_time_zone_ChecklistItem__checked_ChecklistItem__created_ChecklistItem__is_checked)
selfr   r   kwargs
cloud_datar   ccchecked_objcreated_obj	__class__s
            H/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/O365/tasks.pyr,   zChecklistItem.__init__#   s    cIJJ!'6::SZZ 4 4b9
 

?D9 
6<GFOT2$ 	 	(.V__FJJz4J' 	 	
 

?D9 
6<GFOT2$ 	 XX(3))zz),>ZZ 4 4b9
 "~~bh5'^^}vzz->
 !nnR(9%:B?88E nnR(9%:B?88E&NN2k?EB    c                 "    | j                         S )zCRepresentation of the Checklist Item via the Graph api as a string.__repr__r6   s    r=   __str__zChecklistItem.__str__]       }}r>   c                     | j                   rdnd}| j                  r:d| j                  j                          d| j                  j                          d}nd}d| d| j                   d| S )	z7Representation of the Checklist Item via the Graph api.xoz
(checked:  at )  zChecklist Item: ( )r5   r3   datetimer1   )r6   markerchecked_strs      r=   rA   zChecklistItem.__repr__a   sr    ))s>>T^^002348K8K8M7NbQ  K"6("T-?-?,@+OOr>   c                 4    | j                   |j                   k(  S zComparison of tasks.)r0   r6   others     r=   __eq__zChecklistItem.__eq__m       ||u}},,r>   c                     | j                   } |d      | j                   |d      | j                  i}|r&t        |j	                               D ]
  }||vs||=  |S )Return a dict to communicate with the server.

        :param restrict_keys: a set of keys to restrict the returned data to
        :rtype: dict
        r!   r%   )r-   r1   r5   listkeysr6   restrict_keysr9   datakeys        r=   to_api_datazChecklistItem.to_api_dataq   sj     XX }t11{OT..

 DIIK( "m+S	" r>   c                     | j                   S )z=Return Display Name of the task.

        :type: str
        )r1   rB   s    r=   r"   zChecklistItem.displayname   s     !!!r>   c                     | j                   S zBReturn Created time of the task.

        :type: datetime
        )r4   rB   s    r=   createdzChecklistItem.created        ~~r>   c                     | j                   S )zBReturn Checked time of the task.

        :type: datetime
        )r3   rB   s    r=   checkedzChecklistItem.checked   rc   r>   c                     | j                   S )z2Is the item checked.

        :type: bool
        )r5   rB   s    r=   
is_checkedzChecklistItem.is_checked   s        r>   c                 f    d| _         | j                  j                  | j                  d             y)z#Mark the checklist item as checked.Tr%   Nr5   r.   addr-   rB   s    r=   mark_checkedzChecklistItem.mark_checked   s'      56r>   c                 f    d| _         | j                  j                  | j                  d             y)z%Mark the checklist item as unchecked.Fr%   Nri   rB   s    r=   mark_uncheckedzChecklistItem.mark_unchecked   s'    ! 56r>   c                 8   | j                   t        d      | j                  | j                  j	                  t
              j                  | j                  | j                  | j                               }| j                  j                  |      }t        |      S )zaDelete a stored checklist item.

        :return: Success / Failure
        :rtype: bool
        z.Attempting to delete an unsaved checklist itemr/   r   r    )r0   RuntimeError	build_url
_endpointsr'   CONST_CHECKLIST_ITEMformatr/   r   r   deleteboolr6   urlresponses      r=   ru   zChecklistItem.delete   s|     <<OPPnnOO 45<<..$,,4<< = 
 88??3'H~r>   c                    | j                   r| j                  sy| j                  | j                  j	                  t
              j                  | j                  | j                  | j                               }| j                  j                  }| j                  | j                        }ny| j                  | j                  j	                  t              j                  | j                  | j                              }| j                  j                  }| j                         } |||      }|sy| j                  j                          |j                         }| j                   s5|j	                  | j!                  d      d      | _         |j	                  | j!                  d	      d      | _        |j	                  | j!                  d
      d      | _        |j	                  | j!                  d      d      | _        | j"                  r8t)        | j"                        j+                  | j,                  j.                        nd| _        | j$                  r>t)        | j$                        j+                  | j,                  j.                        | _        yd| _        y|j	                  | j!                  d
      d      | _        | j$                  r8t)        | j$                        j+                  | j,                  j.                        nd| _        y)zCreate a new checklist item or update an existing one.

        Does update by checking what values have changed and update them on the server
        :return: Success / Failure
        :rtype: bool
        Tro   r[   )r/   r   r\   Fr    Nr$   r#   r%   )r0   r.   rq   rr   r'   rs   rt   r/   r   r   patchr^   
CONST_TASKpostclearjsonr-   r4   r3   r5   r   
astimezoner   timezone)r6   rx   methodr\   ry   items         r=   savezChecklistItem.save   s\    <<&&..##$89@@"nndllt|| A C
 XX^^F##$2E2E#FD ..##J/66"nndll 7 C XX]]F##%D#D)!!#}}||88DHHTND9DL!XXdhh/@&A4HDN!XXdhh/@&A4HDN $+)> FD >> dnn%001G1GH N >> dnn%001G1GH N   N  "XXdhh/@&A4HDN >> dnn%001G1GH N r>   N)__name__
__module____qualname____doc__rs   r~   rr   r,   rC   rA   rT   r^   propertyr"   rb   re   rg   rk   rm   ru   r   __classcell__r<   s   @r=   r   r      s    0 	[LJ
 "&4 8Ct
P-& " "     ! !7
7
&>r>   r   c                       e Zd ZdZedededediZe	Z
ddd fd
Zd	 Zd
 Zd Zd(dZed        Zed        Zed        Zej(                  d        Zed        Zed        Zed        Zej(                  d        Zed        Zej(                  d        Zed        Zej(                  d        Zed        Zed        Zed        Zej(                  d        Zed        Zed        Zd Zd  Z d! Z!d" Z"d# Z#d$ Z$d)d%Z%d& Z&d(d'Z' xZ(S )*TaskzA Microsoft To-Do task.z7/todo/lists/{folder_id}/tasks/{id}/checklistItems/{ide}z1/todo/lists/{folder_id}/tasks/{id}/checklistItemsz"/todo/lists/{folder_id}/tasks/{id}z/todo/lists/{folder_id}/tasksNr   c                    |r|rt        d      |r|j                  n| _        |j                   j                  i       }|j	                  dd      xs |rt        |dd      nd}t           |r|j                  n|j                  d      |        j                  }t        |       _        |j                  d      xs |j                   _        |j                   j                  i       }|j                   |d      d       _        |j                   |d	      |j                  d
d      xs d       _        |j                   |d      i       }|j                   |d      d       _        |j                   |d      d       _        |j                   |d      d       _        |j                   |d      d       _        |j                   |d      d       _         j&                  dk(   _        |j                   |d      d       _         j                  j,                  } j"                  r$t/         j"                        j1                  |      nd _         j$                  r$t/         j$                        j1                  |      nd _        |j                   |d      i       }	 j3                  |	       _        |j                   |d      i       }
 j3                  |
       _        |j                   |d      d       _        |j                   |d      i       } j3                  |       _         fd|j                   |d      g       D         _        y)a	  Representation of a Microsoft To-Do task.

        :param parent: parent object
        :type parent: Folder
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        :param str folder_id: id of the calender to add this task in
         (kwargs)
        :param str subject: subject of the task (kwargs)
        r   r   Nr   r   r   r/   r    titlesubjectrJ   bodycontentcontentTypehtmlr$   lastModifiedDateTimestatus	completed
importancedueDateTimereminderDateTimeisReminderOnFcompletedDateTimec              3   ^   K   | ]$  } j                   dd ij                  |i & ywr   N checklist_item_constructorr(   .0r   r6   s     r=   	<genexpr>z Task.__init__.<locals>.<genexpr>T  s:      "
 ,D++X4XD<P<PRV;WX"
   *-checklistItems)r&   r   r'   r(   r)   r*   r+   r,   r   r-   r   r.   r/   r   _Task__subject_Task__body	body_type_Task__created_Task__modified_Task__status_Task__is_completed_Task__importancer   r   r   r2   
_Task__due_Task__reminder_Task__is_reminder_on_Task__completed_Task__checklist_items)r6   r   r   r7   r8   r   r9   r   local_tzdue_objreminder_objcompleted_objr<   s   `           r=   r,   zTask.__init__  s    cIJJ!'6::SZZ 4 4b9
 

?D9 
6<GFOT2$ 	 	(.V__FJJz4J' 	 	

 XX(3K0DF4D4DZZ 4 4b9
 "~~bh5#7VZZ	25N5TRTU~~bj"-hhr)}b1}v
 $+<(=tD$..,B)CTJ"r(|T:"mm{:&NN2l+;TB==)):>..E$..!,,X6d 	 <@??E$//"--h7PT 	 ..M!2B744W=
!~~b);&<bA99,G *r./A5 I"r*='>C::=I"
"r*:';R@"
r>   c                 "    | j                         S )z9Representation of the Task via the Graph api as a string.r@   rB   s    r=   rC   zTask.__str__Y  rD   r>   c                 r   | j                   rdnd}| j                  r:d| j                  j                          d| j                  j                          d}nd}| j                  r:d| j                  j                          d| j                  j                          d}nd}d| d| j
                   d	| d	| S )
z-Representation of the Task via the Graph api.rF   rG   z(due: rH   rI   rJ   z(completed: zTask: (rK   )r   r   rL   rM   r   r   )r6   rN   due_str	compl_strs       r=   rA   zTask.__repr__]  s    ++::tzz01djjoo6G5HKGGt//4467tD<L<L<Q<Q<S;TTVW 
 I4>>"2!G9Ai[IIr>   c                 4    | j                   |j                   k(  S rQ   )r   rR   s     r=   rT   zTask.__eq__o  rU   r>   c                    | j                   } |d      | j                   |d      | j                  rdndi}| j                  r0 |d      | j                   |d      | j                  i| |d      <   nd| |d      <   | j
                  r%| j                  | j
                        | |d	      <   nd| |d	      <   | j                  r%| j                  | j                        | |d
      <   nd| |d
      <   | j                  r$| j                  | j                        | |d      <   |r&t        |j                               D ]
  }||vs||=  |S )rW   r   r   r   
notStartedr   r   r   Nr   r   r   )r-   r   r   r   r   r   _build_date_time_time_zoner   r   rX   rY   rZ   s        r=   r^   zTask.to_api_datas  sK    XX wKxL)<)<+,

 ;;=!4>>9t{{ DF
  $DF::&*&E&Edjj&QDM"#&*DM"#??+/+J+J,D&'( ,0D&'(,0,K,K  -D'() DIIK( "m+S	" r>   c                     | j                   S ra   )r   rB   s    r=   rb   zTask.created  rc   r>   c                     | j                   S )zHReturn Last modified time of the task.

        :type: datetime
        )r   rB   s    r=   modifiedzTask.modified  s     r>   c                     | j                   S )zvReturn Body of the task.

        :getter: Get body text
        :setter: Set body of task
        :type: str
        )r   rB   s    r=   r   z	Task.body  s     {{r>   c                 f    || _         | j                  j                  | j                  d             y )Nr   )r   r.   rj   r-   r6   values     r=   r   z	Task.body  s&     01r>   c                     | j                   S )znReturn Task importance.

        :getter: Get importance level (Low, Normal, High)
        :type: str
        )r   rB   s    r=   r   zTask.importance  s        r>   c                 X    | j                   j                         dj                         k(  S )zqIs the task starred (high importance).

        :getter: Check if importance is high
        :type: bool
        high)r   casefoldrB   s    r=   
is_starredzTask.is_starred  s%       ))+v/@@@r>   c                     | j                   S )zsSubject of the task.

        :getter: Get subject
        :setter: Set subject of task
        :type: str
        )r   rB   s    r=   r   zTask.subject  s     ~~r>   c                 f    || _         | j                  j                  | j                  d             y )Nr   )r   r.   rj   r-   r   s     r=   r   zTask.subject  s&     12r>   c                     | j                   S )zwDue Time of task.

        :getter: Get the due time
        :setter: Set the due time
        :type: datetime
        )r   rB   s    r=   duezTask.due  s     zzr>   c                 H   |rt        |t        j                        st        d      t        |t        j                        s5t        j                  |j
                  |j                  |j                        }|j                  '|j                  | j                  j                        }nH|j                  | j                  j                  k7  r%|j                  | j                  j                        }|| _        | j                  j                  | j!                  d             y )Nz%'due' must be a valid datetime objecttzinfor   )
isinstancedtrL   r&   datetimeyearmonthdayr   replacer   r   r   r   r.   rj   r-   r   s     r=   r   zTask.due  s    eRWW- !HIIeR[[1EJJUYYG||#T]]-C-CD!7!77(()?)?@
 78r>   c                     | j                   S )zReminder Time of task.

        :getter: Get the reminder time
        :setter: Set the reminder time
        :type: datetime
        )r   rB   s    r=   reminderzTask.reminder  s     r>   c                 H   |rt        |t        j                        st        d      t        |t        j                        s5t        j                  |j
                  |j                  |j                        }|j                  '|j                  | j                  j                        }nH|j                  | j                  j                  k7  r%|j                  | j                  j                        }|| _        | j                  j                  | j!                  d             y )Nz*'reminder' must be a valid datetime objectr   r   )r   r   rL   r&   r   r   r   r   r   r   r   r   r   r   r.   rj   r-   r   s     r=   r   zTask.reminder  s    eRWW- !MNNeR[[1EJJUYYG||#T]]-C-CD!7!77(()?)?@); <=r>   c                     | j                   S )z`Return isReminderOn of the task.

        :getter: Get isReminderOn
        :type: bool
        )r   rB   s    r=   is_reminder_onzTask.is_reminder_on  s     $$$r>   c                     | j                   S )zGStatus of task

        :getter: Get status
        :type: str
        )r   rB   s    r=   r   zTask.status  s     }}r>   c                     | j                   S )zCompleted Time of task.

        :getter: Get the completed time
        :setter: Set the completed time
        :type: datetime
        )r   rB   s    r=   r   zTask.completed%  s     r>   c                    || j                          nt        |t        j                        st	        d      t        |t        j
                        s5t        j
                  |j                  |j                  |j                        }|j                  '|j                  | j                  j                        }nH|j                  | j                  j                  k7  r%|j                  | j                  j                        }| j                          || _        | j                   j#                  | j%                  d             y )Nz+'completed' must be a valid datetime objectr   r   )mark_uncompletedr   r   rL   r&   r   r   r   r   r   r   r   r   r   mark_completedr   r.   rj   r-   r   s     r=   r   zTask.completed/  s    =!!#eRWW- !NOOeR[[1EJJUYYG||#T]]-C-CD!7!77(()?)?@! )< =>r>   c                     | j                   S )zIs task completed or not.

        :getter: Is completed
        :setter: Set the task to completed
        :type: bool
        )r   rB   s    r=   is_completedzTask.is_completedC  s     """r>   c                     | j                   S )znChecklist items for the task.

        :getter: Get checklistItems
        :type: list[ChecklistItem]
        )r   rB   s    r=   checklist_itemszTask.checklist_itemsM  s     %%%r>   c                 f    d| _         | j                  j                  | j                  d             y)zMark the task as completed.Tr   Nr   r.   rj   r-   rB   s    r=   r   zTask.mark_completedV  s'    " 23r>   c                 f    d| _         | j                  j                  | j                  d             y)zMark the task as uncompleted.Fr   Nr   rB   s    r=   r   zTask.mark_uncompleted[  s'    # 23r>   c                 "   | j                   t        d      | j                  | j                  j	                  t
              j                  | j                  | j                               }| j                  j                  |      }t        |      S )zWDelete a stored task.

        :return: Success / Failure
        :rtype: bool
        z$Attempting to delete an unsaved taskr/   r    )r   rp   rq   rr   r'   r~   rt   r/   r   ru   rv   rw   s      r=   ru   zTask.delete`  su     <<EFFnnOO
+22..T\\ 3 
 88??3'H~r>   c                    | j                   r| j                  sy| j                  | j                  j	                  t
              j                  | j                  | j                               }| j                  j                  }| j                  | j                        }nn| j                  | j                  j	                  t              j                  | j                              }| j                  j                  }| j                         } |||      }|sy| j                  j                          | j                   sh|j                         }|j	                  | j                  d      d      | _         |j	                  | j                  d	      d      | _        |j	                  | j                  d
      d      | _        |j	                  | j                  d      d      | _        | j                   r8t'        | j                         j)                  | j*                  j,                        nd| _        | j"                  r8t'        | j"                        j)                  | j*                  j,                        nd| _        |j	                  | j                  d      d      dk(  | _        yt0        j2                  j5                         j7                  | j*                  j,                        | _        y)zCreate a new task or update an existing one.

        Does update by checking what values have changed and update them on the server
        :return: Success / Failure
        :rtype: bool
        Tr   r{   r/   r|   Fr    Nr$   r   r   r   r   )r   r.   rq   rr   r'   r~   rt   r/   r   r}   r^   CONST_TASK_FOLDERr   r   r   r-   r   r   r   r   r   r   r   r   r   r   nowr   )r6   rx   r   r\   ry   r   s         r=   r   z	Task.saves  s5    <<&&..##J/66"nn 7 C
 XX^^F##$2E2E#FD ..##$56===WC XX]]F##%D#D)!!#||==?D88DHHTND9DL!XXdhh/@&A4HDN"hhtxx0F'GNDO#xx(=tDD >> dnn%001G1GH N ?? doo&11$--2H2HI O
 #'((488H+=t"D"SD  !kkoo/77t}}?U?U7VDOr>   c                     | j                   dk7  r| j                  S 	 t        | j                  d      }|j                  j                  S # t        $ r | j                  cY S w xY w)zqParse the body html and returns the body text using bs4.

        :return: body text
        :rtype: str
        r   html.parser)r   r   bstextrp   )r6   soups     r=   get_body_textzTask.get_body_text  sZ     >>V#99	"dii/D 99>>!  	99	s   A	 	A! A!c                 P    | j                   dk(  rt        | j                  d      S dS )znReturn the beautifulsoup4 of the html body.

        :return: Html body
        :rtype: BeautifulSoup
        r   r   N)r   r   r   rB   s    r=   get_body_soupzTask.get_body_soup  s%     04~~/Gr$))]+QTQr>   c                      j                   j                  j                  t              j	                   j
                   j                              }i }|r||d<   |r||d<   |r)t        |t              r||d<   n||j                         z  } j                  j                  ||      }|st        d      S |j                         } fd|j                  dg       D        S )	a  Return list of checklist items of a specified task.

        :param query: the query string or object to query items
        :param batch: the batch on to retrieve items.
        :param order_by: the order clause to apply to returned items.

        :rtype: checklistItems
        r   $top$orderby$filterparamsr   c              3   ^   K   | ]$  } j                   dd ij                  |i & ywr   r   r   s     r=   r   z+Task.get_checklist_items.<locals>.<genexpr>  s:      
 ,D++X4XD<P<PRV;WX
r   r   )rq   rr   r'   CONST_GET_CHECKLISTSrt   r/   r   r   str	as_paramsr   iterr   r6   querybatchorder_byrx   r  ry   r\   s   `       r=   get_checklist_itemszTask.get_checklist_items  s     nnOO 45<<..T\\ = 
 "F6N!)F:%%$)y!%//++88<<F<38O}}
"-
 	
r>   c                    |yt        |t              rY| j                  | j                  j	                  t
              j                  | j                  | j                  |            }d}d}nl| j                  | j                  j	                  t              j                  | j                  | j                              }ddi}||j                         z  }d}| j                  j	                  ||      }|sy|r|j                         }n)|j                         j	                  d	g       }|r|d
   }ny | j                  dd| i| j                  |iS )zReturn a Checklist Item instance by it's id.

        :param param: an item_id or a Query instance
        :return: Checklist Item for the specified info
        :rtype: ChecklistItem
        N)r/   r    ideTr   r   r   Fr   r   r   r   r   )r   r  rq   rr   r'   CONST_GET_CHECKLISTrt   r/   r   r  r  r   r   r   r(   )r6   paramrx   r  by_idry   r   s          r=   get_checklist_itemzTask.get_checklist_item  sD    =eS!..##$78??"nn5 @ C
 FE..##$89@@"nn A C
 a[Feoo''FE88<<F<3==?D==?&&w3DAw.t.. 

 00$7
 	
r>   c                 >    | j                  | || j                        S )z0Create a checklist item within a specified task.)r   r"   r   )r   r   )r6   r"   s     r=   new_checklist_itemzTask.new_checklist_item  s%    ..[$,, / 
 	
r>   r   NNN))r   r   r   r   r  r  r~   r   rr   r   r   r,   rC   rA   rT   r^   r   rb   r   r   setterr   r   r   r   r   r   r   r   r   r   r   r   ru   r   r   r   r  r  r  r   r   s   @r=   r   r     s   ! 	VQ8:	J "/!%4 J
XJ$-*X       
[[2 2 ! ! A A   ^^3 3   	ZZ9 9   __> > % %       ? ?& # # & &4
4
&9v" R'
R*
X
r>   r   c                   r     e Zd ZdZededediZeZ	ddd fd
Z
d Zd	 Zd
 Zd Zd ZddZddZd Z xZS )FolderzA Microsoft To-Do folder./todo/lists/{id}z/todo/lists/{id}/tasksz/todo/lists/{id}/tasks/{ide}Nr   c                *   |r|rt        d      |r|j                  n|| _        |j                  dd      xs |rt        |dd      nd}t        |   |r|j                  n|j                  d      |       |j                  | j                  i       }|j                  | j                  d      d      | _
        |j                  | j                  d      d      | _        d	| _        |j                  | j                  d
      d      dk(  rd| _        yy)ay  Representation of a Microsoft To-Do Folder.

        :param parent: parent object
        :type parent: ToDo
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        r   r   Nr   r   r!   rJ   r    FwellknownListNamedefaultListT)r&   r   r)   r*   r+   r,   r   r'   r(   r-   namer/   
is_default)r6   r   r   r7   r   r8   r<   s         r=   r,   zFolder.__init__,  s     cIJJ!'6::S 

?D9 
6<GFOT2$ 	 	(.V__FJJz4J' 	 	

 ZZ 4 4b9
 NN488M#:B?	#=>>$((#67<M"DO Nr>   c                 "    | j                         S )z;Representation of the Folder via the Graph api as a string.r@   rB   s    r=   rC   zFolder.__str__P  rD   r>   c                 D    | j                   rdnd}d| j                   | S )z/Representation of the folder via the Graph api.z
 (default)rJ   zFolder: )r  r  )r6   suffixs     r=   rA   zFolder.__repr__T  s$    !%b$))VH--r>   c                 4    | j                   |j                   k(  S )zComparison of folders.r   rR   s     r=   rT   zFolder.__eq__Y  s    ~~00r>   c                 6   | j                   sy| j                  | j                  j                  t              j                  | j                               }| j                  d      | j                  i}| j                  j                  ||      }t        |      S )zoUpdate this folder. Only name can be changed.

        :return: Success / Failure
        :rtype: bool
        Fr    r!   r|   )r/   rq   rr   r'   CONST_FOLDERrt   r-   r  r   r}   rv   )r6   rx   r\   ry   s       r=   updatezFolder.update]  s}     ~~nnOO-444G

 HH]#TYY
 88>>#D>1H~r>   c                     | j                   sy| j                  | j                  j                  t              j                  | j                               }| j                  j                  |      }|syd| _         y)zUDelete this folder.

        :return: Success / Failure
        :rtype: bool
        Fr#  NT)r/   rq   rr   r'   r$  rt   r   ru   rw   s      r=   ru   zFolder.deleter  sd     ~~nnOO-444G
 88??3'r>   c                      j                   j                  j                  t              j	                   j
                              }i }|r||d<   |r||d<   |r)t        |t              r||d<   n||j                         z  } j                  j                  ||      }|st        d      S |j                         } fd|j                  dg       D        S )	a  Return list of tasks of a specified folder.

        :param query: the query string or object to query tasks
        :param batch: the batch on to retrieve tasks.
        :param order_by: the order clause to apply to returned tasks.

        :rtype: tasks
        r#  r   r   r   r   r   c              3   ^   K   | ]$  } j                   dd ij                  |i & ywr   )task_constructorr(   )r   r   r6   s     r=   r   z#Folder.get_tasks.<locals>.<genexpr>  s9      
 "D!!NN$2F2F1MN
r   r   )rq   rr   r'   CONST_GET_TASKSrt   r/   r   r  r  r   r  r   r  s   `       r=   r   zFolder.get_tasks  s     nnOO0774>>7J

 "F6N!)F:%%$)y!%//++88<<F<38O}}
"-
 	
r>   c                 >    | j                  | || j                        S )z(Create a task within a specified folder.)r   r   r/   )r)  r/   )r6   r   s     r=   new_taskzFolder.new_task  s%    $$DNN % 
 	
r>   c                 ~   |yt        |t              rN| j                  | j                  j	                  t
              j                  | j                  |            }d}d}na| j                  | j                  j	                  t              j                  | j                              }ddi}||j                         z  }d}| j                  j	                  ||      }|sy|r|j                         }n)|j                         j	                  d	g       }|r|d
   }ny | j                  dd| i| j                  |iS )zReturn a Task instance by it's id.

        :param param: an task_id or a Query instance
        :return: task for the specified info
        :rtype: Task
        N)r    r  Tr#  r   r   Fr   r   r   r   r   )r   r  rq   rr   r'   CONST_GET_TASKrt   r/   r*  r  r   r   r)  r(   )r6   r  rx   r  r  ry   r   s          r=   r   zFolder.get_task  s!    =eS!..##N3::dnnRW:XC FE..##O4;;t~~;NC a[Feoo''FE88<<F<3==?D==?&&w3DAw$t$$QDQT5I5I44PQQr>   r  r   )r   r   r   r   r$  r*  r.  rr   r   r)  r,   rC   rA   rT   r%  ru   r   r,  r   r   r   s   @r=   r  r  "  s^    # 	(16J
 !%4 "#H.
1**%
N
$Rr>   r  c                   v     e Zd ZdZedediZeZe	Z
ddd fd
Zd Zd Zdd	Zd
 ZddZd ZddZddZ xZS )ToDozA Microsoft To-Do class for MS Graph API.

    In order to use the API following permissions are required.
    Delegated (work or school account) - Tasks.Read, Tasks.ReadWrite
    z/todo/listsr  Nr   c                    |r|rt        d      |r|j                  n|| _        |j                  dd      xs |rt        |dd      nd}t        |   |r|j                  n|j                  d      |       y)al  Initialise the ToDo object.

        :param parent: parent object
        :type parent: Account
        :param Connection con: connection to use if no parent specified
        :param Protocol protocol: protocol to use if no parent specified
         (kwargs)
        :param str main_resource: use this resource instead of parent resource
         (kwargs)
        r   r   Nr   r   )r&   r   r)   r*   r+   r,   r   r'   )r6   r   r   r7   r   r<   s        r=   r,   zToDo.__init__  sz     cIJJ!'6::S 

?D9 
6<GFOT2$ 	 	(.V__FJJz4J' 	 	
r>   c                 "    | j                         S )z9Representation of the ToDo via the Graph api as a string.r@   rB   s    r=   rC   zToDo.__str__  rD   r>   c                      y)z0Representation of the ToDo via the Graph api as.zMicrosoft To-Dor   rB   s    r=   rA   zToDo.__repr__  s     r>   c           	         | j                  | j                  j                  t                    }i }|r||d<   |r)t	        |t
              r||d<   n||j                         z  }| j                  j                  ||xs d      }|sg S |j                         }|j                  dg       D cg c]"  } | j                  dd| i| j                  |i$ c}S c c}w )a  Return a list of folders.

        To use query an order_by check the OData specification here:
        https://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/
        part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions
        -complete.html
        :param query: the query string or object to list folders
        :param int limit: max no. of folders to get. Over 999 uses batch.
        :rtype: list[Folder]
        r   r   Nr   r   r   r   )rq   rr   r'   CONST_ROOT_FOLDERSr   r  r  r   r   folder_constructorr(   )r6   r  limitrx   r  ry   r\   rF   s           r=   list_folderszToDo.list_folders  s     nnT__001CDE"F6N%%$)y!%//++88<<FNd<;I}} XXgr*
 $D##M4MD4H4H!3LM
 	
 
s   ,'Cc                 &   |sy| j                  | j                  j                  t                    }| j                  j                  || j                  d      |i      }|sy|j                         } | j                  dd| i| j                  |iS )zCreate a new folder.

        :param str folder_name: name of the new folder
        :return: a new folder instance
        :rtype: Folder
        Nr!   r|   r   r   )
rq   rr   r'   r5  r   r   r-   r   r6  r(   )r6   folder_namerx   ry   r\   s        r=   
new_folderzToDo.new_folder-  s     nnT__001CDE88==DHH],C[+Q=R}} 't&&SdSt7K7KT6RSSr>   c                    |r|rt        d      |s|st        d      |r| j                  | j                  j                  t              j                  |            }| j                  j                  |      }|r. | j                  d	d| i| j                  |j                         iS dS | j                  d      j                  |      }| j                  |      }|d   S )
zReturn a folder by it's id or name.

        :param str folder_id: the folder id to be retrieved.
        :param str folder_name: the folder name to be retrieved.
        :return: folder for the given info
        :rtype: Folder
        zProvide only one of the optionszProvide one of the optionsr#  r   Nr!   )r  r   r   )rp   rq   rr   r'   CONST_GET_FOLDERrt   r   r6  r(   r   	new_queryequalsr8  )r6   r/   r:  rx   ry   r  folderss          r=   r   zToDo.get_folderB  s     @AA;<<..##$45<<	<JC xx||C(H  ('' $($8$8(--/#J
  }-44[A##%#0qzr>   c                 R    | j                         }|D ]  }|j                  s|c S  y)zPReturn the default folder for the current user.

        :rtype: Folder
        N)r8  r  )r6   r@  r
   s      r=   get_default_folderzToDo.get_default_folderb  s/    
 ##% 	F  	r>   c                 H    | j                         }|j                  ||      S )aD  Get tasks from the default Folder.

        :param order_by: orders the result set based on this condition
        :param int batch: batch size, retrieves items in
         batches allowing to retrieve more items than the limit.
        :return: list of items in this folder
        :rtype: list[Task] or Pagination
        )r
  r	  )rB  r   )r6   r	  r
  default_folders       r=   r   zToDo.get_tasksl  s(     002'''GGr>   c                 F    | j                         }|j                  |      S )zReturn a new (unsaved) Task object in the default folder.

        :param str subject: subject text for the new task
        :return: new task
        :rtype: Task
        )r   )rB  r,  )r6   r   rD  s      r=   r,  zToDo.new_tasky  s&     002&&w&77r>   )NNr   )r   r   r   r   r5  r=  rr   r  r6  r   r)  r,   rC   rA   r8  r;  r   rB  r   r,  r   r   s   @r=   r0  r0    s`     	M,J
  !%4 
2! 
DT*@H8r>   r0  )r   r   r   loggingbs4r   r   dateutil.parserr   utilsr   r   	getLoggerr   logrs   CONST_CHECKLIST_ITEMSr$  r  r  r=  r.  r*  r5  r~   r   r   r   r  r0  r   r>   r=   <module>rM     s    @   $ ! +g!& ( % '  # 
! dL dN]
< ]
@vR\ vRrf8< f8r>   