associer un contact a une offre

This commit is contained in:
Arthur ZHU 2022-03-04 17:10:07 +01:00
parent 60552feec7
commit 5f5c43ec08
7 changed files with 89 additions and 9 deletions

View File

@ -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 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() 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): if not offre_depts or check_offre_depts(depts, offre_depts):
files = [] files = []
path = os.path.join( 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}/*"): for _file in glob.glob(f"{dir}/*"):
file = [os.path.basename(dir), os.path.basename(_file)] file = [os.path.basename(dir), os.path.basename(_file)]
files.append(file) files.append(file)
return [offre, files, offre_depts] return [offre, files, offre_depts, contact]
return None return None

View File

@ -144,6 +144,7 @@ class MultiCheckboxField(SelectMultipleField):
class OffreCreationForm(FlaskForm): class OffreCreationForm(FlaskForm):
hidden_entreprise_id = HiddenField()
intitule = _build_string_field("Intitulé (*)") intitule = _build_string_field("Intitulé (*)")
description = TextAreaField( description = TextAreaField(
"Description (*)", validators=[DataRequired(message=CHAMP_REQUIS)] "Description (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
@ -159,17 +160,26 @@ class OffreCreationForm(FlaskForm):
duree = _build_string_field("Durée (*)") duree = _build_string_field("Durée (*)")
depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int)
expiration_date = DateField("Date expiration", validators=[Optional()]) expiration_date = DateField("Date expiration", validators=[Optional()])
contact = SelectField("Contact à contacté (*)", validators=[Optional()])
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*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 = [ self.depts.choices = [
(dept.id, dept.acronym) for dept in Departement.query.all() (dept.id, dept.acronym) for dept in Departement.query.all()
] ]
class OffreModificationForm(FlaskForm): class OffreModificationForm(FlaskForm):
hidden_entreprise_id = HiddenField()
intitule = _build_string_field("Intitulé (*)") intitule = _build_string_field("Intitulé (*)")
description = TextAreaField( description = TextAreaField(
"Description (*)", validators=[DataRequired(message=CHAMP_REQUIS)] "Description (*)", validators=[DataRequired(message=CHAMP_REQUIS)]
@ -185,11 +195,19 @@ class OffreModificationForm(FlaskForm):
duree = _build_string_field("Durée (*)") duree = _build_string_field("Durée (*)")
depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int) depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int)
expiration_date = DateField("Date expiration", validators=[Optional()]) expiration_date = DateField("Date expiration", validators=[Optional()])
contact = SelectField("Contact à contacté (*)", validators=[Optional()])
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*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 = [ self.depts.choices = [
(dept.id, dept.acronym) for dept in Departement.query.all() (dept.id, dept.acronym) for dept in Departement.query.all()
] ]
@ -206,8 +224,16 @@ class ContactCreationForm(FlaskForm):
) )
poste = _build_string_field("Poste", required=False) poste = _build_string_field("Poste", required=False)
service = _build_string_field("Service", required=False) service = _build_string_field("Service", required=False)
# depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int)
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE) 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): def validate(self):
validate = True validate = True
if not FlaskForm.validate(self): if not FlaskForm.validate(self):
@ -245,8 +271,16 @@ class ContactModificationForm(FlaskForm):
) )
poste = _build_string_field("Poste", required=False) poste = _build_string_field("Poste", required=False)
service = _build_string_field("Service", required=False) service = _build_string_field("Service", required=False)
# depts = MultiCheckboxField("Départements", validators=[Optional()], coerce=int)
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE) 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): def validate(self):
validate = True validate = True
if not FlaskForm.validate(self): if not FlaskForm.validate(self):

View File

@ -75,6 +75,9 @@ class EntrepriseOffre(db.Model):
duree = db.Column(db.Text) duree = db.Column(db.Text)
expiration_date = db.Column(db.Date) expiration_date = db.Column(db.Date)
expired = db.Column(db.Boolean, default=False) expired = db.Column(db.Boolean, default=False)
contact_id = db.Column(
db.Integer, db.ForeignKey("are_contacts.id", ondelete="cascade")
)
def to_dict(self): def to_dict(self):
return { return {
@ -136,6 +139,15 @@ class EntrepriseOffreDepartement(db.Model):
dept_id = db.Column(db.Integer, db.ForeignKey("departement.id", ondelete="cascade")) 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): class EntreprisePreferences(db.Model):
__tablename__ = "are_preferences" __tablename__ = "are_preferences"
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)

View File

@ -221,6 +221,7 @@ def offres_recues():
) )
offres_recues_with_files = [] offres_recues_with_files = []
for offre in offres_recues: for offre in offres_recues:
contact = EntrepriseContact.query.filter_by(id=offre[1].contact_id).first()
files = [] files = []
path = os.path.join( path = os.path.join(
Config.SCODOC_VAR_DIR, Config.SCODOC_VAR_DIR,
@ -235,7 +236,7 @@ def offres_recues():
for file in glob.glob(f"{dir}/*"): for file in glob.glob(f"{dir}/*"):
file = [os.path.basename(dir), os.path.basename(file)] file = [os.path.basename(dir), os.path.basename(file)]
files.append(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( return render_template(
"entreprises/offres_recues.html", "entreprises/offres_recues.html",
title="Offres reçues", title="Offres reçues",
@ -491,7 +492,7 @@ def add_offre(id):
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404( entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
description=f"entreprise {id} inconnue" description=f"entreprise {id} inconnue"
) )
form = OffreCreationForm() form = OffreCreationForm(hidden_entreprise_id=id)
if form.validate_on_submit(): if form.validate_on_submit():
offre = EntrepriseOffre( offre = EntrepriseOffre(
entreprise_id=entreprise.id, entreprise_id=entreprise.id,
@ -501,6 +502,7 @@ def add_offre(id):
missions=form.missions.data.strip(), missions=form.missions.data.strip(),
duree=form.duree.data.strip(), duree=form.duree.data.strip(),
expiration_date=form.expiration_date.data, expiration_date=form.expiration_date.data,
contact_id=form.contact.data,
) )
db.session.add(offre) db.session.add(offre)
db.session.commit() db.session.commit()
@ -537,15 +539,19 @@ def edit_offre(id):
description=f"offre {id} inconnue" description=f"offre {id} inconnue"
) )
offre_depts = EntrepriseOffreDepartement.query.filter_by(offre_id=offre.id).all() 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] offre_depts_list = [(offre_dept.dept_id) for offre_dept in offre_depts]
if form.validate_on_submit(): if form.validate_on_submit():
print(form.contact.data)
offre.intitule = form.intitule.data.strip() offre.intitule = form.intitule.data.strip()
offre.description = form.description.data.strip() offre.description = form.description.data.strip()
offre.type_offre = form.type_offre.data.strip() offre.type_offre = form.type_offre.data.strip()
offre.missions = form.missions.data.strip() offre.missions = form.missions.data.strip()
offre.duree = form.duree.data.strip() offre.duree = form.duree.data.strip()
offre.expiration_date = form.expiration_date.data offre.expiration_date = form.expiration_date.data
offre.contact_id = form.contact.data
if offre_depts_list != form.depts.data: if offre_depts_list != form.depts.data:
for dept in form.depts.data: for dept in form.depts.data:
if dept not in offre_depts_list: if dept not in offre_depts_list:

View File

@ -9,6 +9,16 @@
{% if offre[2] %} {% if offre[2] %}
Département(s) : {% for offre_dept in offre[2] %} <div class="offre-depts">{{ offre_dept.dept_id|get_dept_acronym }}</div> {% endfor %}<br> Département(s) : {% for offre_dept in offre[2] %} <div class="offre-depts">{{ offre_dept.dept_id|get_dept_acronym }}</div> {% endfor %}<br>
{% endif %} {% endif %}
{% if offre[0].contact_id %}
Contacté {{ offre[3].nom }} {{ offre[3].prenom }}
{% if offre[3].mail and offre[3].telephone %}
({{ offre[3].mail }} - {{ offre[3].telephone }})<br>
{% else %}
({{ offre[3].mail }}{{offre[3].telephone}})<br>
{% endif %}
{% endif %}
{% for fichier in offre[1] %} {% for fichier in offre[1] %}
<a href="{{ url_for('entreprises.get_offre_file', entreprise_id=entreprise.id, offre_id=offre[0].id, filedir=fichier[0], filename=fichier[1] )}}">{{ fichier[1] }}</a> <a href="{{ url_for('entreprises.get_offre_file', entreprise_id=entreprise.id, offre_id=offre[0].id, filedir=fichier[0], filename=fichier[1] )}}">{{ fichier[1] }}</a>
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %} {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
@ -16,6 +26,7 @@
{% endif %} {% endif %}
<br> <br>
{% endfor %} {% endfor %}
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %} {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
<a href="{{ url_for('entreprises.add_offre_file', offre_id=offre[0].id) }}">Ajoutez un fichier</a> <a href="{{ url_for('entreprises.add_offre_file', offre_id=offre[0].id) }}">Ajoutez un fichier</a>
{% endif %} {% endif %}
@ -26,9 +37,11 @@
<a class="btn btn-primary" href="{{ url_for('entreprises.edit_offre', id=offre[0].id) }}">Modifier l'offre</a> <a class="btn btn-primary" href="{{ url_for('entreprises.edit_offre', id=offre[0].id) }}">Modifier l'offre</a>
<a class="btn btn-danger" href="{{ url_for('entreprises.delete_offre', id=offre[0].id) }}">Supprimer l'offre</a> <a class="btn btn-danger" href="{{ url_for('entreprises.delete_offre', id=offre[0].id) }}">Supprimer l'offre</a>
{% endif %} {% endif %}
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesSend, None) %} {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesSend, None) %}
<a class="btn btn-primary" href="{{ url_for('entreprises.envoyer_offre', id=offre[0].id) }}">Envoyer l'offre</a> <a class="btn btn-primary" href="{{ url_for('entreprises.envoyer_offre', id=offre[0].id) }}">Envoyer l'offre</a>
{% endif %} {% endif %}
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %} {% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
{% if not offre[0].expired %} {% if not offre[0].expired %}
<a class="btn btn-danger" href="{{ url_for('entreprises.expired', id=offre[0].id) }}">Rendre expirée</a> <a class="btn btn-danger" href="{{ url_for('entreprises.expired', id=offre[0].id) }}">Rendre expirée</a>

View File

@ -16,6 +16,16 @@
Type de l'offre : {{ offre[1].type_offre }}<br> Type de l'offre : {{ offre[1].type_offre }}<br>
Missions : {{ offre[1].missions }}<br> Missions : {{ offre[1].missions }}<br>
Durée : {{ offre[1].duree }}<br> Durée : {{ offre[1].duree }}<br>
{% if offre[1].contact_id %}
Contacté {{ offre[3].nom }} {{ offre[3].prenom }}
{% if offre[3].mail and offre[3].telephone %}
({{ offre[3].mail }} - {{ offre[3].telephone }})<br>
{% else %}
({{ offre[3].mail }}{{offre[3].telephone}})<br>
{% endif %}
{% endif %}
<a href="{{ url_for('entreprises.fiche_entreprise', id=offre[1].entreprise_id) }}">lien vers l'entreprise</a><br> <a href="{{ url_for('entreprises.fiche_entreprise', id=offre[1].entreprise_id) }}">lien vers l'entreprise</a><br>
{% for fichier in offre[2] %} {% for fichier in offre[2] %}

View File

@ -1,8 +1,8 @@
"""tables module gestion relations entreprises """tables module gestion relations entreprises
Revision ID: af05f03b81be Revision ID: 40ece1f74b7a
Revises: b9aadc10227f Revises: b9aadc10227f
Create Date: 2022-03-01 17:12:32.927643 Create Date: 2022-03-04 16:06:28.163870
""" """
from alembic import op from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
from sqlalchemy.dialects import postgresql from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = "af05f03b81be" revision = "40ece1f74b7a"
down_revision = "b9aadc10227f" down_revision = "b9aadc10227f"
branch_labels = None branch_labels = None
depends_on = None depends_on = None
@ -98,6 +98,10 @@ def upgrade():
sa.Column("duree", sa.Text(), nullable=True), sa.Column("duree", sa.Text(), nullable=True),
sa.Column("expiration_date", sa.Date(), nullable=True), sa.Column("expiration_date", sa.Date(), nullable=True),
sa.Column("expired", sa.Boolean(), nullable=True), sa.Column("expired", sa.Boolean(), nullable=True),
sa.Column("contact_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(
["contact_id"], ["are_contacts.id"], ondelete="cascade"
),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
["entreprise_id"], ["are_entreprises.id"], ondelete="cascade" ["entreprise_id"], ["are_entreprises.id"], ondelete="cascade"
), ),
@ -146,9 +150,9 @@ def upgrade():
sa.ForeignKeyConstraint(["offre_id"], ["are_offres.id"], ondelete="cascade"), sa.ForeignKeyConstraint(["offre_id"], ["are_offres.id"], ondelete="cascade"),
sa.PrimaryKeyConstraint("id"), sa.PrimaryKeyConstraint("id"),
) )
op.drop_index("ix_entreprises_dept_id", table_name="entreprises")
op.drop_table("entreprise_contact") op.drop_table("entreprise_contact")
op.drop_table("entreprise_correspondant") op.drop_table("entreprise_correspondant")
op.drop_index("ix_entreprises_dept_id", table_name="entreprises")
op.drop_table("entreprises") op.drop_table("entreprises")
# ### end Alembic commands ### # ### end Alembic commands ###
@ -190,7 +194,6 @@ def downgrade():
sa.PrimaryKeyConstraint("id", name="entreprises_pkey"), sa.PrimaryKeyConstraint("id", name="entreprises_pkey"),
postgresql_ignore_search_path=False, postgresql_ignore_search_path=False,
) )
op.create_index("ix_entreprises_dept_id", "entreprises", ["dept_id"], unique=False)
op.create_table( op.create_table(
"entreprise_correspondant", "entreprise_correspondant",
sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False), sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
@ -242,6 +245,7 @@ def downgrade():
), ),
sa.PrimaryKeyConstraint("id", name="entreprise_contact_pkey"), sa.PrimaryKeyConstraint("id", name="entreprise_contact_pkey"),
) )
op.create_index("ix_entreprises_dept_id", "entreprises", ["dept_id"], unique=False)
op.drop_table("are_offre_departement") op.drop_table("are_offre_departement")
op.drop_table("are_envoi_offre_etudiant") op.drop_table("are_envoi_offre_etudiant")
op.drop_table("are_envoi_offre") op.drop_table("are_envoi_offre")