示例#1
0
def extractFollowup(user_batches=False):
    import os, time
    import pandas as pd
    from fup.utils.dbwrap import sql2df
    from fup.utils.jsoninfo import configInfo, sessionInfo
    from fup.helpers.files import extendRowsFollowup

    config = configInfo()
    xlpath = config['path_to_excels_exported_from_database']
    df = sql2df('followup')

    if user_batches == True:
        session = sessionInfo()
        user_working = session['current_user_working']
        df_batchesinWork = df[df['Responsible'] == user_working]
        save_path = os.path.join(xlpath,
                                 '{} batches.xlsx'.format(user_working))
        df_batchesinWork.to_excel(save_path, index=False)
    else:
        save_path = os.path.join(xlpath, 'followup.xlsx')
        df.to_excel(save_path, index=False)
        for n in range(20):
            if os.path.isfile(save_path):
                extendRowsFollowup()
            else:
                time.sleep(2)
def homePage():
    #Check user in database and send corespondend template
    userinfo = sessionInfo()
    username = userinfo['current_user_working']
    password = userinfo['current_user_password']
    check_user(username, password)
    userinfo = sessionInfo()
    if userinfo["current_user_rights"] == 'user':
        return render_template('users/user_page.html')
    elif userinfo["current_user_rights"] == 'proofreader':
        return render_template('users/proofreader_page.html')
    elif userinfo["current_user_rights"] == 'admin':
        return render_template('users/admin_page.html')
    else:
        errormessage = "Incorrect inputs or user not in database!"
        return redirect(
            url_for('comm.showFailedPage', errormessage=errormessage))
示例#3
0
def createAssignedDirFiles(unassignedBatch):
    import os, re, shutil
    from fup.utils.jsoninfo import configInfo, sessionInfo
    from fup.utils.commun import getfilespath_from, deletetree
    config = configInfo()
    session = sessionInfo()
    user = session['current_user_working']
    if re.search('@', user):
        user = user.split('@')[0]

    dir_unassigned = config[
        "path_to_batches_prepfiles"]  #changed from unassigned path to prepfiles path
    dir_assigned = config['path_to_batches_assigned']
    dir_frontend = config['path_to_frontend']
    dir_feli = os.listdir(dir_frontend)
    dir_feli = [f for f in dir_feli if re.search('.xlsm', f)]
    dir_feFile = [f for f in dir_feli if not re.search('BETA', f.upper())]
    dir_bidli = os.listdir(dir_unassigned)

    try:
        for biddir in dir_bidli:
            if re.search(unassignedBatch, biddir):
                #Get the unassigned and assigned folders paths
                opfile_dirunassigned = os.path.join(dir_unassigned, biddir)
                opfile_dirassigned = os.path.join(dir_assigned,
                                                  str(user + '-' + biddir))
                #Make a new directory in the Assigned folder
                os.mkdir(opfile_dirassigned)
                #Copy the FE macro to the folder created
                fepathfile = os.path.join(dir_frontend, dir_feFile[0])
                shutil.copy2(fepathfile, opfile_dirassigned)
                #Create also here the OP FILE folder and copy here the files from unassigned
                opfilepath = os.path.join(opfile_dirassigned, 'OP FILE')
                os.mkdir(opfilepath)
                org_filesli = getfilespath_from(opfile_dirunassigned)
                org_files = [
                    f for f in org_filesli if not re.search('Thumbs.db', f)
                ]
                for file in org_files:
                    shutil.copy2(file, opfilepath)

                #Rename the FE macro
                filesinassigned = os.listdir(opfile_dirassigned)
                fenameold = [
                    f for f in filesinassigned if re.search('.xlsm', f)
                ][0]
                fefileold = os.path.join(opfile_dirassigned, fenameold)
                fenamenew = unassignedBatch + '-' + fenameold
                fefilenew = os.path.join(opfile_dirassigned, fenamenew)
                os.rename(fefileold, fefilenew)
                #delete the dir from prep files folder
                deletetree(os.path.join(dir_unassigned, biddir))

        return True

    except Exception as e:
        print("GOT: ", e)
        return False
