Files
2021-12-10 14:42:59 +01:00

97 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf8 -*-
from pyramid.view import (
view_config,
)
from pyramid_mailer import get_mailer
from pyramid_mailer.message import Message, Attachment
from ..models.members import (
get_member_by_email
)
from ..models.contents import (
get_docs_bytopic
)
def to_decimal(x):
import decimal
return decimal.Decimal(str(x))
def to_euro(x):
"""Takes a float and returns a string"""
return (u"%.2f" % x).replace('.', ',')
def to_usd(x):
"""Takes a float and returns a string"""
return to_euro(x).replace('','$')
def to_int(x):
try:
number = int(x.replace(',', '.'))
return number
except ValueError:
return 0
def to_percent(x, d):
"""Takes a float and returns a string"""
if x == 0:
pc = ''
elif d == 2:
pc = "%.2f " % x
elif d == 3:
pc = "%.3f " % x
else:
pc = "%.1f " % x
if len(pc) > 0:
pc += "%"
return pc.replace('.', ',')
@view_config(route_name='home', renderer='../templates/home.pt')
def home(request):
logged_in = request.authenticated_userid
member = get_member_by_email(request, 'ctphuoc@gmail.com')
id_photo = member.photo_instagram
# lire toutes les docs
items = get_docs_bytopic(request, 'home', logged_in)
return {
'page_title': "Méditer, cest ouvrir la cage",
'items': items,
'id_photo': id_photo,
}
@view_config(route_name='apropos', renderer='../templates/apropos.pt')
def apropos(request):
return {
'page_title': "A propos",
}
def envoyerMail(request, destinataire, objet, corps):
body = """
%s
Cordialement,
monaa.caotek.fr
""" % (corps)
message = Message(subject=u"[Mes Avoirs] %s" % objet,
sender=request.registry.settings['caotek_mesavoirs.admin_email'],
body=body)
message.add_recipient(destinataire)
mailer = get_mailer(request)
mailer.send_immediately(message)