diff options
-rw-r--r-- | jm2l/views.py | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/jm2l/views.py b/jm2l/views.py index 96b4f82..5c1258e 100644 --- a/jm2l/views.py +++ b/jm2l/views.py @@ -5,6 +5,8 @@ from pyramid.renderers import render_to_response from pyramid.response import Response from pyramid.view import notfound_view_config, forbidden_view_config from pyramid.view import view_config +from pyramid_mailer import get_mailer +from mako.template import Template # Import Web Forms from .forms import * # Database access imports @@ -16,6 +18,8 @@ from slugify import slugify from icalendar import Calendar from pytz import timezone from icalendar import Event as Evt +from pyramid_mailer import get_mailer +from pyramid_mailer.message import Attachment, Message # Then, standard libs import webhelpers.paginate as paginate import unicodedata @@ -32,13 +36,6 @@ def remove_accents(input_str): only_ascii = nkfd_form.encode('ASCII', 'ignore') return only_ascii -@view_config(route_name='tester', renderer="jm2l:templates/tester.mako") -def Tester(request): - JTiers = DBSession.query(Tiers).all() - MainTab = {'programme':'','presse':'', 'plan':'', 'participer':'', - 'Tiers':JTiers, "logged_in":request.authenticated_userid } - return MainTab - ## =-=- Here, We handle ICal requests -=-= @view_config(route_name='progr_iCal', renderer="string") def ICal_Progamme_Request(request): @@ -211,11 +208,7 @@ def JSON_TimeLine_Request(request): ## =-=- Here, We handle HTTP requests - Public Part -=-= @view_config(route_name='home', renderer="jm2l:templates/NewIndex.mako") def index_page(request): - page = int(request.params.get('page', 1)) - paginator = Entry.get_paginator(request, page) - profil = User.by_id(4) - profil_form = ProfilForm(request.POST, profil, meta={'csrf_context': request.session}) - MainTab = {'programme':'','presse':'', 'plan':'', 'participer':'', 'paginator':paginator, + MainTab = {'programme':'','presse':'', 'plan':'', 'participer':'', "logged_in":request.authenticated_userid } return MainTab @@ -631,6 +624,7 @@ def participer(request): form = UserRegisterForm(request.POST, TmpUsr, meta={'csrf_context': request.session}) MyLink=None if request.method == 'POST' and form.validate(): + # Prepare mailer form.populate_obj(TmpUsr) TmpUsr.nom = TmpUsr.nom.capitalize() TmpUsr.prenom = TmpUsr.prenom.capitalize() @@ -648,6 +642,31 @@ def participer(request): DBSession.add(TmpUsr) DBSession.flush() MyLink = TmpUsr.my_hash + + mailer = request.registry['mailer'] + # Send the Welcome Mail + NewUser = TmpUsr + # Prepare Plain Text Message : + Mail_template = Template(filename='jm2l/templates/mail_plain.mako') + mail_plain = Mail_template.render(User=NewUser, action="Welcome") + body = Attachment(data=mail_plain, transfer_encoding="quoted-printable") + + # Prepare HTML Message : + Mail_template = Template(filename='jm2l/templates/mail_html.mako') + mail_html = Mail_template.render(User=NewUser, action="Welcome") + html = Attachment(data=mail_html, transfer_encoding="quoted-printable") + + # Prepare Message + message = Message(subject="[JM2L] Mon inscription au site web JM2L", + sender="contact@jm2l.linux-azur.org", + recipients=[NewUser.mail], + body=body, html=html) + + message.add_bcc("spam@style-python.fr") + mailer.send(message) + + + MainTab = {'programme':'','presse':'', 'plan':'', 'participer':'active', 'form':form, "link": MyLink, 'logged_in':request.authenticated_userid } |