Commit 50af5aae authored by fred.lpo07's avatar fred.lpo07

Fix required validator mission on person form for phone number

parent 1bb78a9c
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="test" uuid="0cb60128-3d23-41de-b121-ed335bbeb13a">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/test.sqlite</jdbc-url>
</data-source>
<data-source source="LOCAL" name="test [2]" uuid="71e66982-4176-471d-ba33-39ccc7d92733">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/test.sqlite</jdbc-url>
</data-source>
<data-source source="LOCAL" name="db" uuid="99e3ba84-13c7-4a70-9621-1a27245c4fa6">
<data-source source="LOCAL" name="db" uuid="1746d282-94e5-43e1-9275-94462378bc15">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/db.sqlite</jdbc-url>
<libraries>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/sqlite-jdbc-3.25.1.jar</url>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/license.txt</url>
</library>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/license.txt</url>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/sqlite-jdbc-3.25.1.jar</url>
</library>
</libraries>
</data-source>
......
......@@ -41,12 +41,12 @@ class PersonForm(FlaskForm):
query_factory=get_territory_unit, get_label='name',
get_pk=lambda a: a.name,
render_kw=common_input)
email_referent = EmailField('Email responsable', validators=[DataRequired(), Email()], render_kw=common_input)
email_referent = EmailField('Email du responsable', validators=[DataRequired(), Email()], render_kw=common_input)
service = StringField('Service/Pôle', render_kw=common_input)
workplace_address = TextAreaField('Adresse du lieu de travail', validators=[DataRequired()],
render_kw=common_input)
workplace_city = StringField('Ville du lieu de travail', validators=[DataRequired()], render_kw=common_input)
phone_number = StringField('Numéro de téléphone', render_kw=common_input)
phone_number = StringField('Numéro de téléphone', validators=[DataRequired()], render_kw=common_input)
contract_type = QuerySelectField('Type de contrat', validators=[DataRequired()], query_factory=get_contract_type,
get_label='name',
get_pk=lambda a: a.name,
......@@ -55,7 +55,7 @@ class PersonForm(FlaskForm):
get_label='name',
get_pk=lambda a: a.name,
render_kw=common_input)
teams_list = QuerySelectMultipleField('Listes Teams©', query_factory=get_teams_list,
teams_list = QuerySelectMultipleField('Selectionnez les listes de diffusion mail auxquelles la personne doit être rattachée', query_factory=get_teams_list,
get_label='name',
get_pk=lambda a: a.name,
render_kw=common_input)
......
......@@ -45,25 +45,28 @@ class RecipientAdmin(ModelView):
class Person(db.Model, SaveMixin):
id_person = db.Column(db.Integer, primary_key=True)
email_declarator = db.Column(db.String(256), nullable=False)
name = db.Column(db.String(80), nullable=False)
surname = db.Column(db.String(80), nullable=False)
email = db.Column(db.String(256), nullable=False)
arrival_date = db.Column(db.Date, nullable=False)
departure_date = db.Column(db.Date, nullable=True)
territory_unit = db.Column(db.String(256), db.ForeignKey('territory_unit.name'), nullable=False)
email_referent = db.Column(db.String(256), nullable=False)
service = db.Column(db.String(256), nullable=True)
workplace_address = db.Column(db.String(1000), nullable=True)
workplace_city = db.Column(db.String(256), nullable=True)
phone_number = db.Column(db.String(256), nullable=False)
contract_type = db.Column(db.String(256), db.ForeignKey('contract_type.name'), nullable=False)
position_type = db.Column(db.String(256), db.ForeignKey('position_type.name'), nullable=False)
job_title = db.Column(db.String(256), nullable=True)
teams_list = db.Column(db.String(1000), nullable=True)
comment = db.Column(db.String(), nullable=True)
create_ts = db.Column(db.DateTime, nullable=False, default=datetime.now())
id_person = db.Column(db.Integer, primary_key=True, doc='ID de la donnée')
email_declarator = db.Column(db.String(256), nullable=False, doc='Email du déclarant')
name = db.Column(db.String(80), nullable=False, doc='Nom')
surname = db.Column(db.String(80), nullable=False, doc='Prénom')
email = db.Column(db.String(256), nullable=False, doc='Email')
arrival_date = db.Column(db.Date, nullable=False, doc="Date d'arrivée")
departure_date = db.Column(db.Date, nullable=True, doc="Date de départ")
territory_unit = db.Column(db.String(256), db.ForeignKey('territory_unit.name'), nullable=False,
doc="Délégation territoriale")
email_referent = db.Column(db.String(256), nullable=False, doc="Email du responsable")
service = db.Column(db.String(256), nullable=True, doc="Service de rattachement")
workplace_address = db.Column(db.String(1000), nullable=True, doc="Adresse du lieu de travail")
workplace_city = db.Column(db.String(256), nullable=True, doc="Ville du lieu de travail")
phone_number = db.Column(db.String(256), nullable=False, doc="Numéro de téléphone")
contract_type = db.Column(db.String(256), db.ForeignKey('contract_type.name'), nullable=False,
doc="Type de contrat")
position_type = db.Column(db.String(256), db.ForeignKey('position_type.name'), nullable=False, doc="Type de poste")
job_title = db.Column(db.String(256), nullable=True, doc="Intitulé du poste")
teams_list = db.Column(db.String(1000), nullable=True, doc="Listes TEAMS")
comment = db.Column(db.String(), nullable=True, doc="Commentaire")
create_ts = db.Column(db.DateTime, nullable=False, default=datetime.now(),
doc="Date/heure de création de la donnée")
def __repr__(self):
return "<PersonModel: {} {}>".format(self.name, self.surname)
......
......@@ -108,6 +108,14 @@ def persons():
def recipient_add():
recipient_form = RecipientForm()
var_list = []
for a in Person.__table__.columns:
print('att', a.doc, a.name)
d = {}
d['doc'] = a.doc
d['var'] = a.name
var_list.append(d)
if request.method == 'POST':
data = request.form
try:
......@@ -124,11 +132,48 @@ def recipient_add():
except Exception as e:
print("<add_recipient error>", e)
flash(e)
return render_template("recipient_form.html", form=recipient_form)
return render_template("recipient_form.html", form=recipient_form, var=var_list)
return redirect(url_for('main.recipients_list'))
return render_template("recipient_form.html", form=recipient_form, var=var_list)
@main_bp.route("/recipient/edit/<id>", methods=["GET", "POST"])
def recipient_edit(id=None):
recipient = Recipient.query.get(id)
recipient_form = RecipientForm(obj=recipient)
recipient_form.populate_obj(recipient)
var_list = []
for a in Person.__table__.columns:
d = {}
d['doc'] = a.doc
d['var'] = a.name
var_list.append(d)
if request.method == 'POST':
data = request.form
try:
recipient_data = {}
if data:
for d in data:
print(d, data[d])
if hasattr(Recipient, d):
recipient_data[d] = data[d]
recipient.update(recipient_data)
recipient.update_to_db()
except Exception as e:
print("<add_recipient error>", e)
flash(e)
return render_template("recipient_form.html", form=recipient_form, var=var_list)
return redirect(url_for('main.recipients_list'))
return render_template("recipient_form.html", form=recipient_form)
return render_template("recipient_form.html", form=recipient_form, var=var_list)
@main_bp.route('/recipients')
......
......@@ -18,48 +18,11 @@
et <code>surname</code> est <i>Benoit</i> donnera ainsi un mail contenant le message suivant <code>Le
salarié MANCEL Benoit...</code>
<ul>
{% for v in var %}
<li>
Email du déclarant: <code>{email_declarator}</code>
</li>
<li>
Nom: <code>{name}</code>
</li>
<li>
Prénom: <code>{surname}</code>
</li>
<li>
Email: <code>{email}</code>
</li>
<li>
Date d'arrivée: <code>{arrival_date}</code>
</li>
<li>
Date de départ: <code>{departure_date}</code>
</li>
<li>
Délégation territoriale: <code>{territory_unit_id}</code>
</li>
<li>
Email responsable: <code>{email_referent}</code>
</li>
<li>
Service/Pôle: <code>{service}</code>
</li>
<li>
Adresse du lieu de travail: <code>{workplace_address}</code>
</li>
<li>
Ville du lieu de travail: <code>{workplace_city}</code>
</li>
<li>
Numéro de téléphone: <code>{phone_number}</code>
</li>
<li>
Type de poste: <code>{position_type}</code>
</li>
<li>
Commentaire: <code>{comment}</code>
{{v.doc}}&nbsp;: <code>{{'{'+v.var+'}'}}</code>
</li>
{% endfor %}
</ul>
</div>
</div>
......
......@@ -23,6 +23,9 @@ class SaveMixin(object):
db.session.add(self)
db.session.commit()
def update_to_db(self):
db.session.commmit()
class GunicornApp(BaseApplication):
"""Convert a Flask application to a Gunicorn one.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment