-
Notifications
You must be signed in to change notification settings - Fork 16
Acantin/recruiter form accessibility fix #371
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,29 @@ def inject_user(): | |
def inject_jepostule_enabled(): | ||
return {'jepostule_enabled': jepostule_enabled} | ||
|
||
def inject_compute_input_attributes(): | ||
def compute_input_attributes(field): | ||
attrs = {} | ||
|
||
if field.validators and field.validators[0].__class__.__name__ == "DataRequired": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je pense que tu peux écrire ça mieux avec There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. En effet, ça marche et c'est plus digeste ! |
||
attrs['aria-required'] = 'true' | ||
|
||
# aria-describedby are used to link input fields to their description and/or error messages | ||
aria_describedby = [] | ||
if field.description: | ||
aria_describedby.append('{}_description'.format(field.id)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Juste pour la forme, en Python 3 il y a les f-strings qui te permettent d'écrire comme ça : aria_describedby.append(f"{field.id}_description") |
||
if field.errors: | ||
aria_describedby.append('{}_errors'.format(field.id)) | ||
|
||
if aria_describedby: | ||
attrs['aria-describedby'] = ' '.join(aria_describedby) | ||
|
||
return attrs | ||
|
||
return dict(compute_input_attributes=compute_input_attributes) | ||
|
||
|
||
flask_app.context_processor(inject_compute_input_attributes) | ||
flask_app.context_processor(inject_dict_for_all_templates) | ||
flask_app.context_processor(inject_user) | ||
flask_app.context_processor(inject_jepostule_enabled) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ class OfficeIdentificationForm(FlaskForm): | |
'N° de Siret *', | ||
validators=[ | ||
DataRequired(), | ||
Regexp('[0-9]{14}', message=("Le siret de l'établissement est invalide (14 chiffres)")) | ||
Regexp('[0-9]{14}', message=("Le siret de l'établissement est invalide (14 chiffres sans espace)")) | ||
], | ||
description="14 chiffres, sans espace. Exemple: 36252187900034", | ||
) | ||
|
@@ -34,30 +34,22 @@ class OfficeIdentificationForm(FlaskForm): | |
first_name = StringField('Prénom *', validators=[DataRequired()]) | ||
phone = TelField( | ||
'Téléphone *', | ||
validators=[DataRequired(), Regexp(PHONE_REGEX)], | ||
render_kw={"placeholder": "01 77 86 39 49, +331 77 86 39 49"} | ||
description="Exemple: 01 77 86 39 49 ou +331 77 86 39 49", | ||
validators=[DataRequired(), Regexp(PHONE_REGEX, message="Entrée invalide. Exemple valide: 01 77 86 39 49 ou +331 77 86 39 49")], | ||
) | ||
email = EmailField( | ||
'Adresse email *', | ||
validators=[DataRequired(), Email()], | ||
render_kw={"placeholder": "[email protected]"} | ||
description="Exemple: [email protected]", | ||
validators=[DataRequired(), Email(message="Entrée invalide. Exemple valide: [email protected]")], | ||
) | ||
|
||
|
||
class OfficeHiddenIdentificationForm(FlaskForm): | ||
siret = HiddenField('Siret *', validators=[DataRequired()]) | ||
last_name = HiddenField('Nom *', validators=[DataRequired()]) | ||
first_name = HiddenField('Prénom *', validators=[DataRequired()]) | ||
phone = HiddenField( | ||
'Téléphone *', | ||
validators=[DataRequired(), Regexp(PHONE_REGEX)], | ||
render_kw={"placeholder": "01 77 86 39 49, +331 77 86 39 49"} | ||
) | ||
email = HiddenField( | ||
'Adresse email *', | ||
validators=[DataRequired(), Email()], | ||
render_kw={"placeholder": "[email protected]"} | ||
) | ||
phone = HiddenField('Téléphone *', validators=[DataRequired(), Regexp(PHONE_REGEX)]) | ||
email = HiddenField('Adresse email *', validators=[DataRequired(), Email()]) | ||
|
||
|
||
class OfficeOtherRequestForm(OfficeHiddenIdentificationForm): | ||
|
@@ -77,27 +69,33 @@ class OfficeUpdateCoordinatesForm(OfficeHiddenIdentificationForm): | |
new_contact_mode = RadioField('Mode de contact à privilégier', choices=CONTACT_MODES, default='email') | ||
new_website = StringField( | ||
'Site Internet', | ||
validators=[URL(), Optional()], render_kw={"placeholder": "http://exemple.com"} | ||
description="Exemple: http://exemple.com", | ||
validators=[URL(message="Entrée invalide. Exemple: http://exemple.com"), Optional()] | ||
) | ||
new_email = EmailField( | ||
'Email recruteur', | ||
validators=[Email(), Optional()], render_kw={"placeholder": "[email protected]"} | ||
description="Exemple: [email protected]", | ||
validators=[Email(message="Entrée invalide. Exemple valide: [email protected]"), Optional()] | ||
) | ||
new_phone = StringField( | ||
'Téléphone', | ||
validators=[Optional(), Regexp(PHONE_REGEX)], | ||
render_kw={"placeholder": "01 77 86 39 49, +331 77 86 39 49"} | ||
description="Exemple: 01 77 86 39 49 ou +331 77 86 39 49", | ||
validators=[Optional(), Regexp(PHONE_REGEX, message="Entrée invalide. Exemple valide: 01 77 86 39 49 ou +331 77 86 39 49")] | ||
) | ||
social_network = StringField( | ||
'Réseau social', | ||
description="Exemple: https://twitter.com/0123456_abcdef", | ||
validators=[URL(message="Entrée invalide. Exemple: https://twitter.com/0123456_abcdef"), Optional()] | ||
) | ||
social_network = StringField('Réseau social', validators=[URL(), Optional()]) | ||
new_email_alternance = EmailField( | ||
'Email recruteur spécialisé alternance', | ||
validators=[validators.optional(), Email()], | ||
render_kw={"placeholder": "exemple-alternance@domaine.com"} | ||
description="Exemple: [email protected]", | ||
validators=[validators.optional(), Email(message="Entrée invalide. Exemple valide: [email protected]")] | ||
) | ||
new_phone_alternance = StringField( | ||
'Téléphone du recruteur spécialisé alternance', | ||
validators=[validators.optional(), Regexp(PHONE_REGEX)], | ||
render_kw={"placeholder": "01 77 86 39 49, +331 77 86 39 49"} | ||
description="Exemple: 01 77 86 39 49 ou +331 77 86 39 49", | ||
validators=[validators.optional(), Regexp(PHONE_REGEX, message="Entrée invalide. Exemple valide: 01 77 86 39 49 ou +331 77 86 39 49")] | ||
) | ||
rgpd_consent = BooleanField( | ||
'En cochant cette case, vous consentez à diffuser des données à caractère personnel sur les services numériques de Pôle emploi.', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,8 @@ def change_info(): | |
fix_csrf_session() | ||
form = forms.OfficeIdentificationForm() | ||
|
||
form_has_errors = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ça me paraît super bizarre, il y a une propriété There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Le message d'erreur était un message flash, je l'ai passé en erreur au niveau du champs en question :) |
||
|
||
# Clear session if user comes from 'I don't have recruiter account' | ||
if request.args.get('no_pe_connect', ''): | ||
peam_recruiter.clear_pe_connect_recruiter_session() | ||
|
@@ -138,6 +140,7 @@ def change_info(): | |
|
||
action_name = get_action_name() | ||
if not action_name: | ||
form_has_errors = True | ||
flash('Une erreur inattendue est survenue, veuillez sélectionner à nouveau une action', 'error') | ||
return redirect(url_for('contact_form.ask_action')) | ||
|
||
|
@@ -152,6 +155,7 @@ def change_info(): | |
if form.validate_on_submit(): | ||
office = models.Office.query.filter(models.Office.siret == form.siret.data).first() | ||
if not office: | ||
form_has_errors = True | ||
flash(unknown_siret_message(), 'error') | ||
else: | ||
params = {key: form.data[key] for key in ['siret', 'last_name', 'first_name', 'phone', 'email']} | ||
|
@@ -161,15 +165,19 @@ def change_info(): | |
url = url_for(action_form_url, **params) | ||
return redirect(url) | ||
|
||
if form.errors and not form_has_errors: | ||
form_has_errors = True | ||
|
||
return render_template('contact_form/form.html', | ||
title='Identifiez-vous', | ||
title='Erreur - Identifiez-vous' if form_has_errors else 'Identifiez-vous', | ||
submit_text='suivant', | ||
extra_submit_class='identification-form', | ||
form=form, | ||
is_certified_recruiter=peam_recruiter.is_certified_recruiter(), | ||
is_recruiter=peam_recruiter.is_recruiter(), | ||
use_lba_template=is_recruiter_from_lba(), | ||
show_disclaimer=True, | ||
show_credentials_disclaimer=True, | ||
show_required_disclaimer=True, | ||
hide_return=True, | ||
custom_ga_pageview='/recruteur/%s/identification' % action_name, | ||
) | ||
|
@@ -237,7 +245,7 @@ def update_coordinates_form(form): | |
else: | ||
redirect_params = get_success_value() | ||
return render_template('contact_form/success_message.html', | ||
title="Merci pour votre message", | ||
title="Confirmation - Merci pour votre message", | ||
use_lba_template=is_recruiter_from_lba(), | ||
site_name=redirect_params.get('site_name'), | ||
email=redirect_params.get('email'), | ||
|
@@ -251,6 +259,7 @@ def update_coordinates_form(form): | |
return render_template('contact_form/form.html', | ||
title='Modifier ma fiche entreprise', | ||
form=form, | ||
submit_text='Modifier ma fiche entreprise', | ||
params=extract_recruiter_data(), | ||
use_lba_template=is_recruiter_from_lba(), | ||
show_entreprise_page=True, | ||
|
@@ -297,7 +306,7 @@ def update_jobs_form(form): | |
else: | ||
redirect_params = get_success_value() | ||
return render_template('contact_form/success_message.html', | ||
title="Merci pour votre message", | ||
title="Confirmation - Merci pour votre message", | ||
use_lba_template=is_recruiter_from_lba(), | ||
site_name=redirect_params.get('site_name'), | ||
email=redirect_params.get('email'), | ||
|
@@ -313,6 +322,7 @@ def update_jobs_form(form): | |
return render_template('contact_form/change_job_infos.html', | ||
title='Demande de modification des métiers', | ||
form=form, | ||
submit_text='Modifier mes métiers', | ||
params=extract_recruiter_data(), | ||
use_lba_template=is_recruiter_from_lba(), | ||
manually_added_jobs=extract_manually_added_jobs(office), | ||
|
@@ -340,7 +350,7 @@ def delete_form(form): | |
else: | ||
redirect_params = get_success_value() | ||
return render_template('contact_form/success_message.html', | ||
title="Merci pour votre message", | ||
title="Confirmation - Merci pour votre message", | ||
use_lba_template=is_recruiter_from_lba(), | ||
site_name=redirect_params.get('site_name'), | ||
email=redirect_params.get('email'), | ||
|
@@ -353,6 +363,7 @@ def delete_form(form): | |
return render_template('contact_form/form.html', | ||
title='Supprimer mon entreprise', | ||
form=form, | ||
submit_text='Supprimer mon entreprise', | ||
params=extract_recruiter_data(), | ||
use_lba_template=is_recruiter_from_lba(), | ||
custom_ga_pageview='/recruteur/delete/delete', | ||
|
@@ -378,7 +389,7 @@ def other_form(form): | |
else: | ||
redirect_params = get_success_value() | ||
return render_template('contact_form/success_message.html', | ||
title="Merci pour votre message", | ||
title="Confirmation - Merci pour votre message", | ||
use_lba_template=is_recruiter_from_lba(), | ||
site_name=redirect_params.get('site_name'), | ||
email=redirect_params.get('email'), | ||
|
@@ -392,6 +403,7 @@ def other_form(form): | |
'contact_form/form.html', | ||
form=form, | ||
title='Autre demande', | ||
submit_text='Envoyer votre message', | ||
params=extract_recruiter_data(), | ||
use_lba_template=is_recruiter_from_lba(), | ||
show_required_disclaimer=True, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ça mérite une docstring qui explique ce que ça fait !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