relocate exception in right place
This commit is contained in:
parent
0b4891703d
commit
ea8490747f
16
main.py
16
main.py
@ -1,7 +1,6 @@
|
|||||||
import bottle
|
import bottle
|
||||||
request = bottle.request
|
request = bottle.request
|
||||||
response = bottle.response
|
response = bottle.response
|
||||||
redirect = bottle.redirect
|
|
||||||
import smtplib
|
import smtplib
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
@ -17,11 +16,6 @@ import datetime # to name unsent mails
|
|||||||
|
|
||||||
##################################################### Bottle stuff ############################################
|
##################################################### Bottle stuff ############################################
|
||||||
|
|
||||||
# The exception that is thrown when an argument is missing
|
|
||||||
class MissingParameterException (Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class StripPathMiddleware(object):
|
class StripPathMiddleware(object):
|
||||||
'''
|
'''
|
||||||
Get that slash out of the request
|
Get that slash out of the request
|
||||||
@ -37,6 +31,11 @@ app = application = bottle.Bottle(catchall=False)
|
|||||||
|
|
||||||
|
|
||||||
##################################################### Configuration ############################################
|
##################################################### Configuration ############################################
|
||||||
|
|
||||||
|
# The exception that is thrown when an argument is missing
|
||||||
|
class MissingParameterException (Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
def get_env(var, default=None):
|
def get_env(var, default=None):
|
||||||
"""var is an env var name, default is the value to return if var does not exist. If no default and no value, an exception is raised."""
|
"""var is an env var name, default is the value to return if var does not exist. If no default and no value, an exception is raised."""
|
||||||
if var in os.environ:
|
if var in os.environ:
|
||||||
@ -92,13 +91,14 @@ mongodb_database = mongodb_client[mongodb_dbname]
|
|||||||
|
|
||||||
@app.post('/submit')
|
@app.post('/submit')
|
||||||
def submission ():
|
def submission ():
|
||||||
# Getting subject
|
# Getting token
|
||||||
if 'token' in request.forms:
|
if 'token' in request.forms:
|
||||||
token = request.forms.getunicode('token')
|
token = request.forms.getunicode('token')
|
||||||
else:
|
else:
|
||||||
response.status = 400
|
response.status = 400
|
||||||
return 'Le jeton d’autentification est requis'
|
return 'Le jeton d’autentification est requis'
|
||||||
|
|
||||||
|
# Getting mail address
|
||||||
if 'mail' in request.forms:
|
if 'mail' in request.forms:
|
||||||
from_address = request.forms.getunicode('mail')
|
from_address = request.forms.getunicode('mail')
|
||||||
else:
|
else:
|
||||||
@ -145,7 +145,7 @@ def submission ():
|
|||||||
|
|
||||||
|
|
||||||
# Redirection
|
# Redirection
|
||||||
#redirect(success_redirect_default)
|
#bottle.redirect(success_redirect_default)
|
||||||
origin = request.headers.get('origin')
|
origin = request.headers.get('origin')
|
||||||
return '<p>Mail envoyé !</p>' + ('<p>Retour au <a href="{}">formulaire de contact</a></p>'.format(origin) if origin else '')
|
return '<p>Mail envoyé !</p>' + ('<p>Retour au <a href="{}">formulaire de contact</a></p>'.format(origin) if origin else '')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user