From 178016b682c3767754454f0f44f02b4b78cb6e57 Mon Sep 17 00:00:00 2001 From: Arthur ZHU Date: Fri, 24 Dec 2021 16:07:36 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20page=20offres,=20insertion=20en=20base?= =?UTF-8?q?=20des=20diff=C3=A9rents=20objets,=20enrichissement=20des=20cha?= =?UTF-8?q?mps?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/entreprises/forms.py | 4 +++- app/entreprises/routes.py | 32 +++++++++++++++++++++---- app/templates/entreprises/contacts.html | 1 - app/templates/entreprises/offres.html | 28 ++++++++++++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 app/templates/entreprises/offres.html diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index d2f3762b..502db347 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -67,11 +67,13 @@ class OffreModificationForm(FlaskForm): submit = SubmitField("Modifier") class ContactCreationForm(FlaskForm): + hidden_entreprise_id = HiddenField() nom = StringField("Nom", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)]) 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")]) - hidden_entreprise_id = HiddenField() + poste = StringField("Poste", validators=[]) + service = StringField("Service", validators=[]) submit = SubmitField("Envoyer") def validate(self): diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index 1791199e..7570c806 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -21,7 +21,8 @@ from app.entreprises.models import ( EntrepriseOffre, EntrepriseContact, EntrepriseLog, - EntrepriseEtudiant + EntrepriseEtudiant, + EntrepriseEnvoiOffre ) from app.models import ( Identite @@ -52,10 +53,16 @@ def fiche_entreprise(id): contacts = entreprise.contacts logs = EntrepriseLog.query.order_by(EntrepriseLog.date.desc()).filter_by(object=id).limit(LOGS_LEN).all() historique = db.session.query(EntrepriseEtudiant, Identite).order_by(EntrepriseEtudiant.date_debut.desc()).\ - filter_by(entreprise_id=id).\ + filter(EntrepriseEtudiant.entreprise_id == id).\ join(Identite, Identite.id == EntrepriseEtudiant.etudid).all() return render_template("entreprises/fiche_entreprise.html", title=("Fiche entreprise"), entreprise=entreprise, contacts=contacts, offres=offres, logs=logs, historique=historique) +@bp.route("/offres", methods=["GET"]) +def offres(): + offres_recus = db.session.query(EntrepriseEnvoiOffre, EntrepriseOffre).filter(EntrepriseEnvoiOffre.user_id == current_user.id).\ + join(EntrepriseOffre, EntrepriseOffre.id == EntrepriseEnvoiOffre.offre_id).all() + return render_template("entreprises/offres.html", title=("Offres"), offres_recus=offres_recus) + @bp.route("/add_entreprise", methods=["GET", "POST"]) def add_entreprise(): form = EntrepriseCreationForm() @@ -245,7 +252,9 @@ def add_contact(id): nom=form.nom.data.strip(), prenom=form.prenom.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() ) log = EntrepriseLog( authenticated_user = current_user.user_name, @@ -268,6 +277,8 @@ def edit_contact(id): contact.prenom = form.prenom.data.strip() contact.telephone = form.telephone.data.strip() contact.mail = form.mail.data.strip() + contact.poste = form.poste.data.strip() + contact.service = form.service.data.strip() log = EntrepriseLog( authenticated_user = current_user.user_name, object = contact.entreprise_id, @@ -282,6 +293,8 @@ def edit_contact(id): form.prenom.data = contact.prenom form.telephone.data = contact.telephone form.mail.data = contact.mail + form.poste.data = contact.poste + form.service.data = contact.service return render_template("entreprises/form.html", title=("Modification contact"), form=form) @bp.route("/delete_contact/", methods=["GET", "POST"]) @@ -335,9 +348,20 @@ def add_historique(id): @bp.route("/envoyer_offre/", methods=["GET", "POST"]) def envoyer_offre(id): + offre = EntrepriseOffre.query.filter_by(id=id).first_or_404() form = EnvoiOffreForm() if form.validate_on_submit(): - print("tmp") # faire l'envoie du mail + responsable_data = form.responsable.data.upper().strip() + stm = text("SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:responsable_data") + responsable = User.query.from_statement(stm).params(responsable_data=responsable_data).first() + envoi_offre = EntrepriseEnvoiOffre( + user_id = responsable.id, + offre_id = offre.id + ) + db.session.add(envoi_offre) + db.session.commit() + flash(f"L'offre a été envoyé à {responsable.get_nomplogin()}.") + return redirect(url_for("entreprises.fiche_entreprise", id=offre.entreprise_id)) return render_template("entreprises/envoi_offre_form.html", title=("Envoyer une offre"), form=form) @bp.route("/etudiants") diff --git a/app/templates/entreprises/contacts.html b/app/templates/entreprises/contacts.html index 7f143333..fdf2a747 100644 --- a/app/templates/entreprises/contacts.html +++ b/app/templates/entreprises/contacts.html @@ -36,7 +36,6 @@
{% else %}
Aucun contact présent dans la base
-
{% endif %} diff --git a/app/templates/entreprises/offres.html b/app/templates/entreprises/offres.html new file mode 100644 index 00000000..717364b9 --- /dev/null +++ b/app/templates/entreprises/offres.html @@ -0,0 +1,28 @@ +{% extends 'base.html' %} + +{% block app_content %} +
+

{{ title }}

+ {% if offres_recus %} +
+
+ {% for offre in offres_recus %} +
+

+ Date envoi : {{ offre[0].date_envoi.strftime('%d/%m/%Y %H:%M') }}
+ Intitulé : {{ offre[1].intitule }}
+ Description : {{ offre[1].description }}
+ Type de l'offre : {{ offre[1].type_offre }}
+ Missions : {{ offre[1].missions }}
+ Durée : {{ offre[1].duree }}
+

+
+ {% endfor %} +
+
+ {% else %} +
Aucune offre reçue
+
+ {% endif %} +
+{% endblock %} \ No newline at end of file