def get_tasks_in_tasklist(self, tasklist): """ Return a dictionary of all tasks belonging to the specified tasklist. Dictionary keys will be entity IDs, values will be the corresponding task instances. """ # Execute the list operation and store the resulting str dict, which # contains an array/list of results stored under an "items" key. assert (tasklist is not None and tasklist.entity_id is not None) list_results_str_dict = self.service_proxy.list(tasklist=tasklist.entity_id).execute() tasks = dict() # Check to see if the tasklist has any assigned tasks. if list_results_str_dict.has_key(GoogleKeywords.ITEMS): for task_str_dict in list_results_str_dict.get(GoogleKeywords.ITEMS): # Create a Task to represent the result captured in the str dict. task = Task.from_str_dict(task_str_dict) # Set the tasklist id (this property is maintained locally per # session, not provided by the Google service. task.tasklist_id = tasklist.entity_id # Add the resulting Task to the results list. tasks[task.entity_id] = task return tasks
def add_task(self, task): assert (task is not None and task.tasklist_id is not None) # Create the str dict (JSON formatted data) for the insert request. insert_str_dict = task.to_str_dict() # Store the tasklist ID as it will not be wiped out in the process # of creating a new task from the service results. tasklist_id = task.tasklist_id # Submit/execute the insert request and receive the resulting updated # task properties. if task.parent_id is not None: result_str_dict = self.service_proxy.insert( tasklist=task.tasklist_id, parent=task.parent_id, body=insert_str_dict).execute() else: result_str_dict = self.service_proxy.insert( tasklist=task.tasklist_id, body=insert_str_dict).execute() # Re-populate the task with the updated propety information from # Google. task = Task.from_str_dict(result_str_dict) task.tasklist_id = tasklist_id return task
def get_task(self, tasklist_id, task_id): assert (task_id is not None and tasklist_id is not None) result_str_dict = self.service_proxy.get(tasklist=tasklist_id, task=task_id).execute() task = Task.from_str_dict(result_str_dict) return task
def update_task(self, task): assert (task is not None and task.entity_id is not None and task.tasklist_id is not None) # Create a str dict that holds the task's updated properties. update_str_dict = task.to_str_dict() # Store the tasklist ID temporarily as it will be lost in the Task # object as it is re-created with the Google service update response. tasklist_id = task.tasklist_id # Execute the update operation and capture the resulting str dict, # which contains the up-to-date values for the task properties. update_result_str_dict = self.service_proxy.update( tasklist=tasklist_id, task=task.entity_id, body=update_str_dict).execute() # Replace the Task with a new Task populated with the updated # properties. task = Task.from_str_dict(update_result_str_dict) task.tasklist_id = tasklist_id return task