Compare commits

...

6 Commits

7 changed files with 118 additions and 17 deletions

View File

@ -16,15 +16,32 @@ def departements():
"""
Retourne la liste des ids de départements visibles
Exemple de résultat : [2, 5, 8, 1, 4, 18]
Exemple de résultat :
[
{
"id": 1,
"acronym": "TAPI",
"description": null,
"visible": true,
"date_creation": "Fri, 15 Apr 2022 12:19:28 GMT"
},
{
"id": 2,
"acronym": "MMI",
"description": null,
"visible": false,
"date_creation": "Fri, 18 Apr 2022 11:20:8 GMT"
},
...
]
"""
# Récupération de tous les départements
depts = models.Departement.query.filter_by(visible=True)
depts = models.Departement.query.all()
# Mise en place de la liste avec tous les ids de départements
depts_ids = [d.id for d in depts]
# Mise en place de la liste avec tous les départements
data = [d.to_dict() for d in depts]
return jsonify(depts_ids)
return jsonify(data)
@bp.route("/departements/<string:dept>/etudiants/liste", methods=["GET"])

View File

@ -50,6 +50,7 @@ from app.entreprises.models import (
Entreprise,
EntrepriseCorrespondant,
EntreprisePreferences,
EntrepriseSite,
)
from app.models import Identite, Departement
from app.auth.models import User
@ -171,6 +172,7 @@ class EntrepriseModificationForm(FlaskForm):
class SiteCreationForm(FlaskForm):
hidden_entreprise_id = HiddenField()
nom = _build_string_field("Nom du site (*)")
adresse = _build_string_field("Adresse (*)")
codepostal = _build_string_field("Code postal (*)")
@ -178,6 +180,49 @@ class SiteCreationForm(FlaskForm):
pays = _build_string_field("Pays", required=False)
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
def validate(self):
validate = True
if not FlaskForm.validate(self):
validate = False
site = EntrepriseSite.query.filter_by(
entreprise_id=self.hidden_entreprise_id.data, nom=self.nom.data
).first()
if site is not None:
self.nom.errors.append("Ce site existe déjà (même nom)")
validate = False
return validate
class SiteModificationForm(FlaskForm):
hidden_entreprise_id = HiddenField()
hidden_site_id = HiddenField()
nom = _build_string_field("Nom du site (*)")
adresse = _build_string_field("Adresse (*)")
codepostal = _build_string_field("Code postal (*)")
ville = _build_string_field("Ville (*)")
pays = _build_string_field("Pays", required=False)
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
def validate(self):
validate = True
if not FlaskForm.validate(self):
validate = False
site = EntrepriseSite.query.filter(
EntrepriseSite.entreprise_id == self.hidden_entreprise_id.data,
EntrepriseSite.id != self.hidden_site_id.data,
EntrepriseSite.nom == self.nom.data,
).first()
if site is not None:
self.nom.errors.append("Ce site existe déjà (même nom)")
validate = False
return validate
class MultiCheckboxField(SelectMultipleField):
widget = ListWidget(prefix_label=False)

View File

