[Checkins] SVN: Grokstar/trunk/src/grokstar/ add ability to add categories and search by categories

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


Log message for revision 87256:
  add ability to add categories and search by categories

Changed:
  U   Grokstar/trunk/src/grokstar/blog.py
  A   Grokstar/trunk/src/grokstar/blog_templates/categories.pt
  U   Grokstar/trunk/src/grokstar/entry.py
  U   Grokstar/trunk/src/grokstar/interfaces.py

-=-
Modified: Grokstar/trunk/src/grokstar/blog.py
===================================================================
--- Grokstar/trunk/src/grokstar/blog.py	2008-06-09 20:24:02 UTC (rev 87255)
+++ Grokstar/trunk/src/grokstar/blog.py	2008-06-09 21:13:28 UTC (rev 87256)
@@ -2,19 +2,22 @@
 from datetime import datetime, timedelta
 from itertools import islice
 
+from zc.catalog.catalogindex import SetIndex
 from zope import schema, interface
 from zope.interface import Interface
 from zope.traversing.api import getParents
 from hurry.query.query import Query
 from hurry import query
+from hurry.query.set import AllOf
 from hurry.workflow.interfaces import IWorkflowState
-
 import grok
 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
 
 class Blog(grok.Container, grok.Application):
     interface.implements(IBlog)
@@ -33,6 +36,7 @@
     title = index.Text()
     content = index.Text()
     published = index.Field()
+    categories = index.Set()
 
 class WorkflowIndexes(grok.Indexes):
     grok.site(Blog)
@@ -95,6 +99,7 @@
         entries = Query().searchResults(
             (query.Eq(('entry_catalog', 'workflow_state'), PUBLISHED) &
              (query.Text(('entry_catalog', 'title'), q) |
+              AllOf(('entry_catalog', 'categories'), [q]) |
               query.Text(('entry_catalog', 'content'), q))))
         self.results = list(islice(entries, 10))
 
@@ -121,3 +126,12 @@
     return sorted(
         entries, key=lambda entry: entry.updated, reverse=True
         )[:amount]
+
+class Categories(ViewBase):
+    grok.context(Blog)
+    grok.name('categories')
+
+    def categories(self):
+        cat = getUtility(ICatalog, 'entry_catalog')
+        categories = cat['categories']
+        return categories.values()

Added: Grokstar/trunk/src/grokstar/blog_templates/categories.pt
===================================================================
--- Grokstar/trunk/src/grokstar/blog_templates/categories.pt	                        (rev 0)
+++ Grokstar/trunk/src/grokstar/blog_templates/categories.pt	2008-06-09 21:13:28 UTC (rev 87256)
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" metal:use-macro="context/@@blogmacros/macros/blogpage">
+  <head>
+    <title metal:fill-slot="title">Categories</title>
+  </head>
+  <body>
+    <div metal:fill-slot="main-content">
+      <ul>
+        <li tal:repeat="cat view/categories">
+          <a tal:attributes="href string:${view/application_url}/search?q=${cat}"
+             tal:content="cat" />
+        </li>
+      </ul>
+    </div>
+  </body>
+</html>

Modified: Grokstar/trunk/src/grokstar/entry.py
===================================================================
--- Grokstar/trunk/src/grokstar/entry.py	2008-06-09 20:24:02 UTC (rev 87255)
+++ Grokstar/trunk/src/grokstar/entry.py	2008-06-09 21:13:28 UTC (rev 87256)
@@ -16,18 +16,22 @@
 class Entry(grok.Model):
     interface.implements(interfaces.IEntry, IAttributeAnnotatable)
 
-    def __init__(self, title, summary, rightsinfo):
+    def __init__(self, title, summary, rightsinfo, categories=None):
         self.title = title
         self.updated = datetime.now()
         self.published = None
         self.summary = summary
         self.rightsinfo = rightsinfo
+        if categories is None:
+            self.categories = []
+        else:
+            self.categories = categories
 
 class RestructuredTextEntry(Entry):
     interface.implements(interfaces.IRestructuredTextEntry)
 
-    def __init__(self, title, summary, rightsinfo, content):
-        super(RestructuredTextEntry, self).__init__(title, summary, rightsinfo)
+    def __init__(self, title, summary, rightsinfo, content, categories=None):
+        super(RestructuredTextEntry, self).__init__(title, summary, rightsinfo, categories)
         self.content = content
 
 grok.context(RestructuredTextEntry)

Modified: Grokstar/trunk/src/grokstar/interfaces.py
===================================================================
--- Grokstar/trunk/src/grokstar/interfaces.py	2008-06-09 20:24:02 UTC (rev 87255)
+++ Grokstar/trunk/src/grokstar/interfaces.py	2008-06-09 21:13:28 UTC (rev 87256)
@@ -28,8 +28,9 @@
 ##     contributors = schema.List(title=u"Contributors", value_type=schema.Object,
 ##                                default=[])
 
-##     categories = schema.List(title=u"Categories", value_type=schema.Object,
-##                              default=[])
+    categories = schema.List(title=u"Categories",
+                             value_type=schema.TextLine(title=u"Categories"),
+                             default=[])
  
     #links = schema.List(title=u"Links", value_type=schema.TextLine,
     #                    default=[])



More information about the Checkins mailing list