forked from ScoDoc/ScoDoc
empeche les doublons sur contact dans une même entreprise
This commit is contained in:
parent
0beea0dfc6
commit
9477106e9a
@ -3,10 +3,10 @@ from markupsafe import Markup
|
||||
from flask.app import Flask
|
||||
import requests, re
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SubmitField, TextAreaField, SelectField, FileField
|
||||
from wtforms import StringField, SubmitField, TextAreaField, SelectField, FileField, HiddenField
|
||||
from wtforms.fields.html5 import EmailField, DateField
|
||||
from wtforms.validators import ValidationError, DataRequired, Email
|
||||
from app.entreprises.models import Entreprise
|
||||
from app.entreprises.models import Entreprise, EntrepriseContact
|
||||
from app.models import Identite
|
||||
from app.auth.models import User
|
||||
from app.scodoc import sco_etud
|
||||
@ -71,8 +71,27 @@ class ContactCreationForm(FlaskForm):
|
||||
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()
|
||||
submit = SubmitField("Envoyer")
|
||||
|
||||
def validate(self):
|
||||
rv = FlaskForm.validate(self)
|
||||
if not rv:
|
||||
return False
|
||||
|
||||
contact = EntrepriseContact.query.filter_by(
|
||||
entreprise_id = self.hidden_entreprise_id.data,
|
||||
nom = self.nom.data,
|
||||
prenom = self.prenom.data
|
||||
).first()
|
||||
|
||||
if contact is not None:
|
||||
self.nom.errors.append("Ce contact existe déjà (même nom et prénom)")
|
||||
self.prenom.errors.append("")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
class ContactModificationForm(FlaskForm):
|
||||
nom = StringField("Nom", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
|
||||
prenom = StringField("Prénom", validators=[DataRequired(message=DATA_REQUIRED_ERROR_MESSAGE)])
|
||||
|
@ -238,7 +238,7 @@ def delete_offre(id):
|
||||
@bp.route("/add_contact/<id>", methods=["GET", "POST"])
|
||||
def add_contact(id):
|
||||
entreprise = Entreprise.query.filter_by(id=id).first_or_404()
|
||||
form = ContactCreationForm()
|
||||
form = ContactCreationForm(hidden_entreprise_id=entreprise.id)
|
||||
if form.validate_on_submit():
|
||||
contact = EntrepriseContact(
|
||||
entreprise_id=entreprise.id,
|
||||
|
@ -12,6 +12,9 @@
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<p>
|
||||
Les champs s'autocomplète selon le SIRET
|
||||
</p>
|
||||
{{ wtf.quick_form(form, novalidate=True) }}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user