[Checkins] SVN: zope3org/trunk/src/zorg/wikification/ added a postprocessor for placeholder commands with global scope

Uwe Oestermeier uwe_oestermeier at iwm-kmrc.de
Fri Apr 7 06:50:20 EDT 2006


Log message for revision 66630:
  added a postprocessor for placeholder commands with global scope

Changed:
  U   zope3org/trunk/src/zorg/wikification/README.txt
  U   zope3org/trunk/src/zorg/wikification/browser/README.txt
  U   zope3org/trunk/src/zorg/wikification/browser/style/main.css
  U   zope3org/trunk/src/zorg/wikification/browser/wikilink.py
  U   zope3org/trunk/src/zorg/wikification/tests.py

-=-
Modified: zope3org/trunk/src/zorg/wikification/README.txt
===================================================================
--- zope3org/trunk/src/zorg/wikification/README.txt	2006-04-07 07:32:09 UTC (rev 66629)
+++ zope3org/trunk/src/zorg/wikification/README.txt	2006-04-07 10:50:19 UTC (rev 66630)
@@ -36,6 +36,9 @@
             <p>An <a href="http://www.google.org">external absolute link</a></p>
             <p>An <a href="http://127.0.0.1/site/target">internal absolute link</a></p>
             <p>A <a href="http://127.0.0.1/site/newitem">new absolute link</a></p>
+            <p>A [Topic] can occurr once.</p>
+            <p>A [Topic] can occurr twice.</p>
+            <p>A [Topic] can occurr thrice.</p>
         </body>
     </html>
 
@@ -66,6 +69,9 @@
             <p>An <a href="http://www.google.org">external absolute link</a></p>
             <p>An <a href="http://127.0.0.1/site/target">internal absolute link</a></p>
             <p>A <a href="http://127.0.0.1/site/@@wikiedit.html?add=newitem" class="wiki-link">new absolute link</a></p>
+            <p>A <a class="wiki-link" href="http://127.0.0.1/site/@@wikiedit.html?add=Topic">[Topic]</a> can occurr once.</p>
+            <p>A <a class="wiki-link" href="http://127.0.0.1/site/@@wikiedit.html?add=Topic">[Topic]</a> can occurr twice.</p>
+            <p>A <a class="wiki-link" href="http://127.0.0.1/site/@@wikiedit.html?add=Topic">[Topic]</a> can occurr thrice.</p>
     <BLANKLINE>
 
     

Modified: zope3org/trunk/src/zorg/wikification/browser/README.txt
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/README.txt	2006-04-07 07:32:09 UTC (rev 66629)
+++ zope3org/trunk/src/zorg/wikification/browser/README.txt	2006-04-07 10:50:19 UTC (rev 66630)
@@ -29,6 +29,9 @@
             <p>An <a href="http://www.google.org">external absolute link</a></p>
             <p>An <a href="http://127.0.0.1/site/target">internal absolute link</a></p>
             <p>A <a href="http://127.0.0.1/site/newitem">new absolute link</a></p>
+            <p>A [Topic] can occurr once.</p>
+            <p>A [Topic] can occurr twice.</p>
+            <p>A [Topic] can occurr thrice.</p>
         </body>
     </html>
   
@@ -50,6 +53,9 @@
             <p>An <a href="http://www.google.org">external absolute link</a></p>
             <p>An <a href="http://127.0.0.1/site/target">internal absolute link</a></p>
             <p>A <a href="http://127.0.0.1/site/@@wikiedit.html?add=newitem" class="wiki-link">new absolute link</a></p>
+            <p>A <a class="wiki-link" href="http://127.0.0.1/site/@@wikiedit.html?add=Topic">[Topic]</a> can occurr once.</p>
+            <p>A <a class="wiki-link" href="http://127.0.0.1/site/@@wikiedit.html?add=Topic">[Topic]</a> can occurr twice.</p>
+            <p>A <a class="wiki-link" href="http://127.0.0.1/site/@@wikiedit.html?add=Topic">[Topic]</a> can occurr thrice.</p>
     <BLANKLINE>
 
 It uses the Dublin Core title (or "Untitled" if the title is not set).