@ -17,6 +17,7 @@ from app.entreprises.forms import (
EntrepriseCreationForm,
EntrepriseModificationForm,
SiteCreationForm,
SiteModificationForm,
SuppressionConfirmationForm,
OffreCreationForm,
OffreModificationForm,
@ -110,8 +111,9 @@ def correspondants():
Permet d'afficher une page avec la liste des correspondants des entreprises visibles et une liste des dernières opérations
"""
correspondants = (
db.session.query(EntrepriseCorrespondant, Entreprise)
.join(Entreprise, EntrepriseCorrespondant.entreprise_id == Entreprise.id)
db.session.query(EntrepriseCorrespondant, EntrepriseSite)
.join(EntrepriseSite, EntrepriseCorrespondant.site_id == EntrepriseSite.id)
.join(Entreprise, EntrepriseSite.entreprise_id == Entreprise.id)
.filter_by(visible=True, active=True)
)
logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).limit(LOGS_LEN).all()
@ -700,7 +702,7 @@ def add_site(id):
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
description=f"entreprise {id} inconnue"
)
form = SiteCreationForm()
form = SiteCreationForm(hidden_entreprise_id=id)
if form.validate_on_submit():
site = EntrepriseSite(
entreprise_id=entreprise.id,
@ -721,6 +723,38 @@ def add_site(id):
)
@bp.route(
"/fiche_entreprise/<int:id_entreprise>/edit_site/<int:id_site>",
methods=["GET", "POST"],
)
def edit_site(id_entreprise, id_site):
site = EntrepriseSite.query.filter_by(
id=id_site, entreprise_id=id_entreprise
).first_or_404(description=f"site {id_site} inconnu")
form = SiteModificationForm(
hidden_entreprise_id=id_entreprise, hidden_site_id=id_site
)
if form.validate_on_submit():
site.nom = form.nom.data.strip()
site.adresse = form.adresse.data.strip()
site.codepostal = form.codepostal.data.strip()
site.ville = form.ville.data.strip()
site.pays = (form.pays.data.strip() if form.pays.data.strip() else "FRANCE",)
db.session.commit()
return redirect(url_for("entreprises.fiche_entreprise", id=site.entreprise_id))
elif request.method == "GET":
form.nom.data = site.nom
form.adresse.data = site.adresse
form.codepostal.data = site.codepostal
form.ville.data = site.ville
form.pays.data = site.pays
return render_template(
"entreprises/form.html",
title="Modification site",
form=form,
)
@bp.route(
"/fiche_entreprise/<int:id_entreprise>/add_correspondant/<int:id_site>",
methods=["GET", "POST"],

View File

@ -423,17 +423,19 @@ def list_abs_date(etudid, beg_date=None, end_date=None):
print("On rentre")
cnx = ndb.GetDBConnexion()
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
print("Juste avant le SQL")
cursor.execute(
"""SELECT jour, matin, estabs, estjust, description FROM ABSENCES A
WHERE A.ETUDID = %(etudid)s"""
+ ""
req = """SELECT jour, matin, estabs, estjust, description
FROM ABSENCES A
WHERE A.ETUDID = %(etudid)s""" + (
""
if beg_date is None
else """
AND A.jour >= %(beg_date)s
AND A.jour <= %(end_date)s
""",
"""
)
cursor.execute(
req,
vars(),
)

View File

@ -54,7 +54,7 @@
<td>{{ correspondant[0].mail }}</td>
<td>{{ correspondant[0].poste}}</td>
<td>{{ correspondant[0].service}}</td>
<td><a href="{{ url_for('entreprises.fiche_entreprise', id=correspondant[1].id) }}">{{ correspondant[1].nom }}</a></td>
<td><a href="{{ url_for('entreprises.fiche_entreprise', id=correspondant[1].entreprise_id) }}">{{ correspondant[1].nom }}</a></td>
</tr>
{% endfor %}
</tbody>

View File

@ -61,7 +61,10 @@
Ville : {{ site.ville }}<br>
Pays : {{ site.pays }}
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
<br><a class="btn btn-primary" href="{{ url_for('entreprises.add_correspondant', id_entreprise=entreprise.id, id_site=site.id) }}">Ajouter correspondant</a>
<div>
<a class="btn btn-primary" href="{{ url_for('entreprises.edit_site', id_entreprise=entreprise.id, id_site=site.id) }}">Modifier</a>
<a class="btn btn-primary" href="{{ url_for('entreprises.add_correspondant', id_entreprise=entreprise.id, id_site=site.id) }}">Ajouter correspondant</a>
</div>
{% endif %}
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesCorrespondants, None) %}
{% for correspondant in site.correspondants %}

View File

@ -1,7 +1,7 @@
# -*- mode: python -*-
# -*- coding: utf-8 -*-
SCOVERSION = "9.2.13"
SCOVERSION = "9.2.14"
SCONAME = "ScoDoc"