export liste entreprises

This commit is contained in:
Arthur ZHU 2021-12-24 18:10:19 +01:00
parent 178016b682
commit 2a6d63cf03
3 changed files with 39 additions and 5 deletions

View File

@ -12,6 +12,15 @@ class Entreprise(db.Model):
contacts = db.relationship('EntrepriseContact', backref='entreprise', lazy='dynamic', cascade="all, delete-orphan") contacts = db.relationship('EntrepriseContact', backref='entreprise', lazy='dynamic', cascade="all, delete-orphan")
offres = db.relationship('EntrepriseOffre', backref='entreprise', lazy='dynamic', cascade="all, delete-orphan") offres = db.relationship('EntrepriseOffre', backref='entreprise', lazy='dynamic', cascade="all, delete-orphan")
def to_dict(self):
return {
"siret": self.siret,
"nom": self.nom,
"adresse": self.adresse,
"codepostal": self.codepostal,
"pays": self.pays
}
class EntrepriseContact(db.Model): class EntrepriseContact(db.Model):
__tablename__ = "entreprise_contact" __tablename__ = "entreprise_contact"
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)

View File

@ -1,9 +1,10 @@
from flask import render_template, redirect, url_for, request, flash from flask import render_template, redirect, url_for, request, flash, send_file
from flask.json import jsonify from flask.json import jsonify
from flask_login import current_user from flask_login import current_user
from app.decorators import permission_required from app.decorators import permission_required
from app.entreprises import LOGS_LEN
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
from app.entreprises import LOGS_LEN
from app.entreprises.forms import ( from app.entreprises.forms import (
EntrepriseCreationForm, EntrepriseCreationForm,
EntrepriseModificationForm, EntrepriseModificationForm,
@ -30,7 +31,8 @@ from app.models import (
from app.auth.models import User from app.auth.models import User
from app.scodoc.sco_find_etud import search_etud_by_name from app.scodoc.sco_find_etud import search_etud_by_name
from app import db from app import db
from app.scodoc import sco_etud from app.scodoc import sco_etud, sco_excel
import app.scodoc.sco_utils as scu
from sqlalchemy import text from sqlalchemy import text
@bp.route("/", methods=["GET"]) @bp.route("/", methods=["GET"])
@ -403,3 +405,21 @@ def json_responsables():
list.append(content) list.append(content)
content = {} content = {}
return jsonify(results=list) return jsonify(results=list)
@bp.route("/export_entreprises")
def export_entreprises():
entreprises = Entreprise.query.all()
keys=[
"siret",
"nom",
"adresse",
"ville",
"codepostal",
"pays"
]
titles = keys[:]
L = [[entreprise.to_dict().get(k, "") for k in keys] for entreprise in entreprises]
title = "entreprises"
xlsx = sco_excel.excel_simple_table(titles=titles, lines=L, sheet_name=title)
filename = title
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)

View File

@ -53,6 +53,11 @@
<br> <br>
</div> </div>
{% endif %} {% endif %}
<a class="btn btn-default" href="{{ url_for('entreprises.add_entreprise') }}">Ajouter une entreprise</a> <div>
<a class="btn btn-default" href="{{ url_for('entreprises.add_entreprise') }}">Ajouter une entreprise</a>
{% if entreprises %}
<a class="btn btn-default" href="{{ url_for('entreprises.export_entreprises') }}">Exporter la liste des entreprises</a>
{% endif %}
</div>
</div> </div>
{% endblock %} {% endblock %}