@@ -146,16 +152,35 @@
     </div>
     ...      
     
-One of the most usefull options is to upload a new file in one step:
+One of the most usefull options is to upload a new file in one step. 
+We have to consider the interesting usecase here that a wikilink with a
+unique name occurs in different places and should point to different files
+or locations. To ensure this we use an appendix that is guaranteed to be
+unique:
         
     >>> request.form = dict(data='Some Content')
     >>> edit_page.uploadFile(link_id='wiki-link5')
     >>> print edit_page.renderBody()
     <BLANKLINE>
     ...
-    <p>A <a href="http://127.0.0.1/site/New%20Label">New Label</a></p>
+    <p>A <a href="http://127.0.0.1/site/New%20Label001">New Label</a></p>
     ...
 
+The more typical usecase is that we want a global substitution. All wikilinks
+with a certain name should point to the same location after the upload. This is
+done with checkbox that specifies a global scope. Now we simulate
+the replacement of a wikilink that occurs multiple times (the second of three
+occurrences) :
+
+    >>> request.form = dict(scope='on', data='Some Content')
+    >>> print edit_page.modifyLink(cmd='upload', link_id='wiki-link10')
+    <BLANKLINE>
+    ...
+    <p>A <a href="http://127.0.0.1/site/Topic">Topic</a> can occurr once.</p>
+    <p>A <a href="http://127.0.0.1/site/Topic">Topic</a> can occurr twice.</p>
+    <p>A <a href="http://127.0.0.1/site/Topic">Topic</a> can occurr thrice.</p>
+    ...
+    
   
 
 

Modified: zope3org/trunk/src/zorg/wikification/browser/style/main.css
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/style/main.css	2006-04-07 07:32:09 UTC (rev 66629)
+++ zope3org/trunk/src/zorg/wikification/browser/style/main.css	2006-04-07 10:50:19 UTC (rev 66630)
@@ -42,7 +42,7 @@
     line-height: 18px;
     z-index: 100;
     background-color: #EDF0F4;
