def download_action(): if utils_validations.validate_admin(session['user'], session['password']): try: Q = request.form["Q_button"] #file_path = path_crosland + "crosland_app/PDFs/" + Q file_path = path_crosland + "/PDFs/" + Q # local_path timestr = time.strftime("%Y%m%d-%H%M%S") fileName = "reportes_360_{}.zip".format(timestr) memory_file = io.BytesIO() with zipfile.ZipFile(memory_file, 'w', zipfile.ZIP_DEFLATED) as zipf: for root, dirs, files in os.walk(file_path): for file in files: zipf.write(os.path.join(root, file)) memory_file.seek(0) return send_file(memory_file, attachment_filename=fileName, as_attachment=True) #return str(request.form["Q_button"]) except: global Qs Qs = Qs flash('Aún no se han generado usuarios ni contraseñas') return render_template("download_previous_results.html", buttons=Qs) else: return "Inicia sesión"
def download_previous_results(): if utils_validations.validate_admin(session['user'], session['password']): global Qs Qs = Qs return render_template("download_previous_results.html", buttons=Qs) else: return "Inicia sesión"
def save_action_excel_plantilla_feedback(): if utils_validations.validate_admin(session['user'], session['password']): try: file = request.files.get('plantilla_feedback') file.save( os.path.join( "static\\data\\plantilla_resultados_feedback.xlsx")) return redirect("/previous_results") except: return redirect("/previous_results")
def download_action_excel_plantilla_critics(): if utils_validations.validate_admin(session['user'], session['password']): try: return send_file( 'static/data/plantilla_resultados_criticos.xlsx', mimetype='application/vnd.ms-excel', attachment_filename='plantilla_resultados_criticos.xlsx', as_attachment=True) except: return "No file found" else: return "Inicia sesión"
def template_dashboard_360(): try: if utils_validations.validate_admin(session['user'], session['password']): #return send_file(path_crosland+"crosland_app/static/files_to_download/Dashboard_360.pbix",attachment_filename="Dashboard_360.pbix",as_attachment=True) return send_file(path_crosland + "/static/files_to_download/Dashboard_360.pbix", attachment_filename="Dashboard_360.pbix", as_attachment=True) else: return render_template("fail_login_admin_html.html") except: return "Error al leer archivo/Inicie sesión como administrador"
def pdf_tutorial(): try: if utils_validations.validate_admin(session['user'], session['password']): #return send_file(path_crosland+"crosland_app/static/files_to_download/Tutorial_Actualizando_Dashboard.pdf",attachment_filename="Tutorial_Actualizando_Dashboard.pdf") return send_file( path_crosland + "/static/files_to_download/Tutorial_Actualizando_Dashboard.pdf", attachment_filename="Tutorial_Actualizando_Dashboard.pdf") else: return render_template("fail_login_admin_html.html") except: return "Error al leer archivo/Inicie sesión como administrador"
def download_action_excel(): if utils_validations.validate_admin(session['user'], session['password']): try: df_results_temp = pd.read_csv("data/df_results.csv") resp = make_response(df_results_temp.to_csv(index=False, sep=";")) resp.headers[ "Content-Disposition"] = "attachment; filename=Resultados_maestro.csv" resp.headers["Content-Type"] = "text/csv" return resp except: return "No file found" else: return "Inicia sesión"
def action_admin(): try: session['user'] = request.form["user"] session['password'] = request.form["password"] except: pass try: if utils_validations.validate_admin(session['user'], session['password']): return render_template("action_admin_html.html") else: return render_template("fail_login_admin_html.html") except: return render_template("fail_login_admin_html.html")
def upload_files(): try: if utils_validations.validate_admin(session['user'], session['password']): return render_template("surveys_files_html.html") else: return render_template("fail_login_admin_html.html") except: try: file_format_error = request.form["error_button"] if file_format_error == "user_error" or file_format_error == "data_process_error": return render_template("surveys_files_html.html") else: return "Unknown user start counterattack 1" except: return "Unknown user start counterattack 2"
def dnis_chunks(Periodo_path, Periodo): try: if utils_validations.validate_admin(session['user'], session['password']): pass else: return ("Error al cargar la página iniciar sesión") except: return ("Error al cargar la página iniciar sesión") global df_complete df_complete = df_complete global df_feedback df_feedback = df_feedback global df_auto df_auto = df_auto Periodo_path = Periodo_path.replace(";", "/") options = {"enable-local-file-access": None} path_wkthmltopdf = wkhtmltopdf_path config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf) DNIs = session["DNIs"] if len(DNIs) >= 30: DNIs_temp = DNIs[:30] session["DNIs"] = DNIs[30:] else: DNIs_temp = DNIs[:30] session["DNIs"] = [] i = 0 #print(len(DNIs)) for DNI in DNIs_temp: i += 1 #print(DNI, i) df_complete_DNI = df_complete.loc[ df_complete["DNI_evaluado"].apply(utils_data_wrangling.try_int_str) == utils_data_wrangling.try_int_str(DNI)] name = df_complete_DNI["Nombre Completo_evaluado"].values[0] try: tipo_doc = df_complete_DNI["TIPO DE DOCUMENTO_evaluado"].dropna( ).values[0] except: tipo_doc = "DNI" #print('df_complete_DNI["TIPO DE DOCUMENTO_evaluado"]', df_complete_DNI["TIPO DE DOCUMENTO_evaluado"]) #print("tipo_doc:", tipo_doc) file_name = utils_data_wrangling.DNI_PDF_format( DNI, tipo_doc) + "-" + name + '.pdf' #print(file_name) df_auto_DNI = df_auto.loc[df_auto["DNI_evaluador"] == int(DNI)] #print(df_auto_DNI) #print("NOMBREEE: ", name) if (len(df_complete_DNI) == 0): #print("no results 1") render = render_template("home_html.html") pdfkit.from_string(render, "/PDFs/" + Periodo + "/" + file_name, configuration=config, options=options) else: try: year = session["year"] print("YEAR:", year) dfs_show_coll = utils_data_wrangling.personal_reporting( df_complete[df_complete["year"] == year], df_feedback[df_feedback["year"] == year], df_auto[df_auto["year"] == year], int(DNI)) #dfs_show_coll = utils_data_wrangling.personal_reporting(df_complete,df_feedback,df_auto,int(DNI)) #print(dfs_show_coll) dfs_show_coll_html = [ x.set_index(x.columns[0]).T.to_html( classes='data').replace('border="1"', 'border="0"') for x in dfs_show_coll ] #print(dfs_show_coll_html) dfs_cols = [x.columns.values for x in dfs_show_coll] #print(dfs_cols) #css_report_path = path_crosland + "crosland_app/static/css_colab_results_download.css" #logo_path = path_crosland + "crosland_app/static/pictures/crosland.png" css_report_path = path_crosland + "/static/css_colab_results_download.css" logo_path = path_crosland + "/static/pictures/crosland.png" render = render_template( "coll_results_html_download.html", css_path=css_report_path, tables=dfs_show_coll_html, logo_path=logo_path, titles=[ "", "Informacion personal", "Calificación Crosland", "Calificación Personal", "Calificación Personal por nivel ocupacional", "Feedback", "Autoevaluación" ]) print("render") #print(DNI, len(DNI)) pdfkit.from_string(render, Periodo_path + "/" + file_name, configuration=config, options=options, css=css_report_path) print("pdfkit") except: render = render_template("no_results.html") pdfkit.from_string(render, Periodo_path + "/" + file_name, configuration=config, options=options) #print("no results 2") Periodo_path = Periodo_path.replace("/", ";") if len(session["DNIs"]) > 0: return redirect(url_for("dnis_chunks", Periodo_path=Periodo_path, Periodo=Periodo), code=307) else: return render_template('final_html.html')
def final_page_action(): if request.method == 'POST': try: if utils_validations.validate_admin(session['user'], session['password']): pass else: return ("Error al cargar la página iniciar sesión") except: return ("Error al cargar la página iniciar sesión") year = session["year"] Q = session["Q"] Periodo = str(session["year"]) + "-" + session["Q"] #Periodo_path = path_crosland + "crosland_app/PDFs/"+Periodo Periodo_path = path_crosland + "/PDFs/" + Periodo # local_path try: shutil.rmtree(Periodo_path, ignore_errors=True) except: pass os.mkdir(Periodo_path) global df_complete df_complete = df_complete global df_feedback df_feedback = df_feedback global df_auto df_auto = df_auto global df_feedback_detail_old df_feedback_detail_old = df_feedback_detail_old global df_evaluator_satisfied_count_old df_evaluator_satisfied_count_old = df_evaluator_satisfied_count_old #print(df_complete) df_new = utils_data_wrangling.update(df_complete, "data/df_results.csv") #print(df_new) DNIs = [int(x) for x in df_complete.DNI_evaluado.unique()] session["DNIs"] = DNIs DNIs_all = [int(x) for x in df_new.DNI_evaluado.unique()] df_users_passwords = utils_data_wrangling.build_password_df(DNIs_all) df_complete = df_new.loc[df_new["Periodo"] <= Periodo] df_complete["DNI_evaluado"] = df_complete["DNI_evaluado"].astype(int) #print(df_users_passwords) df_users_passwords.to_csv("data/df_users_passwords.csv", encoding='utf-8', index=False) #df_users_passwords = df_users_passwords.to_csv(index = False) #resp_df_users_passwords = make_response(df_users_passwords) #resp_df_users_passwords.headers["Content-Disposition"] = "attachment; filename=export.csv" #resp_df_users_passwords.headers["Content-Type"] = "text/csv" #print("saved users pass") df_new_feedback = utils_data_wrangling.update(df_feedback, "data/df_feedback.csv") df_feedback = df_new_feedback.loc[ df_new_feedback["Periodo"] <= Periodo] df_auto["DNI_evaluador"] = df_auto["DNI_evaluador"].astype(int) #df_new_feedback.to_csv("data/df_feedback.csv", index = False) df_new_auto = utils_data_wrangling.update(df_auto, "data/df_auto.csv") df_auto = df_new_auto.loc[df_new_auto["Periodo"] <= Periodo] #df_new_auto.to_csv("data/df_auto.csv", index = False) df_feedback_detail_old = utils_data_wrangling.update( df_feedback_detail, "data/df_feedback_detail.csv") df_evaluator_satisfied_count_new = utils_data_wrangling.finder_critical_evaluator( df_new.loc[df_new["Periodo"] == Periodo]) df_evaluator_satisfied_count_old = utils_data_wrangling.update( df_evaluator_satisfied_count_new, "data/df_evaluator_satisfied_count.csv") global df_results df_results = pd.read_csv("data/df_results.csv") global df_feedback_old df_feedback_old = pd.read_csv("data/df_feedback.csv") global df_auto_old df_auto_old = pd.read_csv("data/df_auto.csv") global Qs Qs = list(df_results.Periodo.unique()) Qs.sort() Periodo_path = Periodo_path.replace("/", ";") return redirect(url_for("dnis_chunks", Periodo_path=Periodo_path, Periodo=Periodo), code=307)
def dashboard(): if utils_validations.validate_admin(session['user'], session['password']): return render_template("dashboard_html.html") else: return "Inicia sesión"