Exemplo n.º 1
0
def editTask():
    csql = t2t_sqlite.editTask(item, request.args.get('taskid'), request.args.get('troopid'), request.args.get('eventid'))
    if csql is not None:
        debug(csql)
        debug(callSQL(usersdb, csql))
        return "GOOD EDIT!"
    else:
        return "Task edit error!"
Exemplo n.º 2
0
def view_workspace():
    try:
        if session['email'] is not None:
            debug('User: '******'email'])
        else:
            return redirect('/login')
    except:
        return redirect('/login')

    htmlTable = ''
    csql = None
    formAddTroop = AddTroopForm()
    formAddEvent = AddEventForm()
    formAddTask = AddTaskForm()
    formEditTask = EditTaskForm()

    dbase = './troops-to-task/user_db.sqlite'
    sql = t2t_sqlite.getUser(session['email'])
    check = callSQL(dbase, sql)

    usersdb = './troops-to-task/userdb/' + check[0][5] + '.sqlite'

    if formAddTroop.validate_on_submit():
        sql = t2t_sqlite.addTroop(formAddTroop.troopid.data, formAddTroop.rank.data, formAddTroop.first_name.data, formAddTroop.last_name.data)
        callSQL(usersdb, sql)

    if formAddEvent.validate_on_submit():
        sql = t2t_sqlite.addEvent(formAddEvent.title.data, formAddEvent.startDTG.data, formAddEvent.endDTG.data)
        callSQL(usersdb, sql)

    if formAddTask.validate_on_submit():
        sql = t2t_sqlite.addTask(formAddTask.troopid.data, formAddTask.eventid.data)
        callSQL(usersdb, sql)

    #render the page for the user's workspace
    tblreq = request.args.get('show')
    rmreq = request.args.get('rm')
    edreq = request.args.get('ed')
    item = request.args.get('i')
    try:
        if tblreq is None:
            try:
                sql = t2t_sqlite.listCurrentTroopstoTask()
            except:
                flash('Error loading the Current Troops to Task Table.')
        elif tblreq == 'troops':
            sql = t2t_sqlite.shortList('troops')
        elif tblreq == 'events':
            sql = t2t_sqlite.shortList('events')
        elif tblreq == 'tasks':
            sql = t2t_sqlite.shortList('tasks')

        if rmreq is None:
            csql = None
        elif rmreq == 'e':
            csql = t2t_sqlite.removeEvent(item)
        elif rmreq == 'tr':
            csql = t2t_sqlite.removeTroop(item)
        elif rmreq == 'ta':
            csql = t2t_sqlite.removeTask(item)

        if edreq is None:
            csql = None
        elif edreq == 'e':
            csql = t2t_sqlite.editEvent(item, request.args.get('title'), request.args.get('startDTG'), request.args.get('endDTG'))
        elif edreq == 'tr':
            csql = t2t_sqlite.editTroop(item, request.args.get('troopid'), request.args.get('eventid'))
        elif edreq == 'ta':
            csql = t2t_sqlite.editTask(item, request.args.get('rank'), request.args.get('firstName'), request.args.get('lastName'))

        if csql is not None:
            debug(csql)
            debug(callSQL(usersdb, csql))

        debug(sql)
        theReturn = selectTable(usersdb, sql)

        if theReturn == []:
            htmlTable = 'There are no current Troops to Task.'
        else:
            table = print_table(theReturn[0], theReturn[1])
            htmlTable = table.get_html_string(attributes = {"class": "table table-striped"})

        return render_template('workspace.html',
                                user=check[0][1],
                                table=htmlTable,
                                AddTroopForm=formAddTroop,
                                AddEventForm=formAddEvent,
                                AddTaskForm=formAddTask,
                                EditTaskForm=formEditTask)

    except:
        return show_error_page('Workspace failed to load correctly.')