forked from ScoDoc/DocScoDoc
export liste entreprises
This commit is contained in:
parent
178016b682
commit
2a6d63cf03
@ -12,6 +12,15 @@ class Entreprise(db.Model):
|
||||
contacts = db.relationship('EntrepriseContact', 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):
|
||||
__tablename__ = "entreprise_contact"
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
@ -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_login import current_user
|
||||
from app.decorators import permission_required
|
||||
from app.entreprises import LOGS_LEN
|
||||
|
||||
from app.scodoc.sco_permissions import Permission
|
||||
from app.entreprises import LOGS_LEN
|
||||
from app.entreprises.forms import (
|
||||
EntrepriseCreationForm,
|
||||
EntrepriseModificationForm,
|
||||
@ -30,7 +31,8 @@ from app.models import (
|
||||
from app.auth.models import User
|
||||
from app.scodoc.sco_find_etud import search_etud_by_name
|
||||
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
|
||||
|
||||
@bp.route("/", methods=["GET"])
|
||||
@ -403,3 +405,21 @@ def json_responsables():
|
||||
list.append(content)
|
||||
content = {}
|
||||
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)
|
@ -53,6 +53,11 @@
|
||||
<br>
|
||||
</div>
|
||||
{% 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>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user