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
|
||||
request = bottle.request
|
||||
response = bottle.response
|
||||
redirect = bottle.redirect
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
@ -17,11 +16,6 @@ import datetime # to name unsent mails
|
||||
|
||||
##################################################### Bottle stuff ############################################
|
||||
|
||||
# The exception that is thrown when an argument is missing
|
||||
class MissingParameterException (Exception):
|
||||
pass
|
||||
|
||||
|
||||
class StripPathMiddleware(object):
|
||||
'''
|
||||
Get that slash out of the request
|
||||
@ -37,6 +31,11 @@ app = application = bottle.Bottle(catchall=False)
|
||||
|
||||
|
||||
##################################################### Configuration ############################################
|
||||
|
||||
# The exception that is thrown when an argument is missing
|
||||
class MissingParameterException (Exception):
|
||||
pass
|
||||
|
||||
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."""
|
||||
if var in os.environ:
|
||||
@ -92,13 +91,14 @@ mongodb_database = mongodb_client[mongodb_dbname]
|
||||
|
||||
@app.post('/submit')
|
||||
def submission ():
|
||||
# Getting subject
|
||||
# Getting token
|
||||
if 'token' in request.forms:
|
||||
token = request.forms.getunicode('token')
|
||||
else:
|
||||
response.status = 400
|
||||
return 'Le jeton d’autentification est requis'
|
||||
|
||||
# Getting mail address
|
||||
if 'mail' in request.forms:
|
||||
from_address = request.forms.getunicode('mail')
|
||||
else:
|
||||
@ -145,7 +145,7 @@ def submission ():
|
||||
|
||||
|
||||
# Redirection
|
||||
#redirect(success_redirect_default)
|
||||
#bottle.redirect(success_redirect_default)
|
||||
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 '')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user