[Checkins] SVN: Grokstar/trunk/src/grokstar/ remove view base class in favor of utility view that returns number of

Robert Marianski rmarianski at openplans.org
Mon Jun 9 17:28:54 EDT 2008


Log message for revision 87258:
  remove view base class in favor of utility view that returns number of
  posts

Changed:
  D   Grokstar/trunk/src/grokstar/base.py
  U   Grokstar/trunk/src/grokstar/blog.py
  U   Grokstar/trunk/src/grokstar/blog_templates/blogmacros.pt
  U   Grokstar/trunk/src/grokstar/calendar.py
  U   Grokstar/trunk/src/grokstar/entry.py
  U   Grokstar/trunk/src/grokstar/form.py
  A   Grokstar/trunk/src/grokstar/utils.py

-=-
Deleted: Grokstar/trunk/src/grokstar/base.py
===================================================================
--- Grokstar/trunk/src/grokstar/base.py	2008-06-09 21:15:06 UTC (rev 87257)
+++ Grokstar/trunk/src/grokstar/base.py	2008-06-09 21:28:53 UTC (rev 87258)
@@ -1,18 +0,0 @@
-import grok
-from hurry.query.query import Query
-from hurry import query
-from zope.interface import Interface
-from grokstar.interfaces import IBlog
-
-class ViewBase(grok.View):
-    """contain common view methods"""
-    grok.context(Interface)
-
-    def numPosts(self):
-        # @@ is there a better way to get all entries through the catalog?
-        obj = self.context
-        while obj is not None:
-            if IBlog.providedBy(obj):
-                return len(obj['entries'])
-            obj = obj.__parent__
-        return 0

Modified: Grokstar/trunk/src/grokstar/blog.py
===================================================================
--- Grokstar/trunk/src/grokstar/blog.py	2008-06-09 21:15:06 UTC (rev 87257)
+++ Grokstar/trunk/src/grokstar/blog.py	2008-06-09 21:28:53 UTC (rev 87258)
@@ -14,7 +14,6 @@
 from grok import index
 from grokstar.interfaces import IRestructuredTextEntry, IBlog
 from grokstar.interfaces import PUBLISHED, CREATED
-from grokstar.base import ViewBase
 from form import GrokstarEditForm
 from zope.app.catalog.interfaces import ICatalog
 from zope.component import getUtility
@@ -50,7 +49,7 @@
 class Drafts(grok.Model):
       pass
 
-class DraftsIndex(ViewBase):
+class DraftsIndex(grok.View):
     grok.context(Drafts)
     grok.name('index')
     
@@ -60,14 +59,14 @@
 class Entries(grok.Container):
     pass
 
-class BlogIndex(ViewBase):
+class BlogIndex(grok.View):
     grok.context(Blog)
     grok.name('index')
 
     def entries(self):
         return lastEntries(10)
 
-class BlogMacros(ViewBase):
+class BlogMacros(grok.View):
     grok.context(Interface)
 
 class BlogEdit(GrokstarEditForm):
@@ -80,11 +79,11 @@
         self.applyData(self.context, **data)
         self.redirect(self.url(self.context))
 
-class BlogAbout(ViewBase):
+class BlogAbout(grok.View):
     grok.context(Blog)
     grok.name('about')
 
-class Search(ViewBase):
+class Search(grok.View):
     grok.context(Blog)
 
     def update(self, q=None):
@@ -103,7 +102,7 @@
               query.Text(('entry_catalog', 'content'), q))))
         self.results = list(islice(entries, 10))
 
-class EntriesIndex(ViewBase):
+class EntriesIndex(grok.View):
     grok.context(Entries)
     grok.name('index')
 
@@ -127,7 +126,7 @@
         entries, key=lambda entry: entry.updated, reverse=True
         )[:amount]
 
-class Categories(ViewBase):
+class Categories(grok.View):
     grok.context(Blog)
     grok.name('categories')
 

Modified: Grokstar/trunk/src/grokstar/blog_templates/blogmacros.pt
===================================================================
--- Grokstar/trunk/src/grokstar/blog_templates/blogmacros.pt	2008-06-09 21:15:06 UTC (rev 87257)
+++ Grokstar/trunk/src/grokstar/blog_templates/blogmacros.pt	2008-06-09 21:28:53 UTC (rev 87258)
@@ -34,8 +34,9 @@
       <div metal:define-slot="main-content" />
     </div>
     <div id="ft">
