diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index 6a831d866..5f0cfd3ec 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -367,10 +367,10 @@ def add_entreprise(): db.session.add(correspondant) if current_user.has_permission(Permission.RelationsEntreprisesValidate, None): entreprise.visible = True - nom_entreprise = f"{entreprise.nom}" + lien_entreprise = f"{entreprise.nom}" log = EntrepriseHistorique( authenticated_user=current_user.user_name, - text=f"{nom_entreprise} - Création de la fiche entreprise ({entreprise.nom})", + text=f"{lien_entreprise} - Création de la fiche entreprise ({entreprise.nom})", entreprise_id=entreprise.id, ) db.session.add(log) @@ -404,50 +404,49 @@ def edit_entreprise(id): ) form = EntrepriseModificationForm(siret=entreprise.siret) if form.validate_on_submit(): - nom_entreprise = f"{form.nom.data.strip()}" + lien_entreprise = f"{form.nom.data.strip()}" + logs_text = [] if entreprise.nom != form.nom.data.strip(): - log = EntrepriseHistorique( - authenticated_user=current_user.user_name, - entreprise_id=entreprise.id, - text=f"{nom_entreprise} - Modification du nom (ancien nom: {entreprise.nom})", + logs_text.append( + f"{lien_entreprise} - Modification du nom (ancien nom: {entreprise.nom})" ) entreprise.nom = form.nom.data.strip() - db.session.add(log) + if entreprise.adresse != form.adresse.data.strip(): - log = EntrepriseHistorique( - authenticated_user=current_user.user_name, - entreprise_id=entreprise.id, - text=f"{nom_entreprise} - Modification de l'adresse (ancienne adresse: {entreprise.adresse})", + logs_text.append( + f"{lien_entreprise} - Modification de l'adresse (ancienne adresse: {entreprise.adresse})" ) entreprise.adresse = form.adresse.data.strip() - db.session.add(log) + if entreprise.codepostal != form.codepostal.data.strip(): - log = EntrepriseHistorique( - authenticated_user=current_user.user_name, - entreprise_id=entreprise.id, - text=f"{nom_entreprise} - Modification du code postal (ancien code postal: {entreprise.codepostal})", + logs_text.append( + f"{lien_entreprise} - Modification du code postal (ancien code postal: {entreprise.codepostal})" ) entreprise.codepostal = form.codepostal.data.strip() - db.session.add(log) + if entreprise.ville != form.ville.data.strip(): - log = EntrepriseHistorique( - authenticated_user=current_user.user_name, - entreprise_id=entreprise.id, - text=f"{nom_entreprise} - Modification de la ville (ancienne ville: {entreprise.ville})", + logs_text.append( + f"{lien_entreprise} - Modification de la ville (ancienne ville: {entreprise.ville})" ) entreprise.ville = form.ville.data.strip() - db.session.add(log) + if entreprise.pays != form.pays.data.strip() or not form.pays.data.strip(): - log = EntrepriseHistorique( - authenticated_user=current_user.user_name, - entreprise_id=entreprise.id, - text=f"{nom_entreprise} - Modification du pays (ancien pays: {entreprise.pays})", + logs_text.append( + f"{lien_entreprise} - Modification du pays (ancien pays: {entreprise.pays})" ) entreprise.pays = ( form.pays.data.strip() if form.pays.data.strip() else "FRANCE" ) - db.session.add(log) + entreprise.association = form.association.data + for log_text in logs_text: + db.session.add( + EntrepriseHistorique( + authenticated_user=current_user.user_name, + entreprise_id=entreprise.id, + text=log_text, + ) + ) db.session.commit() flash("L'entreprise a été modifié.") return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) @@ -865,6 +864,7 @@ def add_site(id): ) form = SiteCreationForm(hidden_entreprise_id=id) if form.validate_on_submit(): + lien_entreprise = f"{entreprise.nom} - {form.nom.data.strip()}" site = EntrepriseSite( entreprise_id=entreprise.id, nom=form.nom.data.strip(), @@ -875,6 +875,16 @@ def add_site(id): ) db.session.add(site) db.session.commit() + db.session.refresh(site) + log = EntrepriseHistorique( + authenticated_user=current_user.user_name, + entreprise_id=entreprise.id, + object="site", + object_id=site.id, + text=f"{lien_entreprise} - Création d'un site", + ) + db.session.add(log) + db.session.commit() flash("Le site a été créé et ajouté à la fiche entreprise") return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) return render_template( @@ -1157,7 +1167,7 @@ def contacts(id): "entreprises/contacts.html", title="Liste des contacts", contacts=contacts, - entreprise_id=id, + entreprise=entreprise, ) @@ -1602,3 +1612,8 @@ def preferences(): title="Préférences", form=form, ) + + +@bp.errorhandler(404) +def not_found_error_handler(e): + return render_template("entreprises/error.html", title="Erreur", e=e) diff --git a/app/static/css/entreprises.css b/app/static/css/entreprises.css index ce3a4ccda..947f90fbb 100644 --- a/app/static/css/entreprises.css +++ b/app/static/css/entreprises.css @@ -1,37 +1,85 @@ -.nav-entreprise { +/* nav */ + +.nav_entreprise { text-align: left; } -.nav-entreprise ul { +.nav_entreprise > ul { padding: 0; } -.nav-entreprise li{ +.nav_entreprise_item { list-style: none; display: inline-block; padding: 10px; + margin: 2px; border: 2px black solid; border-radius: 10px; } -.nav-entreprise li:hover{ +.nav_entreprise_item:hover { background-color: rgb(212, 212, 212); } -.nav-entreprise>ul>li>a { +.nav_entreprise_link { text-decoration: none; color: black; padding: 15px; } -.nav-entreprise>ul>li>a:hover { +.nav_entreprise_link:hover { text-decoration: underline; + color: black; +} + +.nav_entreprise_link-active { + font-weight: bold; +} + +/* breadcrumbs */ + +.breadcrumbs { + padding: 0; +} + +.breadcrumbs_item { + display: inline-block; +} + +.breadcrumbs_item:not(:last-of-type)::after { + content: '\203a'; + margin: 0 5px; + color: #777; +} + +.breadcrumbs_link { + text-decoration: none; + color: #777; +} + +.breadcrumbs_link:hover { + text-decoration: underline; + color: #333; +} + +.breadcrumbs_link-active { + color: #333; + font-weight: bold; +} + +/* form error */ + +.title-form-error { + font-weight: bold; + color: #a94442; } .form-error { color: #a94442; } +/* entreprises */ + .boutons .btn { margin-top: 5px; margin-bottom: 5px; @@ -90,7 +138,7 @@ flex: 1 0 0; } -.taxe-apprentissage{ +.taxe-apprentissage { overflow-y: scroll; height: 100px; } @@ -138,38 +186,4 @@ #form-entreprise-filter > label { margin-right: 20px; -} - -.title-form-error { - font-weight: bold; - color: #a94442; -} - -.breadcrumbs { - padding: 0; -} - -.breadcrumbs_item { - display: inline-block; -} - -.breadcrumbs_item:not(:last-of-type)::after { - content: '\203a'; - margin: 0 5px; - color: #777; -} - -.breadcrumbs_link { - text-decoration: none; - color: #777; -} - -.breadcrumbs_link:hover { - text-decoration: underline; - color: #333; -} - -.breadcrumbs_link-active { - color: #333; - font-weight: bold; } \ No newline at end of file diff --git a/app/templates/entreprises/contacts.html b/app/templates/entreprises/contacts.html index 70ad459e0..df2cbc472 100644 --- a/app/templates/entreprises/contacts.html +++ b/app/templates/entreprises/contacts.html @@ -15,7 +15,7 @@ Entreprises