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
def importFollowup(): #check if the excel contains the columns needed and import it if it has import pandas as pd from fup.utils.dbwrap import tb_cols_placeholder, df2sql from fup.utils.jsoninfo import configInfo config = configInfo() followup_columns = list(tb_cols_placeholder('followup')['columns']) df = pd.read_excel(config['path_to_excels_to_be_imported_in_database'] + 'followup.xlsx') xlfollowupColsli = df.columns.tolist() cols_diff = list(set(followup_columns).difference(set(xlfollowupColsli))) if len(cols_diff) == 0: df2sql(df, 'followup') return True else: colsneeded = ', '.join(followup_columns) response = "The followup.xlsx must contain theese columns: " + colsneeded return response