Пример #1
0
def get_task_details(user, task, include_subtasks = False):
    '''
    Takes input an user object and a task object, and returns a dictionary of
    only the details of that particular task. 'subtasks' key will be set to
    empty list, and 'indent' key will be set to 0.
    This dictionary can then be appended to the JSON object.
    User object is needed to get the datetime in string format based on his
    preferences
    '''
    start_date = get_datetime_str(user, task.start_date)
    due_date = get_datetime_str(user, task.due_date)
    closed_date = get_datetime_str(user, task.closed_date)
    last_modified_date = get_datetime_str(user, task.last_modified_date, \
                                          precise_needed = True)
    subtask_list = []
    if include_subtasks:
        subtask_list = [str(subtask.id) for subtask in task.subtasks.all()]
    details =  {"id": task.id, "name": task.name, \
                "description": task.description, \
                "start_date": start_date, "due_date": due_date, \
                "closed_date": closed_date, \
                "last_modified_date": last_modified_date, \
                "status": task.status, "tags": get_tags_by_task(task), \
                "subtasks": subtask_list, "indent": 0, \
                "shared_with": [], "owner": ''}
    return details
Пример #2
0
def get_task_tree_details(user, task, indent, visited_list, folder, \
                          main_list=[]):
    '''
    Takes input an user object and a task object, and returns a dictionary of all
    the details for the task AND all of it's subtasks having the same status.
    This dictionary can then be appended to the JSON object.
    User object is needed to get the datetime in string format based on his
    preferences
    '''
    
    start_date = get_datetime_str(user, task.start_date)
    due_date = get_datetime_str(user, task.due_date)
    closed_date = get_datetime_str(user, task.closed_date)
    last_modified_date = get_datetime_str(user, task.last_modified_date)
    
    shared = [get_user_details(i) for i in task.shared_with.all()]
    owner = ''
    
    if folder == -1:
        subtasks_list = task.subtasks.all()
    elif folder == YOUR_SHARED:
        subtasks_list = task.subtasks.annotate(num = Count('shared_with'))
        subtasks_list = subtasks_list.filter(num__gt = 0)
        print >>sys.stderr, "subtasks found = " + str(subtasks_list)
        owner = ''
    elif folder == THEY_SHARED:
        q = list(set(task.subtasks.all()).intersection(user.shared_set.all()))
        subtasks_list = q
        shared = []
        owner = get_user_details(task.user)
    else:
        subtasks_list = task.subtasks.filter(status = task.status)
        
    details =  {"id": task.id, "name": task.name, \
                "description": task.description, \
                "start_date": start_date, "due_date": due_date, \
                "closed_date": closed_date, \
                "last_modified_date": last_modified_date, \
                "status": task.status, "tags": get_tags_by_task(task), \
                "subtasks": get_task_tree(user, subtasks_list, \
                                          indent+1, visited_list, folder, \
                                          main_list = main_list), \
                "shared_with": shared, "owner": owner, \
                "indent": indent}    
    return details