示例#4
0
def mergeDirBatches(batchidstrli):
    import os, re, shutil, time
    from fup.utils.commun import copytree, generateID, listifyString
    from fup.utils.jsoninfo import configInfo, sessionInfo
    config = configInfo()
    session = sessionInfo()
    try:
        user = session['current_user_working']
        if re.search('@', user):
            user = user.split('@')[0]

        batchidli = listifyString(batchidstrli)

        dir_assigned = config['path_to_batches_assigned']
        dirs_assigned = os.listdir(dir_assigned)

        #Make a dir for the merged batches
        mergedID = generateID()
        mergeddirpath = os.path.join(
            dir_assigned, '{}-___ A___ BID_{}'.format(user, mergedID))
        os.mkdir(mergeddirpath)

        #Get names of the folders from Assigned folder by checking the BID
        dirstomergeli = []
        for batchid in batchidli:
            dir_bidAssigned = [
                d for d in dirs_assigned if re.search(batchid, d)
            ]
            dirstomergeli.append(dir_bidAssigned[0])

        #Copy contents of the old batches into the new created merged folder
        for folderName in dirstomergeli:
            assignedPathOld = os.path.join(dir_assigned, folderName)
            src, dst = assignedPathOld, mergeddirpath
            copytree(src, dst, symlinks=False, ignore=None)
            files_not_deleted = True
            while files_not_deleted:
                try:
                    shutil.rmtree(assignedPathOld)  #delete folders
                    files_not_deleted = False
                except:
                    print("Please close file(s) open in folder {}".format(
                        assignedPathOld))
                    time.sleep(2)

        mergedInfodict = {
            'mergedID': mergedID,
            'mergeddirpath': mergeddirpath,
            'batchidli': batchidli
        }
        return mergedInfodict
    except Exception as e:
        print('mergeDirBatches/helpers Got :', e)
        return False
def updateBatchinFollowup(batchdict):
    from fup.utils.dbwrap import sql_updateDict, tb_cols_placeholder
    from fup.utils.commun import cleanDict
    from fup.utils.jsoninfo import sessionInfo
    from fup.helpers.batchdirs import moveDirsforUpdate, renameAssgnDir
    from fup.models.batch import verifyStatus, resetStartDate

    #print('updateBatchinFollowup: ', batchdict)

    session = sessionInfo()

    try:
        cleanedBatch = cleanDict(batchdict)
        comment = cleanedBatch['comments']
        cleanedBatch.pop('comments', None)

        if session["current_user_rights"] == 'user':
            cleanedBatch['ResponsibleComment'] = comment
        elif session["current_user_rights"] == 'proofreader' or session[
                "current_user_rights"] == 'admin':
            cleanedBatch['ProofreaderComment'] = comment
    except:  #no comments
        pass

    followupCols = list(tb_cols_placeholder('followup')['columns'])
    infoBatchdict = {}
    for k, v in cleanedBatch.items():
        if k in followupCols:
            infoBatchdict[k] = v

    #print('updateBatchinFollowup-infoBatchdict: ', infoBatchdict)
    movedir_response = moveDirsforUpdate(infoBatchdict)
    #print(movedir_response)
    if movedir_response == False:
        return False

    infoBatchdict = verifyStatus(infoBatchdict)
    resetStartDate(infoBatchdict)
    #print('infoBatchdict ', infoBatchdict)
    try:
        if isinstance(infoBatchdict['Responsible'], str):
            renameAssgnDir(infoBatchdict)
    except:
        pass

    if sql_updateDict('followup', infoBatchdict, 'BatchID') == False:
        return False
    else:
        return True
示例#6
0
def viewBatches(user_batches=False):
    from fup.utils.dbwrap import get_dftable
    from fup.utils.jsoninfo import sessionInfo
    import pandas
    df = get_dftable('followup')
    if user_batches == True:
        session = sessionInfo()
        user_working = session['current_user_working']
        df_batchesinWork = df[df['Responsible'] == user_working]
        df_dictinWork = df_batchesinWork.reindex(
            index=df_batchesinWork.index[::-1]).to_dict('list')
        return df_dictinWork
    else:
        df_dict = df.reindex(index=df.index[::-1]).to_dict('list')
        return df_dict
def delegateUserPage():
    #Check user in database and send corespondend template
    username = request.form['username']
    password = request.form['password']
    check_user(username, password)
    userinfo = sessionInfo()
    #print('guguuuu', userinfo)
    if userinfo["current_user_rights"] == 'user':
        return render_template('users/user_page.html')
    elif userinfo["current_user_rights"] == 'proofreader':
        return render_template('users/proofreader_page.html')
    elif userinfo["current_user_rights"] == 'admin':
        return render_template('users/admin_page.html')
    else:
        errormessage = "Incorrect inputs or user not in database!"
        return redirect(
            url_for('comm.showFailedPage', errormessage=errormessage))
