ajout page contacts

This commit is contained in:
Arthur ZHU 2021-12-23 23:21:47 +01:00
parent 93d026d2ac
commit d740244d25
5 changed files with 92 additions and 43 deletions

View File

@ -32,12 +32,30 @@ from app import db
from app.scodoc import sco_etud from app.scodoc import sco_etud
from sqlalchemy import text from sqlalchemy import text
@bp.route("/", methods=["GET", "POST"]) @bp.route("/", methods=["GET"])
def index(): def index():
entreprises = Entreprise.query.all() entreprises = Entreprise.query.all()
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all() logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
return render_template("entreprises/entreprises.html", title=("Entreprises"), entreprises=entreprises, logs=logs) return render_template("entreprises/entreprises.html", title=("Entreprises"), entreprises=entreprises, logs=logs)
@bp.route("/contacts", methods=["GET"])
def contacts():
contacts = db.session.query(EntrepriseContact, Entreprise).\
join(Entreprise, EntrepriseContact.entreprise_id == Entreprise.id).all()
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
return render_template("entreprises/contacts.html", title=("Contacts"), contacts=contacts, logs=logs)
@bp.route("/fiche_entreprise/<id>", methods=["GET"])
def fiche_entreprise(id):
entreprise = Entreprise.query.filter_by(id=id).first_or_404()
offres = entreprise.offres
contacts = entreprise.contacts
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).filter_by(object=id).limit(LOGS_LEN).all()
historique = db.session.query(EntrepriseHistory, Identite).order_by(EntrepriseHistory.date_debut.desc()).\
filter_by(entreprise_id=id).\
join(Identite, Identite.id == EntrepriseHistory.etudid).all()
return render_template("entreprises/fiche_entreprise.html", title=("Fiche entreprise"), entreprise=entreprise, contacts=contacts, offres=offres, logs=logs, historique=historique)
@bp.route("/add_entreprise", methods=["GET", "POST"]) @bp.route("/add_entreprise", methods=["GET", "POST"])
def add_entreprise(): def add_entreprise():
form = EntrepriseCreationForm() form = EntrepriseCreationForm()
@ -147,17 +165,6 @@ def delete_entreprise(id):
return redirect(url_for("entreprises.index")) return redirect(url_for("entreprises.index"))
return render_template("entreprises/delete_confirmation.html", title=("Supression entreprise"), form=form) return render_template("entreprises/delete_confirmation.html", title=("Supression entreprise"), form=form)
@bp.route("/fiche_entreprise/<id>", methods=["GET", "POST"])
def fiche_entreprise(id):
entreprise = Entreprise.query.filter_by(id=id).first_or_404()
offres = entreprise.offres
contacts = entreprise.contacts
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).filter_by(object=id).limit(LOGS_LEN).all()
historique = db.session.query(EntrepriseHistory, Identite).order_by(EntrepriseHistory.date_debut.desc()).\
filter_by(entreprise_id=id).\
join(Identite, Identite.id == EntrepriseHistory.etudid).all()
return render_template("entreprises/fiche_entreprise.html", title=("Fiche entreprise"), entreprise=entreprise, contacts=contacts, offres=offres, logs=logs, historique=historique)
@bp.route("/add_offre/<id>", methods=["GET", "POST"]) @bp.route("/add_offre/<id>", methods=["GET", "POST"])
def add_offre(id): def add_offre(id):
entreprise = Entreprise.query.filter_by(id=id).first_or_404() entreprise = Entreprise.query.filter_by(id=id).first_or_404()
@ -326,6 +333,13 @@ def add_historique(id):
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id)) return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
return render_template("entreprises/form.html", title=("Ajout historique"), form=form) return render_template("entreprises/form.html", title=("Ajout historique"), form=form)
@bp.route("/envoyer_offre/<id>", methods=["GET", "POST"])
def envoyer_offre(id):
form = EnvoiOffreForm()
if form.validate_on_submit():
print("tmp") # faire l'envoie du mail
return render_template("entreprises/form.html", title=("Envoyer une offre"), form=form)
@bp.route("/etudiants") @bp.route("/etudiants")
def json_etudiants(): def json_etudiants():
term = request.args.get('term').strip() term = request.args.get('term').strip()
@ -349,13 +363,6 @@ def json_etudiants():
content = {} content = {}
return jsonify(results=list) return jsonify(results=list)
@bp.route("/envoyer_offre/<id>", methods=["GET", "POST"])
def envoyer_offre(id):
form = EnvoiOffreForm()
if form.validate_on_submit():
print("tmp") # faire l'envoie du mail
return render_template("entreprises/form.html", title=("Envoyer une offre"), form=form)
@bp.route("/responsables") @bp.route("/responsables")
def json_responsables(): def json_responsables():
term = request.args.get('term').strip() term = request.args.get('term').strip()

View File

