copanier/copanier/utils.py
Alexis MÃtaireau b451a82c7b Reorganize the files,
I've split everything in different concepts (groups, login, products and delivery) so that it's easier to find what we're looking for (the __init__.py file was really too big).
2020-03-13 18:58:54 +01:00

37 lines
768 B
Python

from datetime import datetime, timezone, timedelta
import jwt
from . import config
def utcnow():
return datetime.now(timezone.utc)
def create_token(email):
return jwt.encode(
{"sub": str(email), "exp": utcnow() + timedelta(days=7)},
config.SECRET,
config.JWT_ALGORITHM,
)
def read_token(token):
try:
return jwt.decode(token, config.SECRET, algorithms=[config.JWT_ALGORITHM])
except (jwt.DecodeError, jwt.ExpiredSignatureError):
return {}
def prefix(string, delivery):
date = delivery.to_date.strftime("%Y-%m-%d")
return f"{config.SITE_NAME}-{date}-{string}"
def date_filter(value):
return value.strftime(r"%A %d %B")
def time_filter(value):
return value.strftime(r"%H:%M")