[Twisted-Python] Minor addition to woven.widgets.ExpandMacro

Alex Levy mesozoic at polynode.com
Mon Jun 23 12:13:15 EDT 2003


The following diff does two things which are fairly unrelated.

One change allows woven.widgets.ExpandMacro to receive a 'macroTemplate'
argument instead of requiring a macro's template to reside in a file
somewhere.  I find this Very Useful(tm).

The other is a typo/glitch that I pointed out to Glyph a while back and he
hasn't fixed yet.  <nudge/><nudge/>  ;)


Index: twisted/web/woven/widgets.py
===================================================================
RCS file: /cvs/Twisted/twisted/web/woven/widgets.py,v
retrieving revision 1.91
diff -u -r1.91 widgets.py
--- twisted/web/woven/widgets.py	23 Jun 2003 07:38:48 -0000	1.91
+++ twisted/web/woven/widgets.py	23 Jun 2003 16:03:48 -0000
@@ -933,17 +933,23 @@
             <h3><span slot="greeting" />, <span slot="greetee" />!</h3>
         </div>
     """
-    def __init__(self, model, macroFile="", macroFileDirectory="", macroName="", **kwargs):
+    def __init__(self, model, macroTemplate="", macroFile="", macroFileDirectory="", macroName="", **kwargs):
+        self.macroTemplate = macroTemplate
         self.macroFile=macroFile
         self.macroFileDirectory=macroFileDirectory
         self.macroName=macroName
         Widget.__init__(self, model, **kwargs)
 
     def generate(self, request, node):
-        templ = view.View(
-            self.model,
-            templateFile=self.macroFile, 
-            templateDirectory=self.macroFileDirectory).lookupTemplate(request)
+        if self.macroTemplate:
+            templ = view.View(
+                self.model,
+                template = self.macroTemplate).lookupTemplate(request)
+        else:
+            templ = view.View(
+                self.model,
+                templateFile=self.macroFile, 
+                templateDirectory=self.macroFileDirectory).lookupTemplate(request)
 
         ## We are going to return the macro node from the metatemplate,
         ## after replacing any slot= nodes in it with fill-slot= nodes from `node'
Index: twisted/world/structfile.py
===================================================================
RCS file: /cvs/Twisted/twisted/world/structfile.py,v
retrieving revision 1.5
diff -u -r1.5 structfile.py
--- twisted/world/structfile.py	8 Jun 2003 11:27:39 -0000	1.5
+++ twisted/world/structfile.py	23 Jun 2003 16:03:48 -0000
@@ -195,7 +195,7 @@
         for row in self:
             f.write('<tr><td>')
             f.write('</td><td>'.join([str(x) for x in row]))
-            f.write('</tr>')
+            f.write('</td></tr>')
         f.write("</table>")
 
     def close(self):



-- 
Alex Levy
WWW: http://mesozoic.geecs.org

"Never let your sense of morals prevent you from doing what is right."
 -- Salvor Hardin, Isaac Asimov's _Foundation_





More information about the Twisted-Python mailing list