def get_searching_user(): search_dict_dps=(request.args.get('search_dict', 1)) search_dict=json.loads(request.args.get('search_dict', 1)) page= int(request.args.get('page', 1)) try: con=postgres_connetion( host_postgres, db_name_postgres, db_user_postgres, db_password_postgres) cur=con.cursor() count,page_result,columns_names,record=search_user_pages(search_dict,page,cur) link_next="" link_previous="" max_pages=0 if not record: redirect('user.search_user_') flash("Zéro Résultat , Merci D'affiner votre recherche !") else : file_name=f"search_user_result" csv_columns = columns_names.copy() csv_columns.insert(0,'id') csv_columns.remove('Link') csv_columns.append('nombre de resultat') all_record=search_all_user(search_dict,cur) to_csv(file_name,csv_columns,all_record) next_page=page+1 previous=page-1 results=page_result*page if count%page_result==0: max_pages=count//page_result else: max_pages=count//page_result max_pages=max_pages+1 if results>=count and page==1: link_next=url_for('user.get_search_user_',search_dict=search_dict_dps,page=1) elif page>1 and results>=count: link_next=url_for('user.get_search_user_',search_dict=search_dict_dps,page=page) else: link_next=url_for('user.get_search_user_',search_dict=search_dict_dps,page=next_page) if page==1: link_previous=url_for('user.get_search_user_',search_dict=search_dict_dps,page=1) else: link_previous=url_for('user.get_search_user_',search_dict=search_dict_dps,page=previous) except Exception as error: print(error) abort(422) finally : if con is not None: cur.close() con.close() return render_template( "search/search_user.html",search_result=record,columns=columns_names, search_dict=search_dict_dps,link_next=link_next,link_previous=link_previous,page=page,nb=page_result,max_pages=max_pages)
def search_result(): search_dict_dps=request.args.get('search_dict',{}) search_dict= json.loads(request.args.get('search_dict',{})) page= int(request.args.get('page', 1)) try: con=postgres_connetion( host_postgres, db_name_postgres, db_user_postgres, db_password_postgres) cur=con.cursor() count,page_result,columns_names,record=search_sinister(search_dict,page,cur) link_next="" link_previous="" max_pages=0 if not record: flash('Zero Result , Please Check Your Search Criteria !') return redirect(url_for('sinister.search_sinisters')) else: file_name=f"search_sinister_result" csv_columns = columns_names.copy() csv_columns.insert(0,'id') csv_columns.remove('Link') csv_columns.append('number_results') all_record=search_all_sinister(search_dict,cur) to_csv(file_name,csv_columns,all_record) next_page=page+1 previous=page-1 results=page_result*page if count%page_result==0: max_pages=count//page_result else: max_pages=(count//page_result)+1 if results>=count and page==1: link_next=url_for('sinister.search_result_',search_dict=search_dict_dps,page=1) elif page>1 and results>=count: link_next=url_for('sinister.search_result_',search_dict=search_dict_dps,page=page) else: link_next=url_for('sinister.search_result_',search_dict=search_dict_dps,page=next_page) if page==1: link_previous=url_for('sinister.search_result_',search_dict=search_dict_dps,page=1) else: link_previous=url_for('sinister.search_result_',search_dict=search_dict_dps,page=previous) except Exception as error: print(error) abort(422) finally : if con is not None: cur.close() con.close() return render_template( "search/search_sinisters.html",search_result=record,columns=columns_names, search_dict=search_dict_dps,link_next=link_next,link_previous=link_previous,page=page,nb=page_result,max_pages=max_pages)
def get_searching_client(): search_dict_dps = (request.args.get('search_dict', 1)) search_dict = json.loads(request.args.get('search_dict', 1)) page = int(request.args.get('page', 1)) try: con = postgres_connetion(host_postgres, db_name_postgres, db_user_postgres, db_password_postgres) cur = con.cursor() count, page_result, columns_names, record = search_client_pages( search_dict, page, cur) link_next = "" link_previous = "" max_pages = 0 if not record: redirect('client.search_client_') flash('Zero Result , Please Check Your Search Criteria !') else: file_name = f"search_result" csv_columns = columns_names.copy() csv_columns.remove('Link') csv_columns.append('contracts') csv_columns.append('number_results') record2 = search_client_pages_export(search_dict, page, cur) to_csv(file_name, csv_columns, record2) next_page = page + 1 previous = page - 1 results = page_result * page max_pages = count // page_result if count % page_result == 0: max_pages = count // page_result else: max_pages = max_pages + 1 if results >= count and page == 1: link_next = url_for('client.get_search_client_', search_dict=search_dict_dps, page=1) elif page > 1 and results >= count: link_next = url_for('client.get_search_client_', search_dict=search_dict_dps, page=page) else: link_next = url_for('client.get_search_client_', search_dict=search_dict_dps, page=next_page) if page == 1: link_previous = url_for('client.get_search_client_', search_dict=search_dict_dps, page=1) else: link_previous = url_for('client.get_search_client_', search_dict=search_dict_dps, page=previous) except Exception as error: print(error) abort(422) finally: if con is not None: cur.close() con.close() return render_template("search/search_client.html", search_result=record, columns=columns_names, search_dict=search_dict_dps, link_next=link_next, link_previous=link_previous, page=page, nb=page_result, max_pages=max_pages, now=str(datetime.datetime.now().date()))
def show_payments(id, contract_id): try: con = postgres_connetion(host_postgres, db_name_postgres, db_user_postgres, db_password_postgres) cur = con.cursor() columns, columns_names, record = show_client_payments( id, contract_id, cur) if request.method == 'POST': if request.form['submit'] == 'payer': f = request.form for key in f.keys(): if key != 'submit': update_payment( { 'status': 'Payé', 'payment_date': str( datetime.datetime.now().date()) }, id, request.form[key], con, cur) submit = request.form['submit'] if submit == 'export': columns.append('payment_sum') columns.append('total_number') file_name = f"échéance_{contract_id}" csv = to_csv(file_name, columns, record[:-3]) response = make_response(csv) response.headers[ "Content-Disposition"] = "attachment; filename=books.csv" return response if submit == 'pdf': file_name = f"pdf_{contract_id}.pdf" template = render_template("payments_table.html", search_result=record, columns=columns_names, id=id, contract_id=contract_id) main_dir = os.path.basename( os.path.dirname(os.path.dirname(__file__))) css1 = os.path.join(main_dir, "static", "css", "bootstrap.min.css") css2 = os.path.join(main_dir, "static", "css", "bootstrap.css") css = [css1, css2] pdf = pdfkit.from_string(template, False, css=css) response = make_response(pdf) response.headers['Content-type'] = 'application/pdf' response.headers[ 'Content-disposition'] = f'inline;filename={file_name}' return response except Exception as error: print(error) abort(422) finally: if con is not None: cur.close() con.close() return render_template("payments.html", search_result=record, columns=columns_names, id=id, contract_id=contract_id)