# -*- 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.security import ( authenticated_userid, remember, forget, ) from pyramid.httpexceptions import ( HTTPFound, HTTPNotFound, HTTPForbidden, ) from pyramid_mailer import get_mailer from pyramid_mailer.message import Message, Attachment from datetime import * import hashlib from sqlalchemy.exc import DBAPIError from ..security import groupfinder from ..models.members import ( get_member_by_email, ) import json def to_decimal(x): import decimal return decimal.Decimal(str(x)) def to_euro(x): """Takes a float and returns a string""" #if x == 0: # return "" #else: return (u"%.2f €" % x).replace('.', ',') def to_int(x): try: number = int(x.replace(',', '.')) return number except ValueError: return 0 def to_percent(x): """Takes a float and returns a string""" return (u"%.2f " % x).replace('.', ',') + "%" @view_config(route_name='home', renderer='../templates/home.pt', permission='view') def home(request): logged_in = authenticated_userid(request) # lire la fiche du membre membre = get_member_by_email(request, logged_in) if not membre: request.session.flash(u"Utilisateur non trouvé : %s" % logged_in, 'warning') return HTTPFound(location=request.route_url('/home')) return { 'page_title': u"%s %s" % (membre.prenom, membre.nom), } def envoyerMail(request, destinataire, objet, corps): body = u""" %s Cordialement, gestion.entreprise-dumas.com """ % (corps) message = Message(subject=u"[Ent. Dumas] %s" % objet, sender=request.registry.settings['mondumas.admin_email'], body=body) message.add_recipient(destinataire) mailer = get_mailer(request) mailer.send_immediately(message)