-      <span id="num-posts">
-        Me grok <tal:posts replace="view/numPosts" /> posts!
+      <span id="num-posts"
+            tal:define="utils nocall:context/@@utils">
+        Me grok <tal:posts replace="utils/numPosts" /> posts!
       </span>
       <div id="external-links">
         <ul>

Modified: Grokstar/trunk/src/grokstar/calendar.py
===================================================================
--- Grokstar/trunk/src/grokstar/calendar.py	2008-06-09 21:15:06 UTC (rev 87257)
+++ Grokstar/trunk/src/grokstar/calendar.py	2008-06-09 21:28:53 UTC (rev 87258)
@@ -6,7 +6,6 @@
 from hurry import query
 
 from grokstar.interfaces import PUBLISHED
-from grokstar.base import ViewBase
 
 class Year(grok.Model):
     def __init__(self, year):
@@ -21,7 +20,7 @@
             return None
         return Month(self.year, month)
 
-class YearIndex(ViewBase):
+class YearIndex(grok.View):
     grok.name('index')
     grok.context(Year)
     grok.template('dateindex')
@@ -44,7 +43,7 @@
         # XXX should check whether day is acceptable
         return Day(self.year, self.month, day)
 
-class MonthIndex(ViewBase):
+class MonthIndex(grok.View):
     grok.name('index')
     grok.context(Month)
     grok.template('dateindex')
@@ -67,7 +66,7 @@
         self.month = month
         self.day = day
 
-class DayIndex(ViewBase):
+class DayIndex(grok.View):
     grok.name('index')
     grok.context(Day)
     grok.template('dateindex')

Modified: Grokstar/trunk/src/grokstar/entry.py
===================================================================
--- Grokstar/trunk/src/grokstar/entry.py	2008-06-09 21:15:06 UTC (rev 87257)
+++ Grokstar/trunk/src/grokstar/entry.py	2008-06-09 21:28:53 UTC (rev 87258)
@@ -10,7 +10,6 @@
 
 from grokstar.blog import Blog
 from grokstar import interfaces
-from grokstar.base import ViewBase
 from form import GrokstarAddForm, GrokstarEditForm
 
 class Entry(grok.Model):
@@ -37,11 +36,11 @@
 grok.context(RestructuredTextEntry)
 
 
-class Index(ViewBase):
+class Index(grok.View):
     pass
 
 
-class Item(ViewBase):
+class Item(grok.View):
     def format_published(self, published_date):
         return published_date.strftime('%Y-%m-%d')
 
@@ -90,7 +89,7 @@
         self.redirect(self.url(self.context))
 
 
-class RenderedContent(ViewBase):
+class RenderedContent(grok.View):
     def render(self):
         return renderRest(self.context.content)
 

Modified: Grokstar/trunk/src/grokstar/form.py
===================================================================
--- Grokstar/trunk/src/grokstar/form.py	2008-06-09 21:15:06 UTC (rev 87257)
+++ Grokstar/trunk/src/grokstar/form.py	2008-06-09 21:28:53 UTC (rev 87258)
@@ -1,8 +1,10 @@
 import grok
-from base import ViewBase
+from zope.interface import Interface
 
-class GrokstarAddForm(grok.AddForm, ViewBase):
+class GrokstarAddForm(grok.AddForm):
     pass
 
-class GrokstarEditForm(grok.EditForm, ViewBase):
+class GrokstarEditForm(grok.EditForm):
     pass
+
+grok.context(Interface)

Added: Grokstar/trunk/src/grokstar/utils.py
===================================================================
--- Grokstar/trunk/src/grokstar/utils.py	                        (rev 0)
+++ Grokstar/trunk/src/grokstar/utils.py	2008-06-09 21:28:53 UTC (rev 87258)
@@ -0,0 +1,21 @@
+import grok
+from hurry.query.query import Query
+from hurry import query
+from zope.interface import Interface
+from grokstar.interfaces import IBlog
+
+class Utils(grok.View):
+    """contain common view methods"""
+    grok.context(Interface)
+
+    def numPosts(self):
+        # @@ is there a better way to get all entries through the catalog?
+        obj = self.context
+        while obj is not None:
+            if IBlog.providedBy(obj):
+                return len(obj['entries'])
+            obj = obj.__parent__
+        return 0
+
+    def render(self):
+        return ''



More information about the Checkins mailing list