ajout contacts, correction import

This commit is contained in:
Arthur ZHU 2022-04-05 02:26:43 +02:00
parent efe48582bf
commit 9af424d356
6 changed files with 206 additions and 15 deletions

View File

@ -311,6 +311,24 @@ class CorrespondantModificationForm(FlaskForm):
return validate
class ContactCreationForm(FlaskForm):
date = _build_string_field(
"Date",
render_kw={"type": "datetime-local"},
)
notes = TextAreaField("Notes (*)", validators=[DataRequired(message=CHAMP_REQUIS)])
submit = SubmitField("Envoyer", render_kw=SUBMIT_MARGE)
class ContactModificationForm(FlaskForm):
date = _build_string_field(
"Date",
render_kw={"type": "datetime-local"},
)
notes = TextAreaField("Notes (*)", validators=[DataRequired(message=CHAMP_REQUIS)])
submit = SubmitField("Modifier", render_kw=SUBMIT_MARGE)
class StageApprentissageCreationForm(FlaskForm):
etudiant = _build_string_field(
"Étudiant (*)",

View File

@ -61,6 +61,17 @@ class EntrepriseCorrespondant(db.Model):
}
class EntrepriseContact(db.Model):
__tablename__ = "are_contacts"
id = db.Column(db.Integer, primary_key=True)
date = db.Column(db.DateTime(timezone=True))
user = db.Column(db.Integer, db.ForeignKey("user.id", ondelete="cascade"))
entreprise = db.Column(
db.Integer, db.ForeignKey("are_entreprises.id", ondelete="cascade")
)
notes = db.Column(db.Text)
class EntrepriseOffre(db.Model):
__tablename__ = "are_offres"
id = db.Column(db.Integer, primary_key=True)

View File

@ -19,6 +19,8 @@ from app.entreprises.forms import (
OffreModificationForm,
CorrespondantCreationForm,
CorrespondantModificationForm,
ContactCreationForm,
ContactModificationForm,
StageApprentissageCreationForm,
StageApprentissageModificationForm,
EnvoiOffreForm,
@ -33,6 +35,7 @@ from app.entreprises.models import (
EntrepriseOffre,
EntrepriseCorrespondant,
EntrepriseLog,
EntrepriseContact,
EntrepriseStageApprentissage,
EntrepriseEnvoiOffre,
EntrepriseOffreDepartement,
@ -784,6 +787,69 @@ def delete_correspondant(id):
)
@bp.route("fiche_entreprise/add_contact/<int:id>", methods=["GET", "POST"])
@permission_required(Permission.RelationsEntreprisesChange)
def add_contact(id):
"""
Permet d'ajouter un contact avec une entreprise
"""
entreprise = Entreprise.query.filter_by(id=id, visible=True).first_or_404(
description=f"entreprise {id} inconnue"
)
form = ContactCreationForm()
if form.validate_on_submit():
contact = EntrepriseContact(
date=form.date.data,
user=current_user.id, # a voir
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 render_template(
"entreprises/form.html",
title="Ajout contact",
form=form,
)
@bp.route("fiche_entreprise/edit_contact/<int:id>", methods=["GET", "POST"])
@permission_required(Permission.RelationsEntreprisesChange)
def edit_contact(id):
"""
Permet d'editer un contact avec une entreprise
"""
contact = EntrepriseContact.query.filter_by(id=id).first_or_404(
description=f"contact {id} inconnu"
)
form = ContactModificationForm()
if form.validate_on_submit():
contact.date = form.date.data
contact.notes = form.notes.data
db.session.commit()
return redirect(url_for("entreprises.fiche_entreprise", id=contact.entreprise))
elif request.method == "GET":
form.date.data = contact.date
form.notes.data = contact.notes
return render_template(
"entreprises/form.html",
title="Modification contact",
form=form,
)
@bp.route("/fiche_entreprise/contacts/<int:id>")
def contacts(id):
contacts = EntrepriseContact.query.filter_by(entreprise=id).all()
return render_template(
"entreprises/contacts.html",
title="Liste des contacts",
contacts=contacts,
entreprise_id=id,
)
@bp.route("/add_stage_apprentissage/<int:id>", methods=["GET", "POST"])
@permission_required(Permission.RelationsEntreprisesChange)
def add_stage_apprentissage(id):
@ -1229,6 +1295,9 @@ def import_correspondants():
correspondant_data[6],
)
)
entreprise = Entreprise.query.filter_by(
siret=correspondant_data[6]
).first()
correspondant = EntrepriseCorrespondant(
nom=correspondant_data[0],
prenom=correspondant_data[1],
@ -1236,7 +1305,7 @@ def import_correspondants():
mail=correspondant_data[3],
poste=correspondant_data[4],
service=correspondant_data[5],
entreprise_id=correspondant_data[6],
entreprise_id=entreprise.id,
)
correspondants_import.append(correspondant)
else:

View File

