diff --git a/app/entreprises/app_relations_entreprises.py b/app/entreprises/app_relations_entreprises.py index 68ff9986..6b2a2e56 100644 --- a/app/entreprises/app_relations_entreprises.py +++ b/app/entreprises/app_relations_entreprises.py @@ -85,6 +85,7 @@ def get_offre_files_and_depts(offre: EntrepriseOffre, depts: list): Retourne l'offre, les fichiers attachés a l'offre et les département liés """ offre_depts = EntrepriseOffreDepartement.query.filter_by(offre_id=offre.id).all() + contact = EntrepriseContact.query.filter_by(id=offre.contact_id).first() if not offre_depts or check_offre_depts(depts, offre_depts): files = [] path = os.path.join( @@ -100,7 +101,7 @@ def get_offre_files_and_depts(offre: EntrepriseOffre, depts: list): for _file in glob.glob(f"{dir}/*"): file = [os.path.basename(dir), os.path.basename(_file)] files.append(file) - return [offre, files, offre_depts] + return [offre, files, offre_depts, contact] return None diff --git a/app/entreprises/forms.py b/app/entreprises/forms.py index 0540c080..19719bcc 100644 --- a/app/entreprises/forms.py +++ b/app/entreprises/forms.py @@ -144,6 +144,7 @@ class MultiCheckboxField(SelectMultipleField): class OffreCreationForm(FlaskForm): + hidden_entreprise_id = HiddenField() intitule = _build_string_field("Intitulé (*)") description = TextAreaField( "Description (*)", validators=[DataRequired(message=CHAMP_REQUIS)] @@ -159,17 +160,26 @@ class OffreCreationForm(FlaskForm): duree = _build_string_field("Durée (*)") depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) expiration_date = DateField("Date expiration", validators=[Optional()]) + contact = SelectField("Contact à contacté (*)", validators=[Optional()]) submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.contact.choices = [ + (contact.id, f"{contact.nom} {contact.prenom}") + for contact in EntrepriseContact.query.filter_by( + entreprise_id=self.hidden_entreprise_id.data + ) + ] + self.depts.choices = [ (dept.id, dept.acronym) for dept in Departement.query.all() ] class OffreModificationForm(FlaskForm): + hidden_entreprise_id = HiddenField() intitule = _build_string_field("Intitulé (*)") description = TextAreaField( "Description (*)", validators=[DataRequired(message=CHAMP_REQUIS)] @@ -185,11 +195,19 @@ class OffreModificationForm(FlaskForm): duree = _build_string_field("Durée (*)") depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) expiration_date = DateField("Date expiration", validators=[Optional()]) + contact = SelectField("Contact à contacté (*)", validators=[Optional()]) submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.contact.choices = [ + (contact.id, f"{contact.nom} {contact.prenom}") + for contact in EntrepriseContact.query.filter_by( + entreprise_id=self.hidden_entreprise_id.data + ) + ] + self.depts.choices = [ (dept.id, dept.acronym) for dept in Departement.query.all() ] @@ -206,8 +224,16 @@ class ContactCreationForm(FlaskForm): ) poste = _build_string_field("Poste", required=False) service = _build_string_field("Service", required=False) + # depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) + # def __init__(self, *args, **kwargs): + # super().__init__(*args, **kwargs) + + # self.depts.choices = [ + # (dept.id, dept.acronym) for dept in Departement.query.all() + # ] + def validate(self): validate = True if not FlaskForm.validate(self): @@ -245,8 +271,16 @@ class ContactModificationForm(FlaskForm): ) poste = _build_string_field("Poste", required=False) service = _build_string_field("Service", required=False) + # depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) + # def __init__(self, *args, **kwargs): + # super().__init__(*args, **kwargs) + + # self.depts.choices = [ + # (dept.id, dept.acronym) for dept in Departement.query.all() + # ] + def validate(self): validate = True if not FlaskForm.validate(self): diff --git a/app/entreprises/models.py b/app/entreprises/models.py index dd0b4ba4..b4c1e7ca 100644 --- a/app/entreprises/models.py +++ b/app/entreprises/models.py @@ -75,6 +75,9 @@ class EntrepriseOffre(db.Model): duree = db.Column(db.Text) expiration_date = db.Column(db.Date) expired = db.Column(db.Boolean, default=False) + contact_id = db.Column( + db.Integer, db.ForeignKey("are_contacts.id", ondelete="cascade") + ) def to_dict(self): return { @@ -136,6 +139,15 @@ class EntrepriseOffreDepartement(db.Model): dept_id = db.Column(db.Integer, db.ForeignKey("departement.id", ondelete="cascade")) +# class EntrepriseContactDepartement(db.Model): +# __tablename__ = "are_contact_departement" +# id = db.Column(db.Integer, primary_key=True) +# contact_id = db.Column( +# db.Integer, db.ForeignKey("are_contacts.id", ondelete="cascade") +# ) +# dept_id = db.Column(db.Integer, db.ForeignKey("departement.id", ondelete="cascade")) + + class EntreprisePreferences(db.Model): __tablename__ = "are_preferences" id = db.Column(db.Integer, primary_key=True) diff --git a/app/entreprises/routes.py b/app/entreprises/routes.py index d1633e71..281ad047 100644 --- a/app/entreprises/routes.py +++ b/app/entreprises/routes.py @@ -221,6 +221,7 @@ def offres_recues(): ) offres_recues_with_files = [] for offre in offres_recues: + contact = EntrepriseContact.query.filter_by(id=offre[1].contact_id).first() files = [] path = os.path.join( Config.SCODOC_VAR_DIR, @@ -235,7 +236,7 @@ def offres_recues(): for file in glob.glob(f"{dir}/*"): file = [os.path.basename(dir), os.path.basename(file)] files.append(file) - offres_recues_with_files.append([offre[0], offre[1], files]) + offres_recues_with_files.append([offre[0], offre[1], files, contact]) return render_template( "entreprises/offres_recues.html", title="Offres reçues", @@ -491,7 +492,7 @@ def add_offre(id): entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404( description=f"entreprise {id} inconnue" ) - form = OffreCreationForm() + form = OffreCreationForm(hidden_entreprise_id=id) if form.validate_on_submit(): offre = EntrepriseOffre( entreprise_id=entreprise.id, @@ -501,6 +502,7 @@ def add_offre(id): missions=form.missions.data.strip(), duree=form.duree.data.strip(), expiration_date=form.expiration_date.data, + contact_id=form.contact.data, ) db.session.add(offre) db.session.commit() @@ -537,15 +539,19 @@ def edit_offre(id): description=f"offre {id} inconnue" ) offre_depts = EntrepriseOffreDepartement.query.filter_by(offre_id=offre.id).all() - form = OffreModificationForm() + form = OffreModificationForm( + hidden_entreprise_id=offre.entreprise_id, contact=offre.contact_id + ) offre_depts_list = [(offre_dept.dept_id) for offre_dept in offre_depts] if form.validate_on_submit(): + print(form.contact.data) offre.intitule = form.intitule.data.strip() offre.description = form.description.data.strip() offre.type_offre = form.type_offre.data.strip() offre.missions = form.missions.data.strip() offre.duree = form.duree.data.strip() offre.expiration_date = form.expiration_date.data + offre.contact_id = form.contact.data if offre_depts_list != form.depts.data: for dept in form.depts.data: if dept not in offre_depts_list: diff --git a/app/templates/entreprises/_offre.html b/app/templates/entreprises/_offre.html index cff6f03a..11391da3 100644 --- a/app/templates/entreprises/_offre.html +++ b/app/templates/entreprises/_offre.html @@ -9,6 +9,16 @@ {% if offre[2] %} Département(s) : {% for offre_dept in offre[2] %}