diff --git a/Dockerfile b/Dockerfile index 34eba76..fae895d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.11-slim WORKDIR /app -RUN pip install --no-cache-dir flask flask-sqlalchemy pymysql cryptography +RUN pip install --no-cache-dir flask flask-sqlalchemy pymysql cryptography requests mysql-connector-python EXPOSE 5000 diff --git a/app/routes.py b/app/routes.py index 5b6ac4b..49e440e 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,4 +1,7 @@ from flask import Blueprint, render_template, request, redirect, url_for, session, flash +import time +import requests +import mysql.connector from werkzeug.security import check_password_hash, generate_password_hash from sqlalchemy import text from app import db @@ -141,6 +144,7 @@ def gestion_utilisateurs(): return render_template('gestion_utilisateurs.html', users=users) + # Route pour la gestion des actions @main.route('/gestion-actions', methods=['GET', 'POST']) def gestion_actions(): @@ -149,67 +153,52 @@ def gestion_actions(): if request.method == 'POST': action_type = request.form.get('action') - # On récupère aussi l'id caché s'il s'agit d'une modification action_id = request.form.get('id') - isin = request.form.get('isin') + isin = request.form.get('isin') or None ticker = request.form.get('ticker') - yahoo_code = request.form.get('yahoo_code') company_name = request.form.get('company_name') + exchange = request.form.get('exchange') + pays = request.form.get('pays') + currency = request.form.get('currency') if action_type == 'creer': - if isin: - try: - # Vérifier si l'ISIN existe déjà - check_query = text("SELECT COUNT(*) FROM actions WHERE isin = :isin") - exists = db.session.execute(check_query, {"isin": isin}).scalar() - - if exists > 0: - flash("L'action existe déjà, pas de création.", "warning") - else: - # L'id s'incrémente tout seul, on ne l'inclus pas dans l'INSERT - query = text(""" - INSERT INTO actions (isin, ticker, yahoo_code, company_name, updated_at) - VALUES (:isin, :ticker, :yahoo_code, :company_name, NOW()) - """) - db.session.execute(query, { - "isin": isin, - "ticker": ticker, - "yahoo_code": yahoo_code, - "company_name": company_name - }) - db.session.commit() - flash("Action créée", "success") - except Exception as e: - db.session.rollback() - flash("Erreur lors de la création de l'action.", "danger") - else: - flash("L'ISIN est obligatoire.", "danger") - + try: + query = text(""" + INSERT INTO actions (isin, ticker, company_name, exchange, pays, currency, updated_at) + VALUES (:isin, :ticker, :company_name, :exchange, :pays, :currency, NOW()) + """) + db.session.execute(query, { + "isin": isin, "ticker": ticker, "company_name": company_name, + "exchange": exchange, "pays": pays, "currency": currency + }) + db.session.commit() + flash("Action créée avec succès", "success") + except Exception as e: + db.session.rollback() + flash("Erreur lors de la création de l'action.", "danger") + elif action_type == 'modifier' and action_id: try: - # On met à jour en se basant sur l'id technique unique query = text(""" UPDATE actions - SET isin = :isin, ticker = :ticker, yahoo_code = :yahoo_code, company_name = :company_name, updated_at = NOW() + SET isin = :isin, ticker = :ticker, company_name = :company_name, exchange = :exchange, + pays = :pays, currency = :currency, updated_at = NOW() WHERE id = :id """) db.session.execute(query, { - "id": action_id, - "isin": isin, - "ticker": ticker, - "yahoo_code": yahoo_code, - "company_name": company_name + "id": action_id, "isin": isin, "ticker": ticker, "company_name": company_name, + "exchange": exchange, "pays": pays, "currency": currency }) db.session.commit() flash("Modification effectuée", "success") except Exception as e: db.session.rollback() - flash("Erreur lors de la modification (Vérifiez si l'ISIN n'est pas déjà utilisé par une autre ligne).", "danger") + flash("Erreur lors de la modification.", "danger") return redirect(url_for('main.gestion_actions')) - # On sélectionne l'id en plus dans la requête - actions_query = text("SELECT id, isin, ticker, yahoo_code, company_name, updated_at FROM actions ORDER BY company_name ASC") + # Récupération avec la nouvelle structure + actions_query = text("SELECT id, isin, ticker, company_name, exchange, pays, currency, updated_at FROM actions ORDER BY company_name ASC") result = db.session.execute(actions_query) actions_list = [] @@ -218,8 +207,10 @@ def gestion_actions(): 'id': row.id, 'isin': row.isin if row.isin else '', 'ticker': row.ticker if row.ticker else '', - 'yahoo_code': row.yahoo_code if row.yahoo_code else '', 'company_name': row.company_name if row.company_name else 'Sans nom', + 'exchange': row.exchange if row.exchange else '', + 'pays': row.pays if row.pays else '', + 'currency': row.currency if row.currency else '', 'updated_at': row.updated_at.strftime('%Y-%m-%d %H:%M:%S') if row.updated_at else '' }) @@ -302,4 +293,6 @@ def gestion_societes(): 'Mail': row.Mail if row.Mail else '' }) - return render_template('gestion_societes.html', societes=societes) \ No newline at end of file + return render_template('gestion_societes.html', societes=societes) + + diff --git a/app/templates/gestion_actions.html b/app/templates/gestion_actions.html index bed31a9..1790247 100644 --- a/app/templates/gestion_actions.html +++ b/app/templates/gestion_actions.html @@ -2,7 +2,7 @@ endblock %} {% block header_title %}Gestion actions{% endblock %} {% block content %}