Пример #1
0
def getChildren(id):  # returns a task from its id
    theTasks = []
    try:
        con = mysql.connect()  # set up database connection
        cur = con.cursor()
        cur.execute(
            ("SELECT * FROM task WHERE taskID IN"
             " (SELECT taskID FROM children_tasks WHERE parentTaskID=%s)"), id)
        data = cur.fetchall()
    except:
        con.rollback()
    finally:
        con.commit()
        con.close()
    for task in data:
        taskInstance = Task()  # create the task instance
        taskInstance.set_taskID(task[0])
        taskInstance.set_name(task[1])
        taskInstance.set_effort(task[2])
        taskInstance.set_deadline(task[3])
        taskInstance.set_description(task[4])
        taskInstance.set_assigned_user(task[8])
        taskInstance.add_child_task(getChildren(taskInstance.get_taskID()))
        theTasks.append(taskInstance)
        # call the recursive function to populate the task hierarchy
    return theTasks  # return the task to be appended in the hierarchy
Пример #2
0
def taskDetails():
    taskID = request.args.get('taskID', None)
    projectID = request.args.get('projectID', None)
    error = request.args.get('error', None)
    if 'userID' not in session:  #if not logged in
        return render_template('login.html')
    if taskID is None or projectID is None:
        return home()

    role = session['role']
    try:
        con = mysql.connect()  # set up database connection
        cur = con.cursor()
        cur.execute("SELECT * FROM task WHERE taskID=%s",
                    taskID)  # get the task
        taskSQL = cur.fetchone()
        cur.execute("SELECT * FROM task WHERE parentTask=%s",
                    taskID)  # get its children
        childrenSQL = cur.fetchall()
    except:
        con.rollback()
    finally:
        con.commit()
        con.close()

    task = Task()  # create task object
    task.set_taskID(taskSQL[0])
    task.set_name(taskSQL[1])
    task.set_effort(taskSQL[2])
    task.set_status(taskSQL[3])
    task.set_deadline(taskSQL[4])
    task.set_description(taskSQL[5])
    task.set_assigned_user(taskSQL[8])
    for child in childrenSQL:  # append its child objects after creating them also
        childTask = Task()
        childTask.set_taskID(child[0])
        childTask.set_name(child[1])
        childTask.set_effort(child[2])
        childTask.set_status(child[3])
        childTask.set_deadline(child[4])
        childTask.set_description(child[5])
        childTask.set_assigned_user(child[8])
        task.add_child_task(childTask)  # add the child task to the task object

    return render_template("task.html",
                           task=task,
                           projectID=projectID,
                           role=role,
                           error=error,
                           userID=session['userID'])
Пример #3
0
def sortTasks(
    data
):  #data parameter - the sql returned from collecting all of the parent tasks for the projects.
    project = []  #list of tasks
    for task in data:
        taskInstance = Task()  # create the task instance
        taskInstance.set_taskID(task[0])
        taskInstance.set_name(task[1])
        taskInstance.set_effort(task[2])
        taskInstance.set_status(task[3])
        taskInstance.set_deadline(task[4])
        taskInstance.set_description(task[5])
        taskInstance.set_assigned_user(task[8])
        for childToAdd in getChildren(taskInstance.get_taskID()):
            taskInstance.add_child_task(childToAdd)  # composite pattern
        # call the recursive function to populate the task hierarchy
        project.append(taskInstance)
    return project  # sorts the data into the