[Zope3-checkins] CVS: zopeproducts/zwiki - wiki_toc.pt:1.1 TODO.txt:1.8 browser.py:1.8 configure.zcml:1.12

Stephan Richter srichter@cbu.edu
Wed, 9 Apr 2003 10:33:57 -0400


Update of /cvs-repository/zopeproducts/zwiki
In directory cvs.zope.org:/tmp/cvs-serv10960

Modified Files:
	TODO.txt browser.py configure.zcml 
Added Files:
	wiki_toc.pt 
Log Message:
Added Table of Contents for Wiki.


=== Added File zopeproducts/zwiki/wiki_toc.pt ===
<html metal:use-macro="views/standard_macros/page">
  <head>
    <style metal:fill-slot="style_slot">
    </style>
  </head>
  <body i18n:domain="wiki">
    <div metal:fill-slot="body">

      <h1 i18n:translate="">Wiki Table of Contents</h1>

      <p tal:replace="structure view/toc">This is a table of contents.</p>

    </div>
  </body>
</html>


=== zopeproducts/zwiki/TODO.txt 1.7 => 1.8 ===
--- zopeproducts/zwiki/TODO.txt:1.7	Wed Apr  9 09:41:29 2003
+++ zopeproducts/zwiki/TODO.txt	Wed Apr  9 10:33:57 2003
@@ -28,8 +28,6 @@
     - Create a Management screen (advancedform) that is accessible for users
       without management rights.
 
-    - Table of Contents including unlinked and unparented WikiPages.
-
     - Improve 'Add Comment' screen to show existing Wiki content.
 
 


=== zopeproducts/zwiki/browser.py 1.7 => 1.8 ===
--- zopeproducts/zwiki/browser.py:1.7	Wed Apr  9 09:41:29 2003
+++ zopeproducts/zwiki/browser.py	Wed Apr  9 10:33:57 2003
@@ -21,6 +21,7 @@
 from zope.app.interfaces.dublincore import ICMFDublinCore
 
 from zope.component import getAdapter, getView, getService, createObject
+from zope.proxy.context import ContextWrapper
 from zope.app.browser.container.adding import Adding
 from zope.app.browser.form.widget import ListWidget
 from zope.app.form.widget import CustomWidget
@@ -50,6 +51,31 @@
 class WikiAdding(Adding):
     """Custom adding view for NewsSite objects."""
     menu_id = "add_wiki"
+
+
+class TableOfContents:
+    """Table of contents for a Wiki"""
+
+    def toc(self):
+        """Generate a table of contents."""
+        children = []
+
+        for name, page in self.context.items():
+            wrapped = ContextWrapper(page, self.context, name=name)
+            hier = getAdapter(wrapped, IWikiPageHierarchy)
+            if hier.getParents() == ():
+                children.append((wrapped, hier.findChildren())) 
+        return self._branchHTML(children)
+
+    def _branchHTML(self, children):
+        html = '<ul>\n'
+        for child, subs in children:
+            html += ' <li><a href="../%s">%s</a></li>\n' %(objectName(child),
+                                                           objectName(child))
+            if subs:
+                html += self._branchHTML(subs)
+        html += '</ul>\n'
+        return html
 
 
 class SourceTypeWidget(ListWidget):


=== zopeproducts/zwiki/configure.zcml 1.11 => 1.12 ===
--- zopeproducts/zwiki/configure.zcml:1.11	Wed Apr  9 09:41:29 2003
+++ zopeproducts/zwiki/configure.zcml	Wed Apr  9 10:33:57 2003
@@ -83,6 +83,15 @@
       <browser:page name="action.html" attribute="action" />
   </browser:view>
 
+  <browser:page
+      name="toc.html"
+      for=".interfaces.IWiki"
+      class=".browser.TableOfContents"
+      template="wiki_toc.pt"
+      permission="zope.View"
+      menu="zmi_views"
+      title="TOC"/>
+
 
   <browser:menuItem menu="add_content"
       for="zope.app.interfaces.container.IAdding"