@ -0,0 +1,43 @@
{% extends 'base.html' %}
{% block app_content %}
{% if logs %}
<div class="container">
<h3>Dernières opérations</h3>
<ul>
{% for log in logs %}
<li><span style="margin-right: 10px;">{{ log.date.strftime('%d %b %Hh%M') }}</span><span>{{ log.text|safe }} par {{ log.authenticated_user|get_nomcomplet }}</span></li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="container">
<h1>Liste des contacts</h1>
{% if contacts %}
<div class="table-responsive">
<table class="table table-bordered table-hover">
<tr>
<th>Nom</th>
<th>Prenom</th>
<th>Telephone</th>
<th>Mail</th>
<th>Entreprise</th>
</tr>
{% for contact in contacts %}
<tr class="table-row active">
<th>{{ contact[0].nom }}</th>
<th>{{ contact[0].prenom }}</th>
<th>{{ contact[0].telephone }}</th>
<th>{{ contact[0].mail }}</th>
<th><a href="{{ url_for('entreprises.fiche_entreprise', id=contact[1].id) }}">{{ contact[1].nom }}</a></th>
</tr>
{% endfor %}
</table>
<br>
{% else %}
<div>Aucun contact présent dans la base</div>
<br>
</div>
{% endif %}
</div>
{% endblock %}

View File

@ -1,13 +1,6 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block app_content %} {% block app_content %}
<!-- <style>
#entreprises-table {
table-layout: fixed;
width: 100%;
word-wrap: break-word;
}
</style> -->
{% if logs %} {% if logs %}
<div class="container"> <div class="container">
<h3>Dernières opérations</h3> <h3>Dernières opérations</h3>
@ -22,7 +15,7 @@
<h1>Liste des entreprises</h1> <h1>Liste des entreprises</h1>
{% if entreprises %} {% if entreprises %}
<div class="table-responsive"> <div class="table-responsive">
<table id="entreprises-table" class="table table-bordered table-hover"> <table class="table table-bordered table-hover">
<tr> <tr>
<th>SIRET</th> <th>SIRET</th>
<th>Nom</th> <th>Nom</th>
@ -35,7 +28,7 @@
{% for entreprise in entreprises %} {% for entreprise in entreprises %}
<tr class="table-row active"> <tr class="table-row active">
<th><a href="{{ url_for('entreprises.fiche_entreprise', id=entreprise.id) }}">{{ entreprise.siret }}</a></th> <th><a href="{{ url_for('entreprises.fiche_entreprise', id=entreprise.id) }}">{{ entreprise.siret }}</a></th>
<th class="entreprise-nom">{{ entreprise.nom }}</th> <th>{{ entreprise.nom }}</th>
<th>{{ entreprise.adresse }}</th> <th>{{ entreprise.adresse }}</th>
<th>{{ entreprise.codepostal }}</th> <th>{{ entreprise.codepostal }}</th>
<th>{{ entreprise.ville }}</th> <th>{{ entreprise.ville }}</th>

View File

@ -21,7 +21,9 @@
{% for data in historique %} {% for data in historique %}
<li> <li>
<span style="margin-right: 10px;">{{ data[0].date_debut.strftime('%d/%m/%Y') }} - {{ data[0].date_fin.strftime('%d/%m/%Y') }}</span> <span style="margin-right: 10px;">{{ data[0].date_debut.strftime('%d/%m/%Y') }} - {{ data[0].date_fin.strftime('%d/%m/%Y') }}</span>
<span style="margin-right: 10px;">{{ data[0].type_offre }} réalisé par {{ data[1].nom|format_nom }} {{ data[1].prenom|format_prenom }}</span> <span style="margin-right: 10px;">
{{ data[0].type_offre }} réalisé par {{ data[1].nom|format_nom }} {{ data[1].prenom|format_prenom }} en {{ data[0].formation_text }}
</span>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>

View File

@ -47,25 +47,29 @@
if(response.ok) if(response.ok)
return response.json() return response.json()
else { else {
document.getElementById("nom_entreprise").value = '' emptyForm()
document.getElementById("adresse").value = ''
document.getElementById("codepostal").value = ''
document.getElementById("ville").value = ''
document.getElementById("pays").value = ''
throw new Error("404")
} }
}) })
.then(function(response) { .then(response => fillForm(response))
data = JSON.parse(JSON.stringify(response))
document.getElementById("nom_entreprise").value = data.etablissement.l1_normalisee
document.getElementById("adresse").value = data.etablissement.l4_normalisee
document.getElementById("codepostal").value = data.etablissement.code_postal
document.getElementById("ville").value = data.etablissement.libelle_commune
document.getElementById("pays").value = 'France'
})
.catch(err => err) .catch(err => err)
} }
} }
function fillForm(response) {
document.getElementById("nom_entreprise").value = response.etablissement.l1_normalisee
document.getElementById("adresse").value = response.etablissement.l4_normalisee
document.getElementById("codepostal").value = response.etablissement.code_postal
document.getElementById("ville").value = response.etablissement.libelle_commune
document.getElementById("pays").value = 'FRANCE'
}
function emptyForm() {
document.getElementById("nom_entreprise").value = ''
document.getElementById("adresse").value = ''
document.getElementById("codepostal").value = ''
document.getElementById("ville").value = ''
document.getElementById("pays").value = ''
}
} }
</script> </script>
{% endblock %} {% endblock %}