def assignBatchtoUser(batchID, assignedtoProofreader):
    from fup.utils.jsoninfo import sessionInfo
    from fup.utils.commun import current_date
    from fup.helpers.batch import getUnassignedBatch
    from fup.helpers.batchdirs import createAssignedDirFiles
    from fup.models.batch import checkOverallStatus
    from fup.utils.dbwrap import sql_updateDict
    from fup.helpers.batch import batchExists
    from fup.helpers.user import getuserProofreader

    if checkOverallStatus() == True:

        date = current_date()
        userinfo = sessionInfo()
        responsible_user = userinfo["current_user_working"]
        defaultProofreader = getuserProofreader(responsible_user)

        tableName = 'followup'

        updatedict = {
            "BatchID": batchID,
            "Responsible": responsible_user,
            "ResponsibleStatus": "ASSIGNED",
            "Proofreader": defaultProofreader,
            "ProofreaderStatus": "ASSIGNED",
            "ChangesLog": ''
        }
        if defaultProofreader == "UNASSIGNED":
            updatedict["ProofreaderStatus"] = "UNASSIGNED"

        updatedict_fallback = {
            "BatchID": batchID,
            "Responsible": "UNASSIGNED",
            "ResponsibleStatus": "UNASSIGNED",
            "Proofreader": "UNASSIGNED",
            "ProofreaderStatus": "UNASSIGNED",
            "ChangesLog": ''
        }

        colIDName = "BatchID"

        #print(updatedict)
        if (batchID == '' or batchExists(batchID)) and (assignedtoProofreader
                                                        == True):
            unassignedBatch = getUnassignedBatch(batchID, 'ProofreaderStatus')
            updatedict["BatchID"] = unassignedBatch
            updatedict_fallback["BatchID"] = unassignedBatch
        elif (batchID == '' or batchExists(batchID)) and (assignedtoProofreader
                                                          == False):
            unassignedBatch = getUnassignedBatch(batchID, 'ResponsibleStatus')
            updatedict["BatchID"] = unassignedBatch
            updatedict_fallback["BatchID"] = unassignedBatch

        if assignedtoProofreader == True:
            updatedict.pop("Responsible", None)
            updatedict.pop("ResponsibleStatus", None)
            updatedict.pop("ChangesLog", None)
            if sql_updateDict(tableName, updatedict, colIDName) == True:
                checkOverallStatus()
                return True
            else:
                print('1fallback', tableName, updatedict, colIDName)
                sql_updateDict(tableName, updatedict_fallback, colIDName)
                return False

        elif assignedtoProofreader == False:
            loginfo = "ASSIGNED to {} on {}".format(responsible_user, date)
            updatedict["ChangesLog"] = loginfo
            updatedict["StartDate"] = date
            if (sql_updateDict(tableName, updatedict,
                               colIDName)) == True and (createAssignedDirFiles(
                                   updatedict["BatchID"]) == True):
                checkOverallStatus()
                return True
            else:
                print('2fallback', tableName, updatedict, colIDName)
                sql_updateDict(tableName, updatedict_fallback, colIDName)
                return False
    else:
        return False
示例#9
0
def updateBatchOptions(batchlink=''):
    #get batch update options depending on the user type (user/responsible, admin or proofreader)
    import re
    from fup.utils.commun import listifyString
    from fup.utils.jsoninfo import configInfo, sessionInfo
    from fup.helpers.user import get_usersdict
    from fup.helpers.batch import viewBatches
    from fup.helpers.batch import batchInfo

    #print('updateBatchOptions: ', batchlink)

    config = configInfo()
    update_options_responsible = listifyString(
        config['batch_status_options_responsible'])
    update_options_proofreader = listifyString(
        config['batch_status_options_proofreader'])
    update_options_overall = listifyString(
        config['batch_status_options_overall'])
    aircraft = listifyString(config['aircraft'])
    split_batch_factor = listifyString(config['split_batch_factor'])
    allusers = get_usersdict(True)
    allusers = [user for user in allusers if re.search('\.', user)]
    print("users: ", allusers)

    session = sessionInfo()
    current_user_rights = session['current_user_rights']

    infoBatch = batchInfo(batchlink)
    try:
        infoBatch["Operator"]
    except:
        infoBatch = {
            'Operator': '',
            'Aircraft': '',
            'OverallStatus': '',
            'AddedDate': '',
            'StartDate': '',
            'ImportedDateISAIM': ''
        }

    update_batch_dict = {
        "responsibleStatus": update_options_responsible,
        "proofreaderStatus": update_options_proofreader,
        "overallStatus": update_options_overall,
        "aircraft": aircraft,
        "splitBatch": split_batch_factor,
        "allusers": allusers,
        "batchlink": batchlink,
        "userBatches": viewBatches(user_batches=True),
        "disableCommentResponsible": '',
        "disableCommentProofreader": '',
        "disableCheckbox": '',
        "infoBatch": infoBatch
    }

    if current_user_rights == 'user':
        update_batch_dict["proofreaderStatus"] = ['You cannot change this']
        update_batch_dict["allusers"] = ['You cannot change this']
        update_batch_dict["overallStatus"] = ['You cannot change this']
        update_batch_dict["disableCommentProofreader"] = "disabled"
        update_batch_dict["disableCheckbox"] = "disabled"
        return update_batch_dict
    elif current_user_rights == 'proofreader':
        update_batch_dict["responsibleStatus"] = ['You cannot change this']
        update_batch_dict["disableCommentResponsible"] = "disabled"
        return update_batch_dict
    elif current_user_rights == 'admin':
        return update_batch_dict