def send_email_to_admin(): """ :return: """ if request.method == "POST": message = request.get_json()["message"] if "10" != request.get_json()["theSum"]: return json_result(False, mistake=True, message="") current_user = UserDB.query.filter_by(email=session["email"]).first() envoyer_message_contact(current_user.email, message) return json_result(True, mistake=False, message="Mail correctly sent") else: return json_result(False, mistake=False, message="Wrong method")
def load_row(n_row): processed_row = rows[n_row] print(processed_row) description = processed_row["description"] print(description) if request.method == "GET": ref = icu.extraire_ref_biblio(description) record = icu.extraire_enregistrements(processed_row) already_stored = n_row in already_stored_rows return json_result(True, data=processed_row, ref=ref, record=record, already_stored=already_stored), 200 elif request.method == "POST": store_new_stored_row(n_row) return json_result(True), 200 return json_result(True, message="pas bon"), 400
def check_row_coherence(): l = [] for number, processed_row in enumerate(rows[1:]): if number % 10 == 0: print(number) # print(processed_row) description = processed_row["description"] # print(description) ref = icu.extraire_ref_biblio(description) if ref is None: print(number, "ref is None", description) continue if "authors" not in ref: print(number, "failed because authors not in ref") continue record = icu.extraire_enregistrements(processed_row) if record is None: print("record is None", processed_row) continue # print(record) enregistrement_db = Enregistrement.from_data_to_db(record) is_valid = enregistrement_db.cote in description if not is_valid: l.append(dict(valid=is_valid, description=description, cote=enregistrement_db.cote)) # store_new_stored_row(processed_row) # return json_result(True, data=processed_row, ref=ref, record=record, already_stored=already_stored), 200 return json_result(True, valids=l), 200
def import_complete_catalogue_from_file(): for number, processed_row in enumerate(rows[1:]): if number % 100 == 0: print(number) # print(processed_row) description = processed_row["description"] # print(description) ref = icu.extraire_ref_biblio(description) if ref is None: print(number, "ref is None") continue if "authors" not in ref: print(number, "failed because authors not in ref") continue auteurs = [] for author in ref["authors"]: # print(author) author_exists = AuthorDB.query.filter_by(first_name=author["first_name"], family_name=author["family_name"]).first() if not author_exists: author_db = Author.from_data_to_db(author) db.session.add(author_db) db.session.commit() author_exists = author_db auteurs.append(dict(value=author_exists.id)) # if dv.check_reference_bibliographique_livre(ref): ref["auteurs"] = auteurs # print(ref) reference_db = ReferenceBibliographiqueLivre.from_data_to_db(ref) # print(reference_db) record = icu.extraire_enregistrements(processed_row) if record is None: print("record is None") continue # print(record) # region reference db.session.add(reference_db) db.session.commit() # endregion # region record enregistrement_db = Enregistrement.from_data_to_db(record) # print(enregistrement_db) enregistrement_db.reference = reference_db db.session.add(enregistrement_db) db.session.commit() # endregion # store_new_stored_row(processed_row) # return json_result(True, data=processed_row, ref=ref, record=record, already_stored=already_stored), 200 return json_result(True), 200
def delete_catalogue(): EnregistrementDB.query.delete() ReferenceBibliographiqueLivreDB.query.delete() AuthorDB.query.delete() db.session.commit() return json_result(True), 200
def go_to_next_not_marked_row(n_row): n = get_next_not_marked_row(n_row) return json_result(True, n=n), 200
def remove_from_store(n_row): remove_row_from_stored(n_row) return json_result(True, message="pas bon"), 200
def add_to_store(n_row): store_new_stored_row(n_row) return json_result(True), 200
def get_import_csv_count(): print("count") return json_result(True, total=len(rows)), 200
def import_csv(): n_page = int(request.args.get("page")) size = int(request.args.get("size")) print(n_page, size) return json_result(True, rows=rows[(n_page - 1) * size:n_page * size]), 200