debut import excel entreprises

This commit is contained in:
Arthur ZHU 2022-02-07 18:39:32 +01:00
parent f9cad4fd01
commit ab7a68c74b
5 changed files with 78 additions and 3 deletions

View File

@ -338,7 +338,7 @@ class AjoutFichierForm(FlaskForm):
FileAllowed(["pdf", "docx"], "Fichier .pdf ou .docx uniquement"),
],
)
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
submit = SubmitField("Ajouter", render_kw={"style": "margin-bottom: 10px;"})
class SuppressionConfirmationForm(FlaskForm):
@ -347,3 +347,14 @@ class SuppressionConfirmationForm(FlaskForm):
class ValidationConfirmationForm(FlaskForm):
submit = SubmitField("Valider", render_kw={"style": "margin-bottom: 10px;"})
class ImportEntreprisesForm(FlaskForm):
fichier = FileField(
"Fichier",
validators=[
FileRequired(message=CHAMP_REQUIS),
FileAllowed(["xlsx"], "Fichier .xlsx uniquement"),
],
)
submit = SubmitField("Importer", render_kw={"style": "margin-bottom: 10px;"})

View File

@ -23,6 +23,7 @@ from app.entreprises.forms import (
EnvoiOffreForm,
AjoutFichierForm,
ValidationConfirmationForm,
ImportEntreprisesForm,
)
from app.entreprises import bp
from app.entreprises.models import (
@ -809,6 +810,47 @@ def export_entreprises():
abort(404)
@bp.route("/get_import_entreprises_file_sample")
@permission_required(Permission.RelationsEntreprisesExport)
def get_import_entreprises_file_sample():
keys = [
"siret",
"nom_entreprise",
"adresse",
"ville",
"codepostal",
"pays",
"nom_contact",
"prenom_contact",
"telephone",
"mail",
"poste",
"service",
]
titles = keys[:]
title = "ImportEntreprises"
xlsx = sco_excel.excel_simple_table(titles=titles, sheet_name="Entreprises")
filename = title
return scu.send_file(xlsx, filename, scu.XLSX_SUFFIX, scu.XLSX_MIMETYPE)
@bp.route("/import_entreprises", methods=["GET", "POST"])
@permission_required(Permission.RelationsEntreprisesExport)
def import_entreprises():
form = ImportEntreprisesForm()
if form.validate_on_submit():
path = os.path.join(Config.SCODOC_VAR_DIR, "tmp")
file = form.fichier.data
filename = secure_filename(file.filename)
file.save(os.path.join(path, filename))
# print(sco_excel.excel_file_to_list(filename))
return render_template(
"entreprises/import_entreprises.html",
title=("Importation entreprises"),
form=form,
)
@bp.route("/export_contacts")
@permission_required(Permission.RelationsEntreprisesExport)
def export_contacts():

View File

@ -19,6 +19,9 @@
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
<a class="btn btn-default" href="{{ url_for('entreprises.add_entreprise') }}">Ajouter une entreprise</a>
{% endif %}
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesExport, None) %}
<a class="btn btn-default" href="{{ url_for('entreprises.import_entreprises') }}">Importer des entreprises</a>
{% endif %}
{% if entreprises %}
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesExport, None) %}
<a class="btn btn-default" href="{{ url_for('entreprises.export_entreprises') }}">Exporter la liste des entreprises</a>

View File

@ -4,8 +4,6 @@
{% block styles %}
{{super()}}
<link type="text/css" rel="stylesheet" href="/ScoDoc/static/css/autosuggest_inquisitor.css" />
<script src="/ScoDoc/static/libjs/AutoSuggest.js"></script>
{% endblock %}
{% block app_content %}

View File

@ -0,0 +1,21 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block styles %}
{{super()}}
{% endblock %}
{% block app_content %}
<h1>{{ title }}</h1>
<br>
<div>
<a href="{{ url_for('entreprises.get_import_entreprises_file_sample') }}">Obtenir la feuille excel à remplir</a>
</div>
<br>
<div class="row">
<div class="col-md-4">
{{ wtf.quick_form(form, novalidate=True) }}
</div>
</div>
{% endblock %}