Files
caotek_monaa/caotek_mesavoirs/views/default.py
2021-09-11 10:21:09 +02:00

112 lines
2.3 KiB
Python
Raw 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.response import Response
from pyramid.renderers import render, get_renderer
from pyramid.view import (
view_config,
forbidden_view_config,
)
from pyramid.httpexceptions import (
HTTPFound,
HTTPNotFound,
HTTPForbidden,
)
from pyramid_mailer import get_mailer
from pyramid_mailer.message import Message, Attachment
from sqlalchemy.exc import DBAPIError
from ..security import groupfinder
from ..models.members import (
get_member_by_email
)
from ..models.contents import (
get_docs_bytopic
)
# import datetime
import time
import hashlib
import locale
def to_decimal(x):
import decimal
return decimal.Decimal(str(x))
def to_euro(x):
"""Takes a float and returns 12 345,67 €"""
locale.setlocale(locale.LC_ALL,'')
return locale.currency(x, True, True)
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, 'blog', 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)