Merge branch 'master' into mybranch
[cascardo/ema.git] / eventos / views.py
index 36c0004..e52fb1d 100644 (file)
@@ -27,6 +27,7 @@ from django.template import RequestContext, Context, loader
 from eventos.models import Palestrante, Trabalho, TipoTrabalho, Trilha, Evento, Improve
 from eventos.forms import RegisterSpeaker
 from django.db.models import Q
+import smtplib
 
 forbidden = \
     HttpResponseForbidden('<h2>You are not allowed to do this action.<h2>')
@@ -306,7 +307,8 @@ def talk_improve(request, tid):
         return forbidden
 
     talk = get_object_or_404(Trabalho, pk=tid)
-    speaker = talk.palestrante
+    speakers = [i for i in talk.outros_palestrantes.all()]
+    speakers = [ talk.palestrante ] + speakers
     improve = Improve.objects.filter(trabalho=talk)
 
     # building the form
@@ -321,6 +323,18 @@ def talk_improve(request, tid):
         if cleaned['trabalho'].evento.id != event.id:
             return forbidden
 
+        emails = [i.email for i in speakers]
+        user = cleaned['usuario'].get_full_name()
+        comments = cleaned['comentario']
+        msg = (u"From: emsl@minaslivre.org\r\nTo: %s\r\n"
+               u"Subject: Comentário em seu Trabalho EMSL 2008\r\n"
+               u"Content-Type: text/plain; charset=utf-8\r\n"
+               u"\r\n %s comentou seu trabalho.\r\n%s\r\r\n"
+               % (", ".join(emails), user, comments))
+        smtp = smtplib.SMTP("localhost")
+        smtp.sendmail("emsl@minaslivre.org", emails, str(msg.encode("utf8")))
+        smtp.quit()
+
         instance = form.save()
         return HttpResponseRedirect('/improve/%d/' % talk.id)