diff roundup/cgi/templating.py @ 1120:c26471971d18

Exposed the Batch mechanism through the top-level "utils" variable. See the keyword.item template for an example of how it can be used.
author Richard Jones <richard@users.sourceforge.net>
date Wed, 11 Sep 2002 23:54:26 +0000
parents a95428868bf4
children ddbc5d1ad94f
line wrap: on
line diff
--- a/roundup/cgi/templating.py	Wed Sep 11 21:39:17 2002 +0000
+++ b/roundup/cgi/templating.py	Wed Sep 11 23:54:26 2002 +0000
@@ -150,7 +150,8 @@
              'request': request,
              'content': client.content,
              'db': HTMLDatabase(client),
-             'instance': client.instance
+             'instance': client.instance,
+             'utils': TemplatingUtils(client),
         }
         # add in the item if there is one
         if client.nodeid:
@@ -263,7 +264,6 @@
                     value = []
                 else:
                     value = None
-            print (prop, value)
             return htmlklass(self._client, '', prop, item, value)
 
         # no good
@@ -1316,7 +1316,8 @@
             if index + self.end < self.first: raise IndexError, index
             return self._sequence[index + self.end]
         
-        if index >= self.length: raise IndexError, index
+        if index >= self.length:
+            raise IndexError, index
 
         # move the last_item along - but only if the fetched index changes
         # (for some reason, index 0 is fetched twice)
@@ -1324,13 +1325,16 @@
             self.last_item = self.current_item
             self.last_index = index
 
-        # wrap the return in an HTMLItem
-        if self.classname == 'user':
-            klass = HTMLUser
-        else:
-            klass = HTMLItem
-        self.current_item = klass(self.client, self.classname,
-            self._sequence[index+self.first])
+        item = self._sequence[index + self.first]
+        if not isinstance(item, HTMLItem):
+            # "item" is actually just an id - wrap the return in an HTMLItem
+            if self.classname == 'user':
+                klass = HTMLUser
+            else:
+                klass = HTMLItem
+            item = klass(self.client, self.classname, item)
+
+        self.current_item = item
         return self.current_item
 
     def propchanged(self, property):
@@ -1362,3 +1366,12 @@
         self.sequence_length = l = len(self._sequence)
         return l
 
+class TemplatingUtils:
+    ''' Utilities for templating
+    '''
+    def __init__(self, client):
+        self.client = client
+    def Batch(self, classname, l, size, start, end=0, orphan=0, overlap=0):
+        return Batch(self.client, classname, l, size, start, end, orphan,
+            overlap)
+

Roundup Issue Tracker: http://roundup-tracker.org/