Example #1
0
File: task.py Project: an/GTGOnline
def add_task(user, name, description, start_date, due_date, folder, \
             tag_list = None, parent_id = -1, parent_object = None, \
             needs_task_dict = True):
    '''
    Use this to add a new task. New task means completely new.
    Updating name, description etc. has got it's own functions.
    To create the task as a subtask, give the parent's id in parent_id
    '''
    start_date = get_datetime_object(start_date)
    due_date = get_datetime_object(due_date)
    #print >>sys.stderr, "due_date start = " + str(due_date)
    
    if start_date != None and due_date != None:
        if start_date > due_date:
            start_date = due_date
    
    new_task = Task(user = user, name = name, description = description, \
                    start_date = start_date, due_date = due_date)
    
    # Try to remove this function and use tag_list obtained from client instead
    tag_list = find_tags(name + " " + description)
    
    new_tags, existing_tags = create_tag_objects(user, tag_list)
    new_task.save()
    #print >>sys.stderr, 'after saving in add task, new_task = ' + str(new_task)
    new_task.tags.add(*(new_tags+existing_tags))
    
    parent = None
    if parent_object != None:
        parent = parent_object
    elif parent_id != -1:
        parent = get_task_object(user, parent_id)
    if parent != None:
        new_task.task_set.add(parent)
        modify_parents_dates(new_task, parent, due_date)
        if needs_task_dict:
            new_task = get_task_tree(user, get_oldest_parent(parent), \
                                     0, [], folder)
    
    #print >>sys.stderr, 'before return in add task, new_task = ' + str(new_task)        
    return new_task, parent
Example #2
0
File: task.py Project: an/GTGOnline
def update_task_details(user, task_id, new_name, new_description, \
                        new_start_date, new_due_date, folder, \
                        origin = None, subtask_ids = [], status = IS_ACTIVE):
    task = get_task_object(user, task_id)
    if task == None:
        return
    task.name = new_name
    task.description = new_description
    
    tag_list = find_tags(new_name + " " + new_description)
    new_tags, existing_tags = create_tag_objects(user, tag_list)
    update_tag_set(task, new_tags + existing_tags)
    
    new_start_date = get_datetime_object(new_start_date)
    task = change_task_date(user, task, new_start_date, IS_START_DATE)
    new_due_date = get_datetime_object(new_due_date)
    task = change_task_date(user, task, new_due_date, IS_DUE_DATE)
    
    if task.shared_with.exists():
        update_log(user, task, LOG_TASK_MODIFY)
    
    if subtask_ids != []:
        task = add_remove_subtasks(task, subtask_ids)
    
    change_task_tree_due_date(user, task, new_due_date)
    
    if origin != None:
        print >>sys.stderr, "OLD STATUS = " + str(task.status)
        change_task_status(user, -1, status, task = task)
        print >>sys.stderr, "RECEIVED STATUS = " + str(status)
        print >>sys.stderr, "NEW STATUS = " + str(task.status)
    
    task.save()
    #print >>sys.stderr, str(get_oldest_parent(task))
    
    if origin != None:
        return None
    
    return get_task_tree(user, get_oldest_parent(task), 0, [], folder)