[CalendarServer-changes] [7902] CalendarServer/branches/users/glyph/imip-and-admin-html/ twistedcaldav/mail.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 11 21:40:30 PDT 2011


Revision: 7902
          http://trac.macosforge.org/projects/calendarserver/changeset/7902
Author:   glyph at apple.com
Date:     2011-08-11 21:40:30 -0700 (Thu, 11 Aug 2011)
Log Message:
-----------
make the original test pass!

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py

Modified: CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py
===================================================================
--- CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py	2011-08-12 04:40:19 UTC (rev 7901)
+++ CalendarServer/branches/users/glyph/imip-and-admin-html/twistedcaldav/mail.py	2011-08-12 04:40:30 UTC (rev 7902)
@@ -43,7 +43,9 @@
 from twisted.python.usage import Options, UsageError
 
 from twisted.web import client
-from twisted.web.template import XMLString, TEMPLATE_NAMESPACE
+from twisted.web.template import (
+    XMLString, TEMPLATE_NAMESPACE, Element, renderer, flattenString
+)
 from twisted.web.microdom import parseString
 from twisted.web.microdom import Text as DOMText, Element as DOMElement
 
@@ -120,7 +122,7 @@
     <p>
     <h3>%(timeLabel)s:</h3> %(timeInfo)s %(durationInfo)s
     </p>
-    """
+    """.encode("utf-8")
 
 
 htmlInviteTemplate = u"""<html>
@@ -146,7 +148,7 @@
     <p>
     <h3>%(attLabel)s:</h3> %(htmlAttendees)s
     </p>
-    """
+    """.encode("utf-8")
 
 def _visit(document, node):
     if isinstance(node, DOMText):
@@ -193,7 +195,8 @@
         "t:render", rendererName
     )
     _walk(document, document)
-    return document.toxml()
+    result = document.toxml()
+    return result
 
 
 
@@ -1460,8 +1463,19 @@
 
             with open(templatePath) as templateFile:
                 htmlTemplate = templateFile.read()
-        htmlText = htmlTemplate % details
 
+        class EmailElement(Element):
+            loader = StringFormatTemplateLoader(lambda : StringIO(htmlTemplate),
+                                                "email")
+
+            @renderer
+            def email(self, request, tag):
+                return tag.fillSlots(**details)
+
+        textCollector = []
+        flattenString(None, EmailElement()).addCallback(textCollector.append)
+        htmlText = textCollector[0]
+
         # If the template refers to an icon in a cid: link, it needs to be added
         # in the MIME.
         addIcon = (htmlTemplate.find("cid:%(iconName)s") != -1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110811/547c17aa/attachment.html>


More information about the calendarserver-changes mailing list