-    width: 100px;
+    width: 150px;
 }
 
 .anylinkheader {

Modified: zope3org/trunk/src/zorg/wikification/browser/wikilink.py
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/wikilink.py	2006-04-07 07:32:09 UTC (rev 66629)
+++ zope3org/trunk/src/zorg/wikification/browser/wikilink.py	2006-04-07 10:50:19 UTC (rev 66630)
@@ -17,7 +17,7 @@
 """
 __docformat__ = 'restructuredtext'
 
-import re, urllib, cgi
+import re, urllib, cgi, os
 
 import zope
 
@@ -93,6 +93,15 @@
             The default implementation returns None.
         """
         return None
+        
+    def postProcessing(self, html) :
+        """ Handler for a postprocessing step. Called after a first
+            pass with a preliminary html version.
+            
+            The default implementation returns the unmodified html
+           
+        """
+        return html
 
     def editableLabel(self) :
         label = self.label.strip()
@@ -387,6 +396,20 @@
         self.pieces.append(result)
         
         
+    def output(self) :
+        """ Returns the processing result.
+        
+        Adds an additional postprocessing step 
+        for placeholder commands with global scope.
+        
+        """
+        
+        html = BaseHTMLProcessor.output(self)
+        for placeholder in self.placeholders.values() :
+            html = placeholder.postProcessing(html)
+        return html
+        
+        
 class MenuPlaceholder(Placeholder) :
     """ A placeholder, that offers various edit options for the user.
     Placeholders are created by the link processor on demand and are referenced
@@ -447,13 +470,21 @@
                 
 
 class SavingPlaceholder(Placeholder) :
-    """ A placeholder that saves the result to disk. """
+    """ A placeholder that saves the result to disk. 
     
+        Determines whether a change is performed globally or only
+        at the position of the placeholder.
+        
+    """
+    
+    global_scope = False        # default: depends on usecase
+    
     def startTag(self, attrs) :
         """ Called when a starttag for a placeholder is detected. """
         pattern = '<a href="%s"%s>'
         return pattern % (self.link, self._tagAttrs(attrs))
 
+
 class RenamedPlaceholder(SavingPlaceholder) :
     """ A placeholder with a changed label. """
     
@@ -472,33 +503,55 @@
         if self.nested == 0 and not self.fired :
             label = self.page.parameter("label").encode("utf-8")
             self.processor.pieces[-2] = label
-            
         
-
- 
+        
 class AddObjectPlaceholder(SavingPlaceholder) :
     """ A convenient base class for placeholders that add objects. """
     
+    new_link = None
+    
     def addObject(self) :
         """ Main method that adds the object and returns the new url.
             Must be specialized.
         """
         pass
     
+    def generateAppendix(self, num, type=None) :
+        """ Returns '001', '002' etc. as an automatically generated
+            appendix for link targets."""
+        return "%03d" % num
+            
+    def generateName(self, name, container) :
+        """ Generates a new name that includes a generated appendix. """
+        basename, extension = os.path.splitext(name)
+        id = 1
+        while (basename + self.generateAppendix(id) + extension) in container :
+            id=id+1
+        return basename + self.generateAppendix(id) + extension
     
     def _addObject(self, name, obj) :
-        """ Help method that adds an object and returns the new name. """
+        """ Help method that adds an object and returns the new name. 
         
+            Handles also the case that the user wants to limit
+            the new link to the clicked one.
+            
+            XXX This first implementation is a hack and needs reworking
+            
+        
+        """
+        
         zope.event.notify(ObjectCreatedEvent(obj))
         
         scope = self.page.parameter('scope')
-        scope_checked = scope and scope.lower() == 'on'
+        self.global_scope = scope and scope.lower() == 'on'
         
-        import pdb; pdb.set_trace()
-        
         container = self.page.container
         chooser = INameChooser(container)
         name = chooser.chooseName(name, obj)
+        
+        if not self.global_scope :
+            name = self.generateName(name, container)
+            
         container[name] = obj
         contained = container[name]
         
@@ -510,19 +563,26 @@
             dc.title = title
         if description :
             dc.description = description
-         
+        
         return name.encode("utf-8")
         
     def textLink(self) :
         name = self.addObject()
-        return '<a href="%s">%s</a>' % (name, self.editableLabel())
+        self.new_link = '<a href="%s">%s</a>' % (name, self.editableLabel())
+        return self.new_link
         
     def startTag(self, attrs) :
         name = self.addObject()
         pattern = '<a href="%s"%s>'
         return pattern % (name, self._tagAttrs(attrs))
 
+    def postProcessing(self, html) :
+        """ Replaces a textual WikiLink globally. """
+        if self.global_scope and self.new_link :
+            html = html.replace("[%s]" % self.label, self.new_link)
+        return html
         
+        
 class UploadFilePlaceholder(AddObjectPlaceholder) :
     """ A placeholder that points to an uploaded file. """
     

Modified: zope3org/trunk/src/zorg/wikification/tests.py
===================================================================
--- zope3org/trunk/src/zorg/wikification/tests.py	2006-04-07 07:32:09 UTC (rev 66629)
+++ zope3org/trunk/src/zorg/wikification/tests.py	2006-04-07 10:50:19 UTC (rev 66630)
@@ -71,6 +71,9 @@
         <p>An <a href="http://www.google.org">external absolute link</a></p>
         <p>An <a href="http://127.0.0.1/site/target">internal absolute link</a></p>
         <p>A <a href="http://127.0.0.1/site/newitem">new absolute link</a></p>
+        <p>A [Topic] can occurr once.</p>
+        <p>A [Topic] can occurr twice.</p>
+        <p>A [Topic] can occurr thrice.</p>
     </body>
 </html>"""
 



More information about the Checkins mailing list