@ -0,0 +1,87 @@
{# -*- mode: jinja-html -*- #}
{% extends 'base.html' %}
{% block styles %}
{{super()}}
<script src="/ScoDoc/static/jQuery/jquery-1.12.4.min.js"></script>
<link rel="stylesheet" type="text/css" href="/ScoDoc/static/DataTables/datatables.min.css">
<script type="text/javascript" charset="utf8" src="/ScoDoc/static/DataTables/datatables.min.js"></script>
{% endblock %}
{% block app_content %}
<div class="container" style="margin-bottom: 10px;">
<h1>Liste des contacts</h1>
<a class="btn btn-primary" style="margin-bottom:10px;" href="{{ url_for('entreprises.add_contact', id=entreprise_id) }}">Ajouter contact</a>
<table id="table-contacts">
<thead>
<tr>
<td data-priority="">Date</td>
<td data-priority="">Utilisateur</td>
<td data-priority="">Notes</td>
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
<td data-priority="">Action</td>
{% endif %}
</tr>
</thead>
<tbody>
{% for contact in contacts %}
<tr>
<td>{{ contact.date.strftime('%d/%m/%Y %Hh%M') }}</td>
<td>{{ contact.user|get_nomcomplet_by_id }}</td>
<td>{{ contact.notes }}</td>
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
<td>
<div class="btn-group">
<a class="btn btn-default dropdown-toggle" data-toggle="dropdown" href="#">Action
<span class="caret"></span>
</a>
<ul class="dropdown-menu pull-left">
<li><a href="{{ url_for('entreprises.edit_contact', id=contact.id) }}">Modifier</a></li>
</ul>
</div>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td>Date</td>
<td>Utilisateur</td>
<td>Notes</td>
{% if current_user.has_permission(current_user.Permission.RelationsEntreprisesChange, None) %}
<td>Action</td>
{% endif %}
</tr>
</tfoot>
</table>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
let table = new DataTable('#table-contacts',
{
"autoWidth": false,
"responsive": {
"details": true
},
"pageLength": 10,
"language": {
"emptyTable": "Aucune donnée disponible dans le tableau",
"info": "Affichage de _START_ à _END_ sur _TOTAL_ entrées",
"infoEmpty": "Affichage de 0 à 0 sur 0 entrées",
"infoFiltered": "(filtrées depuis un total de _MAX_ entrées)",
"lengthMenu": "Afficher _MENU_ entrées",
"loadingRecords": "Chargement...",
"processing": "Traitement...",
"search": "Rechercher:",
"zeroRecords": "Aucune entrée correspondante trouvée",
"paginate": {
"next": "Suivante",
"previous": "Précédente"
}
}
});
});
</script>
{% endblock %}

View File

@ -43,6 +43,7 @@
<a class="btn btn-danger" href="{{ url_for('entreprises.delete_entreprise', id=entreprise.id) }}">Supprimer</a>
<a class="btn btn-primary" href="{{ url_for('entreprises.add_offre', id=entreprise.id) }}">Ajouter offre</a>
<a class="btn btn-primary" href="{{ url_for('entreprises.add_correspondant', id=entreprise.id) }}">Ajouter correspondant</a>
<a class="btn btn-primary" href="{{ url_for('entreprises.add_contact', id=entreprise.id) }}">Ajouter contact</a>
{% endif %}
<a class="btn btn-primary" href="{{ url_for('entreprises.offres_expirees', id=entreprise.id) }}">Voir les offres expirées</a>
<div>

View File

@ -1,8 +1,8 @@
"""tables module gestion relations entreprises
Revision ID: 71e760aa626a
Revision ID: e5043b68e6b9
Revises: b9aadc10227f
Create Date: 2022-03-29 18:39:24.772970
Create Date: 2022-04-04 09:14:54.605480
"""
from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = "71e760aa626a"
revision = "e5043b68e6b9"
down_revision = "b9aadc10227f"
branch_labels = None
depends_on = None
@ -51,6 +51,19 @@ def upgrade():
sa.Column("value", sa.Text(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"are_contacts",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("date", sa.DateTime(timezone=True), nullable=True),
sa.Column("user", sa.Integer(), nullable=True),
sa.Column("entreprise", sa.Integer(), nullable=True),
sa.Column("notes", sa.Text(), nullable=True),
sa.ForeignKeyConstraint(
["entreprise"], ["are_entreprises.id"], ondelete="cascade"
),
sa.ForeignKeyConstraint(["user"], ["user.id"], ondelete="cascade"),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"are_correspondants",
sa.Column("id", sa.Integer(), nullable=False),
@ -151,9 +164,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 ###
@ -198,15 +211,7 @@ def downgrade():
op.create_index("ix_entreprises_dept_id", "entreprises", ["dept_id"], unique=False)
op.create_table(
"entreprise_correspondant",
sa.Column(
"id",
sa.INTEGER(),
server_default=sa.text(
"nextval('entreprise_correspondant_id_seq'::regclass)"
),
autoincrement=True,
nullable=False,
),
sa.Column("id", sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column("entreprise_id", sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column("nom", sa.TEXT(), autoincrement=False, nullable=True),
sa.Column("prenom", sa.TEXT(), autoincrement=False, nullable=True),
@ -225,7 +230,6 @@ def downgrade():
name="entreprise_correspondant_entreprise_id_fkey",
),
sa.PrimaryKeyConstraint("id", name="entreprise_correspondant_pkey"),
postgresql_ignore_search_path=False,
)
op.create_table(
"entreprise_contact",
@ -262,6 +266,7 @@ def downgrade():
op.drop_table("are_offres")
op.drop_table("are_stages_apprentissages")
op.drop_table("are_correspondants")
op.drop_table("are_contacts")
op.drop_table("are_preferences")
op.drop_table("are_logs")
op.drop_table("are_entreprises")