export liste contacts

This commit is contained in:
Arthur ZHU 2021-12-27 11:48:58 +01:00
parent 2a6d63cf03
commit 5684f57ca5
6 changed files with 83 additions and 38 deletions

View File

@ -1,8 +1,7 @@
from flask import flash
from markupsafe import Markup
from flask.app import Flask
import requests, re
from flask_wtf import FlaskForm
from markupsafe import Markup
import requests, re
from wtforms import StringField, SubmitField, TextAreaField, SelectField, FileField, HiddenField
from wtforms.fields.html5 import EmailField, DateField
from wtforms.validators import ValidationError, DataRequired, Email
@ -20,13 +19,15 @@ class EntrepriseCreationForm(FlaskForm):
adresse = StringField("Adresse de l'entreprise", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
codepostal = StringField("Code postal de l'entreprise", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
ville = StringField("Ville de l'entreprise", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
pays = StringField("Pays de l'entreprise", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
pays = StringField("Pays de l'entreprise", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)], render_kw={"style": "margin-bottom: 50px;"})
nom_contact = StringField("Nom du contact", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
prenom_contact = StringField("Prénom du contact", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
telephone = StringField("Téléphone du contact", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
mail = EmailField("Mail du contact", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE), Email(message="Adresse e-mail invalide")])
submit = SubmitField("Envoyer")
poste = StringField("Poste du contact", validators=[])
service = StringField("Service du contact", validators=[])
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
def validate_siret(self, siret):
siret = siret.data.strip()
@ -47,7 +48,7 @@ class EntrepriseModificationForm(FlaskForm):
codepostal = StringField("Code postal", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
ville = StringField("Ville", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
pays = StringField("Pays", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
submit = SubmitField("Modifier")
submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"})
class OffreCreationForm(FlaskForm):
intitule = StringField("Intitulé", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
@ -56,7 +57,7 @@ class OffreCreationForm(FlaskForm):
missions = TextAreaField("Missions", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
duree = StringField("Durée", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
ficher = FileField("Fichier", validators=[])
submit = SubmitField("Envoyer")
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
class OffreModificationForm(FlaskForm):
intitule = StringField("Intitulé", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
@ -64,7 +65,7 @@ class OffreModificationForm(FlaskForm):
type_offre = SelectField("Type de l'offre", choices=[('Stage'), ('Alternance')], validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
missions = TextAreaField("Missions", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
duree = StringField("Durée", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
submit = SubmitField("Modifier")
submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"})
class ContactCreationForm(FlaskForm):
hidden_entreprise_id = HiddenField()
@ -74,7 +75,7 @@ class ContactCreationForm(FlaskForm):
mail = EmailField("Mail", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE), Email(message="Adresse e-mail invalide")])
poste = StringField("Poste", validators=[])
service = StringField("Service", validators=[])
submit = SubmitField("Envoyer")
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
def validate(self):
rv = FlaskForm.validate(self)
@ -99,14 +100,16 @@ class ContactModificationForm(FlaskForm):
prenom = StringField("Prénom", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
telephone = StringField("Téléphone", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
mail = EmailField("Mail", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE), Email(message="Adresse e-mail invalide")])
submit = SubmitField("Modifier")
poste = StringField("Poste", validators=[])
service = StringField("Service", validators=[])
submit = SubmitField("Modifier", render_kw={"style": "margin-bottom: 10px;"})
class HistoriqueCreationForm(FlaskForm):
etudiant = StringField("Étudiant", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)], render_kw={"placeholder": "Tapez le nom de l'étudiant puis selectionnez"})
type_offre = SelectField("Type de l'offre", choices=[('Stage'), ('Alternance')], validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
date_debut = DateField("Date début", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
date_fin = DateField("Date fin", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
submit = SubmitField("Envoyer")
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
def validate(self):
rv = FlaskForm.validate(self)
@ -128,7 +131,7 @@ class HistoriqueCreationForm(FlaskForm):
class EnvoiOffreForm(FlaskForm):
responsable = StringField("Responsable de formation", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
submit = SubmitField("Envoyer")
submit = SubmitField("Envoyer", render_kw={"style": "margin-bottom: 10px;"})
def validate_responsable(self, responsable):
responsable_data = responsable.data.upper().strip()
@ -138,4 +141,4 @@ class EnvoiOffreForm(FlaskForm):
raise ValidationError("Champ incorrect (selectionnez dans la liste)")
class SuppressionConfirmationForm(FlaskForm):
submit = SubmitField("Supprimer")
submit = SubmitField("Supprimer", render_kw={"style": "margin-bottom: 10px;"})

View File

@ -12,19 +12,20 @@ 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):
def to_dict_export(self):
return {
"siret": self.siret,
"nom": self.nom,
"adresse": self.adresse,
"codepostal": self.codepostal,
"ville": self.ville,
"pays": self.pays
}
class EntrepriseContact(db.Model):
__tablename__ = "entreprise_contact"
id = db.Column(db.Integer, primary_key=True)
entreprise_id = db.Column(db.Integer, db.ForeignKey("entreprises.id"))
entreprise_id = db.Column(db.Integer, db.ForeignKey("entreprises.id", ondelete="cascade"))
nom = db.Column(db.Text)
prenom = db.Column(db.Text)
telephone = db.Column(db.Text)
@ -32,10 +33,20 @@ class EntrepriseContact(db.Model):
poste = db.Column(db.Text)
service = db.Column(db.Text)
def to_dict_export(self):
return {
"nom": self.nom,
"prenom": self.prenom,
"telephone": self.telephone,
"mail": self.mail,
"poste": self.poste,
"service": self.service
}
class EntrepriseOffre(db.Model):
__tablename__ = "entreprise_offre"
id = db.Column(db.Integer, primary_key=True)
entreprise_id = db.Column(db.Integer, db.ForeignKey("entreprises.id"))
entreprise_id = db.Column(db.Integer, db.ForeignKey("entreprises.id", ondelete="cascade"))
date_ajout = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
intitule = db.Column(db.Text)
description = db.Column(db.Text)

View File

@ -1,9 +1,9 @@
from flask import render_template, redirect, url_for, request, flash, send_file
from flask import render_template, redirect, url_for, request, flash, send_file, abort
from flask.json import jsonify
from flask_login import current_user
from app.decorators import permission_required
from app.scodoc.sco_permissions import Permission
from app.entreprises import LOGS_LEN
from app.entreprises.forms import (
EntrepriseCreationForm,
@ -30,9 +30,11 @@ 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.sco_permissions import Permission
from app.scodoc import sco_etud, sco_excel
import app.scodoc.sco_utils as scu
from app import db
from sqlalchemy import text
@bp.route("/", methods=["GET"])
@ -85,7 +87,9 @@ def add_entreprise():
nom=form.nom_contact.data.strip(),
prenom=form.prenom_contact.data.strip(),
telephone=form.telephone.data.strip(),
mail=form.mail.data.strip()
mail=form.mail.data.strip(),
poste=form.poste.data.strip(),
service=form.service.data.strip()
)
db.session.add(contact)
nom_entreprise = f"<a href=/ScoDoc/entreprises/fiche_entreprise/{entreprise.id}>{entreprise.nom}</a>"
@ -409,6 +413,7 @@ def json_responsables():
@bp.route("/export_entreprises")
def export_entreprises():
entreprises = Entreprise.query.all()
if entreprises:
keys=[
"siret",
"nom",
@ -418,8 +423,31 @@ def export_entreprises():
"pays"
]
titles = keys[:]
L = [[entreprise.to_dict().get(k, "") for k in keys] for entreprise in entreprises]
L = [[entreprise.to_dict_export().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)
else:
abort(404)
@bp.route("/export_contacts")
def export_contacts():
contacts = EntrepriseContact.query.all()
if contacts:
keys=[
"nom",
"prenom",
"telephone",
"mail",
"poste",
"service"
]
titles = keys[:]
L = [[contact.to_dict_export().get(k, "") for k in keys] for contact in contacts]
title = "contacts"
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)
else:
abort(404)

View File

@ -33,10 +33,14 @@
</tr>
{% endfor %}
</table>
<br>
{% else %}
<div>Aucun contact présent dans la base</div>
</div>
{% endif %}
<div>
{% if contacts %}
<a class="btn btn-default" href="{{ url_for('entreprises.export_contacts') }}">Exporter la liste des contacts</a>
{% endif %}
</div>
</div>
{% endblock %}

View File

@ -47,7 +47,6 @@
</tr>
{% endfor %}
</table>
<br>
{% else %}
<div>Aucune entreprise présent dans la base</div>
<br>

View File

@ -36,7 +36,7 @@ def upgrade():
sa.Column('date_fin', sa.Date(), nullable=True),
sa.Column('formation_text', sa.Text(), nullable=True),
sa.Column('formation_scodoc', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['entreprise_id'], ['entreprises.id'], ),
sa.ForeignKeyConstraint(['entreprise_id'], ['entreprises.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
@ -49,7 +49,7 @@ def upgrade():
sa.Column('type_offre', sa.Text(), nullable=True),
sa.Column('missions', sa.Text(), nullable=True),
sa.Column('duree', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['entreprise_id'], ['entreprises.id'], ),
sa.ForeignKeyConstraint(['entreprise_id'], ['entreprises.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)