More labels configuration

This commit is contained in:
Alexis Metaireau 2019-04-14 09:18:00 +02:00 committed by Yohan
parent 2e6cedca44
commit 6c2f07bc3c
9 changed files with 49 additions and 28 deletions

View file

@ -20,9 +20,10 @@ class Response(Response):
if self.request.cookies.get("message"):
context["message"] = json.loads(self.request.cookies["message"])
self.cookies.set("message", "")
context["config"] = config
self.body = env.get_template(template_name).render(*args, **context)
def xlsx(self, body, filename="epinamap.xlsx"):
def xlsx(self, body, filename=f"{config.SITE_NAME}.xlsx"):
self.body = body
mimetype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
self.headers["Content-Disposition"] = f'attachment; filename="{filename}"'
@ -128,10 +129,13 @@ async def sesame(request, response):
async def send_sesame(request, response, unprotected=True):
email = request.form.get("email")
token = utils.create_token(email)
emails.send(
emails.send_from_template(
env,
"access_granted",
email,
"Sésame Copanier",
emails.ACCESS_GRANTED.format(hostname=request.host, token=token.decode()),
f"Sésame {config.SITE_NAME}",
hostname=request.host,
token=token.decode(),
)
response.message(f"Un sésame vous a été envoyé à l'adresse '{email}'")
response.redirect = "/"
@ -150,6 +154,12 @@ async def set_sesame(request, response, token):
response.redirect = "/"
@app.route("/déconnexion", methods=["GET"])
async def logout(request, response):
response.cookies.set(name="token", value="", httponly=True)
response.redirect = "/"
@app.route("/", methods=["GET"])
async def home(request, response):
response.html("home.html", incoming=Delivery.incoming(), former=Delivery.former())

View file

@ -13,6 +13,9 @@ SMTP_LOGIN = ""
FROM_EMAIL = "copanier@epinamap.org"
STAFF = []
LOCALE = "fr_FR.UTF-8"
SITE_NAME = "Copanier"
SITE_DESCRIPTION = "Les paniers piano d'Épinamap"
EMAIL_SIGNATURE = "Les gentils copains d'Épinamap"
def init():

View file

@ -4,16 +4,6 @@ from email.message import EmailMessage
from . import config
ACCESS_GRANTED = """Hey ho!
Voici le sésame:
https://{hostname}/sésame/{token}
Les gentils copains d'Épinamap
"""
def send(to, subject, body, html=None):
msg = EmailMessage()
msg.set_content(body)
@ -35,16 +25,20 @@ def send(to, subject, body, html=None):
server.quit()
def send_from_template(env, template, to, subject, **params):
params["config"] = config
html = env.get_template(f"emails/{template}.html").render(**params)
txt = env.get_template(f"emails/{template}.txt").render(**params)
send(to, subject, body=txt, html=html)
def send_order(request, env, person, delivery, order):
html = env.get_template("emails/order_summary.html").render(
order=order, delivery=delivery, request=request
)
txt = env.get_template("emails/order_summary.txt").render(
order=order, delivery=delivery, request=request
)
send(
send_from_template(
env,
"order_summary",
person.email,
f"Copanier: résumé de la commande {delivery.producer}",
body=txt,
html=html,
f"{config.SITE_NAME} : résumé de la commande {delivery.producer}",
order=order,
delivery=delivery,
request=request
)

View file

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>{% if title %}{{ title }} - {% endif %}Commandes Epinamap</title>
<title>{% if title %}{{ title }} - {% endif %}{{ config.SITE_NAME }}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css"> -->
@ -17,7 +17,7 @@
<section class="notification {{ message[1] }}"><i class="icon-megaphone"></i> {{ message[0] }}</section>
{% endif %}
<section class="menu">
<h1><a href="/">Copanier</a> <small>Les paniers piano d'Épinamap</small></h1>
<h1><a href="/">{{ config.SITE_NAME }}</a> <small>{{ config.SITE_DESCRIPTION }}</small></h1>
<nav>
{% if request.user %}
{% if request.user.is_staff %}

View file

@ -0,0 +1,5 @@
<p>Hey ho!</p>
<p>Voici le sésame, <a href="https://{{ hostname }}/sésame/{{ token }}">clique ici</a> pour t'authentifier.</p>
<p>{{ config.EMAIL_SIGNATURE }}</p>

View file

@ -0,0 +1,7 @@
Hey ho!
Voici le sésame, clique dessus pour accéder à la commande :
https://{{ hostname }}/sésame/{{ token }}
{{ config.EMAIL_SIGNATURE }}

View file

@ -6,3 +6,4 @@
<p>Tu peux la modifier (jusqu'au {{ delivery.order_before|date }}) <a href="https://{{ request.host }}/livraison/{{ delivery.id }}/commander">en cliquant ici</a>.</p>
{% endif %}
<p>Bonne journée!</p>
<p>{{ config.EMAIL_SIGNATURE }}</p>

View file

@ -21,4 +21,5 @@ https://{{ request.host }}/livraison/{{ delivery.id }}/commander
{% endif %}
Bonne journée!
Bonne journée,
{{ config.EMAIL_SIGNATURE }}

View file

@ -1,4 +1,4 @@
<title>{% if title %}{{ title }} - {% endif %}Commandes Epinamap</title>
<title>{% if title %}{{ title }} - {% endif %}{{ config.SITE_NAME }}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">