[Zope-CVS] SVN: zversioning/trunk/src/versioning/ Get History for ZODB

Volker Bachschneider vbachs at dzug.org
Mon Oct 11 07:22:52 EDT 2004


Log message for revision 27963:
  Get History for ZODB
  


Changed:
  U   zversioning/trunk/src/versioning/demo/browser/info.pt
  U   zversioning/trunk/src/versioning/demo/interfaces.py
  U   zversioning/trunk/src/versioning/demo/vproposal.py
  A   zversioning/trunk/src/versioning/getHistories.py


-=-
Modified: zversioning/trunk/src/versioning/demo/browser/info.pt
===================================================================
--- zversioning/trunk/src/versioning/demo/browser/info.pt	2004-10-11 11:17:54 UTC (rev 27962)
+++ zversioning/trunk/src/versioning/demo/browser/info.pt	2004-10-11 11:22:51 UTC (rev 27963)
@@ -4,23 +4,23 @@
 
   <h1 tal:content="context/title">Versionable Proposal</h1>
 
-    <div><h3 i18n:translate="">Use Cases</h3>
-        <div tal:content="structure context/usecase | nothing">
+    <div><h4 i18n:translate="">Use Cases</h4>
+        <div tal:content="structure context/rusecase | nothing">
            What Situations we will solve
         </div><a href="./@@EditUseCase.html" i18n:translate="">Edit</a>
         </div>
-    <div><h3 i18n:translate="">Concept</h3>
-        <div tal:content="structure context/concept | nothing">
+    <div><h4 i18n:translate="">Concept</h4>
+        <div tal:content="structure context/rconcept | nothing">
            Technical Concept
         </div><a href="./@@EditConcept.html" i18n:translate="">Edit</a>
         </div>
-    <div><h3 i18n:translate="">Todo</h3>
-        <div tal:content="structure context/todo | nothing">
+    <div><h4 i18n:translate="">Todo</h4>
+        <div tal:content="structure context/rtodo | nothing">
            Steps to go
         </div><a href="./@@EditTodo.html" i18n:translate="">Edit</a>
         </div>
-    <div><h3 i18n:translate="">Issues</h3>
-        <div tal:content="structure context/issues | nothing">
+    <div><h4 i18n:translate="">Issues</h4>
+        <div tal:content="structure context/rissues | nothing">
            Open Issues
         </div><a href="./@@EditIssues.html" i18n:translate="">Edit</a>
         </div>

Modified: zversioning/trunk/src/versioning/demo/interfaces.py
===================================================================
--- zversioning/trunk/src/versioning/demo/interfaces.py	2004-10-11 11:17:54 UTC (rev 27962)
+++ zversioning/trunk/src/versioning/demo/interfaces.py	2004-10-11 11:22:51 UTC (rev 27963)
@@ -12,4 +12,15 @@
     concept = Text(title=_("Concept"),required=False)
     todo = Text(title=_("Todo"),required=False)
     issues = Text(title=_("Open Issues"),required=False)
-        
\ No newline at end of file
+        
+    def rusecase():
+        """Render usecase to HTML"""    
+        
+    def rconcept():
+        """Render usecase to HTML"""    
+
+    def rtodo():
+        """Render usecase to HTML"""
+        
+    def rissues():
+        """Render usecase to HTML"""        
\ No newline at end of file

Modified: zversioning/trunk/src/versioning/demo/vproposal.py
===================================================================
--- zversioning/trunk/src/versioning/demo/vproposal.py	2004-10-11 11:17:54 UTC (rev 27962)
+++ zversioning/trunk/src/versioning/demo/vproposal.py	2004-10-11 11:22:51 UTC (rev 27963)
@@ -1,5 +1,6 @@
 import persistent
 import zope.interface
+from zope.app.renderer.rest import ReStructuredTextToHTMLRenderer
 from zope.app.dublincore.interfaces import IZopeDublinCore
 from versioning.demo.interfaces import IVProposal
 
@@ -24,6 +25,22 @@
         """Get proposal title in Dublin Core."""
         dc = IZopeDublinCore(self)
         return dc.title
+
+    def rusecase(self):
+        html = ReStructuredTextToHTMLRenderer(self.usecase.encode('utf-8'),None)
+        return unicode(html.render(),'utf-8')
+
+    def rconcept(self):
+        html = ReStructuredTextToHTMLRenderer(self.concept.encode('utf-8'),None)
+        return unicode(html.render(),'utf-8')
+
+    def rtodo(self):
+        html = ReStructuredTextToHTMLRenderer(self.todo.encode('utf-8'),None)
+        return unicode(html.render(),'utf-8')
+
+    def rissues(self):
+        html = ReStructuredTextToHTMLRenderer(self.issues.encode('utf-8'),None)
+        return unicode(html.render(),'utf-8')
         
     title=property(getTitle,setTitle)        
 

Added: zversioning/trunk/src/versioning/getHistories.py
===================================================================
--- zversioning/trunk/src/versioning/getHistories.py	2004-10-11 11:17:54 UTC (rev 27962)
+++ zversioning/trunk/src/versioning/getHistories.py	2004-10-11 11:22:51 UTC (rev 27963)
@@ -0,0 +1,72 @@
+import difflib
+from OFS.History import historicalRevision
+from DocumentTemplate.DT_Util import html_quote
+from DateTime import DateTime
+
+def getHistories(self):
+    """Get a list of historic revisions. Returns metadata as well:
+
+    (object, time, user)"""
+    
+    r = self._p_jar.db().history(self._p_oid, None, 20)
+
+    if r is None:
+        return ()
+
+    # Build list of objects
+    list = []
+    for x in r:
+        serial=x['serial']
+        o = historicalRevision(self, serial)
+        list.append((o.__of__(self.aq_parent), DateTime(x["time"]), x['description'], x['user_name']))
+
+    return list
+
+def getDocumentComparisons(self, max=10):
+    histories = getHistories(self)
+
+    html = ""
+
+    if max > len(histories):
+        max = len(histories)
+
+    for rev in range(1,max):
+
+        a, atime, adesc, auser = histories[rev]
+        b, btime, bdesc, buser = histories[rev-1]
+	if a.meta_type == 'ATDocument':
+	    a = a.getText().split("\n")
+	    b = b.getText().split("\n")
+	else:
+            a = a.text.split("\n")
+            b = b.text.split("\n")
+
+        html += """<h3>Vergleich: %s zu %s</h3>
+          <dl><dt>Kommentar</dt><dd>%s</dd>
+              <dt>Benutzer</dt><dd>%s</dd></dl>
+              <div style="min-height:2em; border:1px solid grey; background-color:#eeeeee;">""" % \
+                (self.toPortalTime(atime,1), self.toPortalTime(btime,1), adesc, auser
+                        )
+
+        lines = [x for x in difflib.unified_diff(a, b)][4:]
+
+        new_lines = []
+        for x in lines:
+            x = html_quote(x)
+            if x.startswith("+"):
+                x = """<span style="color:green;">%s</span>""" % x
+            elif x.startswith("-"):
+                x = """<span style="color:red;">%s</span>""" % x
+            elif x.startswith(" "):
+                x = """&nbsp;%s""" % x
+            elif x.startswith("@"):
+                x = "<b>%s</b>" % x
+            x = x+"<br/>"
+            new_lines.append(x)
+
+
+        html += "\n".join(new_lines)
+        html += "</div>"
+ 
+    return html 
+



More information about the Zope-CVS mailing list