forked from ScoDoc/ScoDoc
ajout champ formulaire contact, entreprise site
This commit is contained in:
parent
edd9fde616
commit
eb288fa6a1
@ -398,21 +398,55 @@ class CorrespondantModificationForm(FlaskForm):
|
||||
|
||||
class ContactCreationForm(FlaskForm):
|
||||
date = _build_string_field(
|
||||
"Date",
|
||||
"Date (*)",
|
||||
render_kw={"type": "datetime-local"},
|
||||
)
|
||||
utilisateur = _build_string_field(
|
||||
"Utilisateur (*)",
|
||||
render_kw={"placeholder": "Tapez le nom de l'utilisateur"},
|
||||
)
|
||||
notes = TextAreaField("Notes (*)", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def validate_utilisateur(self, utilisateur):
|
||||
utilisateur_data = self.utilisateur.data.upper().strip()
|
||||
stm = text(
|
||||
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:utilisateur_data"
|
||||
)
|
||||
utilisateur = (
|
||||
User.query.from_statement(stm)
|
||||
.params(utilisateur_data=utilisateur_data)
|
||||
.first()
|
||||
)
|
||||
if utilisateur is None:
|
||||
raise ValidationError("Champ incorrect (selectionnez dans la liste)")
|
||||
|
||||
|
||||
class ContactModificationForm(FlaskForm):
|
||||
date = _build_string_field(
|
||||
"Date",
|
||||
"Date (*)",
|
||||
render_kw={"type": "datetime-local"},
|
||||
)
|
||||
utilisateur = _build_string_field(
|
||||
"Utilisateur (*)",
|
||||
render_kw={"placeholder": "Tapez le nom de l'utilisateur"},
|
||||
)
|
||||
notes = TextAreaField("Notes (*)", validators=[DataRequired(message=CHAMP_REQUIS)])
|
||||
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
|
||||
|
||||
def validate_utilisateur(self, utilisateur):
|
||||
utilisateur_data = self.utilisateur.data.upper().strip()
|
||||
stm = text(
|
||||
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:utilisateur_data"
|
||||
)
|
||||
utilisateur = (
|
||||
User.query.from_statement(stm)
|
||||
.params(utilisateur_data=utilisateur_data)
|
||||
.first()
|
||||
)
|
||||
if utilisateur is None:
|
||||
raise ValidationError("Champ incorrect (selectionnez dans la liste)")
|
||||
|
||||
|
||||
class StageApprentissageCreationForm(FlaskForm):
|
||||
etudiant = _build_string_field(
|
||||
|
@ -35,10 +35,13 @@ class Entreprise(db.Model):
|
||||
}
|
||||
|
||||
|
||||
# class EntrepriseSite(db.Model):
|
||||
# __tablename__ = "are_sites"
|
||||
# id = db.Column(db.Integer, primary_key=True)
|
||||
# nom = db.Column(db.Text)
|
||||
class EntrepriseSite(db.Model):
|
||||
__tablename__ = "are_sites"
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
entreprise_id = db.Column(
|
||||
db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade")
|
||||
)
|
||||
nom = db.Column(db.Text)
|
||||
|
||||
|
||||
class EntrepriseCorrespondant(db.Model):
|
||||
@ -47,6 +50,7 @@ class EntrepriseCorrespondant(db.Model):
|
||||
entreprise_id = db.Column(
|
||||
db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade")
|
||||
)
|
||||
site_id = db.Column(db.Integer, db.ForeignKey("are_sites.id", ondelete="cascade"))
|
||||
nom = db.Column(db.Text)
|
||||
prenom = db.Column(db.Text)
|
||||
telephone = db.Column(db.Text)
|
||||
|
@ -805,17 +805,31 @@ def add_contact(id):
|
||||
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
|
||||
description=f"entreprise {id} inconnue"
|
||||
)
|
||||
form = ContactCreationForm()
|
||||
form = ContactCreationForm(
|
||||
date=f"{datetime.now().strftime('%Y-%m-%dT%H:%M')}",
|
||||
utilisateur=f"{current_user.nom} {current_user.prenom} ({current_user.user_name})"
|
||||
if current_user.nom and current_user.prenom
|
||||
else "",
|
||||
)
|
||||
if form.validate_on_submit():
|
||||
utilisateur_data = form.utilisateur.data.upper().strip()
|
||||
stm = text(
|
||||
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:utilisateur_data"
|
||||
)
|
||||
utilisateur = (
|
||||
User.query.from_statement(stm)
|
||||
.params(utilisateur_data=utilisateur_data)
|
||||
.first()
|
||||
)
|
||||
contact = EntrepriseContact(
|
||||
date=form.date.data,
|
||||
user=current_user.id, # a voir
|
||||
user=utilisateur.id,
|
||||
entreprise=entreprise.id,
|
||||
notes=form.notes.data.strip(),
|
||||
)
|
||||
db.session.add(contact)
|
||||
db.session.commit()
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=entreprise.id))
|
||||
return redirect(url_for("entreprises.contacts", id=entreprise.id))
|
||||
return render_template(
|
||||
"entreprises/form.html",
|
||||
title="Ajout contact",
|
||||
@ -834,12 +848,26 @@ def edit_contact(id):
|
||||
)
|
||||
form = ContactModificationForm()
|
||||
if form.validate_on_submit():
|
||||
utilisateur_data = form.utilisateur.data.upper().strip()
|
||||
stm = text(
|
||||
"SELECT id, UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')')) FROM \"user\" WHERE UPPER(CONCAT(nom, ' ', prenom, ' ', '(', user_name, ')'))=:utilisateur_data"
|
||||
)
|
||||
utilisateur = (
|
||||
User.query.from_statement(stm)
|
||||
.params(utilisateur_data=utilisateur_data)
|
||||
.first()
|
||||
)
|
||||
contact.date = form.date.data
|
||||
contact.user = utilisateur.id
|
||||
contact.notes = form.notes.data
|
||||
db.session.commit()
|
||||
return redirect(url_for("entreprises.fiche_entreprise", id=contact.entreprise))
|
||||
return redirect(url_for("entreprises.contacts", id=contact.entreprise))
|
||||
elif request.method == "GET":
|
||||
form.date.data = contact.date
|
||||
utilisateur = User.query.filter_by(id=contact.user).first()
|
||||
form.date.data = contact.date.strftime("%Y-%m-%dT%H:%M")
|
||||
form.utilisateur.data = (
|
||||
f"{utilisateur.nom} {utilisateur.prenom} ({utilisateur.user_name})"
|
||||
)
|
||||
form.notes.data = contact.notes
|
||||
return render_template(
|
||||
"entreprises/form.html",
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
{% block styles %}
|
||||
{{super()}}
|
||||
<link type="text/css" rel="stylesheet" href="/ScoDoc/static/css/autosuggest_inquisitor.css" />
|
||||
<script src="/ScoDoc/static/libjs/AutoSuggest.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block app_content %}
|
||||
@ -19,20 +21,6 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
{# pour les formulaires contact #}
|
||||
var champ_date = document.getElementById("date")
|
||||
if (champ_date !== null && champ_date.value === "") {
|
||||
var maintenant = new Date()
|
||||
champ_date.value = `${maintenant.getFullYear()}-${formatDate(maintenant.getMonth() + 1)}-${formatDate(maintenant.getDate())}T${formatDate(maintenant.getHours())}:${formatDate(maintenant.getMinutes())}`
|
||||
}
|
||||
|
||||
function formatDate(value) {
|
||||
if(value < 10)
|
||||
return `0${value}`
|
||||
else
|
||||
return value
|
||||
}
|
||||
|
||||
{# pour les formulaires offre #}
|
||||
var champ_depts = document.getElementById("depts")
|
||||
if (champ_depts !== null) {
|
||||
@ -59,5 +47,16 @@
|
||||
expiration.value = `${date.getFullYear() + 1}-08-01`
|
||||
}
|
||||
}
|
||||
|
||||
var responsables_options = {
|
||||
script: "/ScoDoc/entreprises/responsables?",
|
||||
varname: "term",
|
||||
json: true,
|
||||
noresults: "Valeur invalide !",
|
||||
minchars: 2,
|
||||
timeout: 60000
|
||||
};
|
||||
|
||||
var as_utilisateurs = new bsn.AutoSuggest('utilisateur', responsables_options);
|
||||
</script>
|
||||
{% endblock %}
|
@ -1,8 +1,8 @@
|
||||
"""tables module gestion relations entreprises
|
||||
|
||||
Revision ID: e5043b68e6b9
|
||||
Revision ID: 2a99f5553555
|
||||
Revises: b9aadc10227f
|
||||
Create Date: 2022-04-04 09:14:54.605480
|
||||
Create Date: 2022-04-15 18:12:46.620653
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "e5043b68e6b9"
|
||||
revision = "2a99f5553555"
|
||||
down_revision = "b9aadc10227f"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
@ -65,15 +65,10 @@ def upgrade():
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"are_correspondants",
|
||||
"are_sites",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("entreprise_id", sa.Integer(), nullable=True),
|
||||
sa.Column("nom", sa.Text(), nullable=True),
|
||||
sa.Column("prenom", sa.Text(), nullable=True),
|
||||
sa.Column("telephone", sa.Text(), nullable=True),
|
||||
sa.Column("mail", sa.Text(), nullable=True),
|
||||
sa.Column("poste", sa.Text(), nullable=True),
|
||||
sa.Column("service", sa.Text(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["entreprise_id"], ["are_entreprises.id"], ondelete="cascade"
|
||||
),
|
||||
@ -95,6 +90,23 @@ def upgrade():
|
||||
),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"are_correspondants",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("entreprise_id", sa.Integer(), nullable=True),
|
||||
sa.Column("site_id", sa.Integer(), nullable=True),
|
||||
sa.Column("nom", sa.Text(), nullable=True),
|
||||
sa.Column("prenom", sa.Text(), nullable=True),
|
||||
sa.Column("telephone", sa.Text(), nullable=True),
|
||||
sa.Column("mail", sa.Text(), nullable=True),
|
||||
sa.Column("poste", sa.Text(), nullable=True),
|
||||
sa.Column("service", sa.Text(), nullable=True),
|
||||
sa.ForeignKeyConstraint(
|
||||
["entreprise_id"], ["are_entreprises.id"], ondelete="cascade"
|
||||
),
|
||||
sa.ForeignKeyConstraint(["site_id"], ["are_sites.id"], ondelete="cascade"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_table(
|
||||
"are_offres",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
@ -164,9 +176,9 @@ def upgrade():
|
||||
sa.ForeignKeyConstraint(["offre_id"], ["are_offres.id"], ondelete="cascade"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.drop_index("ix_entreprises_dept_id", table_name="entreprises")
|
||||
op.drop_table("entreprise_contact")
|
||||
op.drop_table("entreprise_correspondant")
|
||||
op.drop_index("ix_entreprises_dept_id", table_name="entreprises")
|
||||
op.drop_table("entreprises")
|
||||
# ### end Alembic commands ###
|
||||
|
||||
@ -264,8 +276,9 @@ def downgrade():
|
||||
op.drop_table("are_envoi_offre_etudiant")
|
||||
op.drop_table("are_envoi_offre")
|
||||
op.drop_table("are_offres")
|
||||
op.drop_table("are_stages_apprentissages")
|
||||
op.drop_table("are_correspondants")
|
||||
op.drop_table("are_stages_apprentissages")
|
||||
op.drop_table("are_sites")
|
||||
op.drop_table("are_contacts")
|
||||
op.drop_table("are_preferences")
|
||||
op.drop_table("are_logs")
|
Loading…
Reference in New Issue
Block a user