Unverified Commit 5b976204 authored by Roland Denis's avatar Roland Denis
Browse files

Submission success and internal error messages.

parent 3386ea5f
Pipeline #2457 passed with stage
in 9 seconds
......@@ -173,10 +173,6 @@ class FormData(object):
if attachment_mime not in ATTACHMENT_MIME_TYPE:
errors.attachment = 'Type de fichier invalide'
# In case of an error and if there is an attachment, recall the user
if errors.has_error() and self.has_attachment() and not errors.attachment:
errors.attachment = "N'oubliez pas de re-déposer votre document"
return errors
def __str__(self):
......@@ -525,7 +521,7 @@ def local_write_job(job_offer):
###############################################################################
def update_html_form(form_data=FormData(), errors=FormError(), debug=Debug()):
def update_html_form(form_data=FormData(), errors=FormError(), debug=Debug(), internal_error=False, success=False):
""" Update the form with error messages. """
from jinja2 import Environment, FileSystemLoader
......@@ -553,7 +549,9 @@ def update_html_form(form_data=FormData(), errors=FormError(), debug=Debug()):
form=form_data,
errors=errors,
file_accept=file_accept,
job_type_list=JOBOFFER_TYPE
job_type_list=JOBOFFER_TYPE,
internal_error=internal_error,
success=success,
))
......@@ -562,30 +560,42 @@ def update_html_form(form_data=FormData(), errors=FormError(), debug=Debug()):
def process_form(form_data, debug=Debug()):
""" Check and submit job-offer. """
# Displaying form data in debug mode
if debug.verbose:
print('[DEBUG] Form data: {}\n'.format(form_data), file=sys.stderr)
errors = FormError()
# Checking form validity
errors = form_data.check()
try:
# Displaying form data in debug mode
if debug.verbose:
print('[DEBUG] Form data: {}\n'.format(form_data), file=sys.stderr)
if debug.verbose:
print('[DEBUG] Form errors: {}\n'.format(errors), file=sys.stderr)
# Checking form validity
errors = form_data.check()
if errors.has_error():
update_html_form(form_data, errors, debug)
return
if debug.verbose:
print('[DEBUG] Form errors: {}\n'.format(errors), file=sys.stderr)
# Creating job offer
job_offer = JobOffer(form_data)
if errors.has_error():
update_html_form(form_data, errors, debug)
return
# Creating pull request
if debug.local:
local_write_job(job_offer)
else:
create_job_request(job_offer, debug)
# Creating job offer
job_offer = JobOffer(form_data)
# Creating pull request
if debug.local:
local_write_job(job_offer)
else:
create_job_request(job_offer, debug)
# Success page
update_html_form(debug=debug, success=True)
except Exception as error:
# Internal error
import traceback
print("[ERROR] Error while submitting job offer: {}".format(error), file=sys.stderr)
print("[ERROR] {}".format(traceback.format_exc()), file=sys.stderr)
update_html_form(form_data, errors, debug, internal_error=True)
# TODO: success page
###############################################################################
......
......@@ -2,8 +2,6 @@
{% block title %}Formulaire de dépôt d'une offre d'emploi{% endblock %}
{% block ogtitle %}Formulaire de dépôt d'une offre d'emploi{% endblock %}
{% block ogurl %}{{ SITEURL }}/contact.html{%endblock%}
{% block canonicalurl %}{{ SITEURL }}/contact.html{%endblock%}
{% block header_content %}
<a href="{{ SITEURL }}/category/offres-demploi.html" class="btn btn-dark my-1" id="header-btn">
......@@ -19,8 +17,25 @@
<div class="container-fluid job_offers">
<div class="container job_form">
{{ ' {% if success %} ' }}
<p>
Nous avons bien enregistré votre offre d'emploi, elle sera publiée très prochainement.
Lorsque votre offre sera périmée, merci de le signaler à <a href="mailto:calcul-contact@services.cnrs.fr">calcul-contact@services.cnrs.fr</a>.
</p>
{{ ' {% else %} ' }}
<link rel="stylesheet" href="{{ SITEURL }}/css/simplemde.min.css">
<script src="{{ SITEURL }}/js/simplemde.min.js"></script>
{{ ' {% if internal_error %} ' }}
<p class="error">
Une erreur interne est survenue pendant la soumission de votre offre.
Veuillez réessayer plus tard ou contactez-nous à <a href="mailto:calcul-contact@services.cnrs.fr">calcul-contact@services.cnrs.fr</a>.
</p>
{{ ' {% endif %} ' }}
{{ ' {% if errors.general %} <p class="error">{{ errors.general }}</p>{% endif %} ' }}
<p><span class="error">Les informations obligatoires sont indiquées par une *.</span></p>
<form name="job_offer_form" enctype="multipart/form-data" method="post" action="">
<P>
......@@ -68,9 +83,12 @@
<span class="error" name="error-description">{{ '{{errors.description}}' }}</span>
</p>
<p>
Fichier joint :
Fichier joint :
<input type="file" name="file" accept="{{ '{{file_accept}}' }}">
<span class="error" name="error-file">{{ '{{errors.attachment}}' }}</span>
{{ ' {% if form.has_attachment() %} ' }}
<span class="error" name="error-file">N'oubliez pas de re-déposer votre document.</span>
{{ ' {% endif %} ' }}
</p>
<p>
<input type="submit" name="submit" value="Soumettre">
......@@ -99,6 +117,8 @@
{% endif %}
' }}
</script>
{{ ' {% endif %} ' }}
</div>
</div>
......
Supports Markdown
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