[Checkins] SVN: grok/trunk/ Beginnings of grokblog, an experimental grok-based blog application.

Martijn Faassen faassen at infrae.com
Fri Nov 3 17:15:13 EST 2006


Log message for revision 71053:
  Beginnings of grokblog, an experimental grok-based blog application.
  

Changed:
  U   grok/trunk/buildout.cfg
  A   grok/trunk/grokblog/
  A   grok/trunk/grokblog/setup.py
  A   grok/trunk/grokblog/src/
  A   grok/trunk/grokblog/src/grokblog/
  A   grok/trunk/grokblog/src/grokblog/__init__.py
  A   grok/trunk/grokblog/src/grokblog/blog.py
  A   grok/trunk/grokblog/src/grokblog/configure.zcml
  U   grok/trunk/grokwiki/src/grokwiki/wiki.py

-=-
Modified: grok/trunk/buildout.cfg
===================================================================
--- grok/trunk/buildout.cfg	2006-11-03 22:14:06 UTC (rev 71052)
+++ grok/trunk/buildout.cfg	2006-11-03 22:15:13 UTC (rev 71053)
@@ -1,5 +1,5 @@
 [buildout]
-develop = . grokwiki ldapaddressbook
+develop = . grokwiki ldapaddressbook grokblog
 parts = zope3 data instance test
 
 # find-links = http://download.zope.org/distribution/
@@ -18,11 +18,13 @@
 eggs = setuptools
        grok
        grokwiki
+       grokblog
 
 zcml = *
        grok
        grok-meta
        grokwiki
+       grokblog
 
 [test]
 recipe = zc.recipe.testrunner

Added: grok/trunk/grokblog/setup.py
===================================================================
--- grok/trunk/grokblog/setup.py	2006-11-03 22:14:06 UTC (rev 71052)
+++ grok/trunk/grokblog/setup.py	2006-11-03 22:15:13 UTC (rev 71053)
@@ -0,0 +1,20 @@
+from setuptools import setup, find_packages
+
+setup(
+    name='grokblog',
+    version='0.1',
+    author='Grok Team',
+    author_email='grok-dev at zope.org',
+    url='http://svn.zope.org/grok/trunk',
+    description="""\
+Grok: the blog
+""",
+    packages=find_packages('src'),
+    package_dir = {'': 'src'},
+    include_package_data = True,
+    zip_safe=False,
+    license='ZPL',
+
+    install_requires=['setuptools',
+                     ],
+)

Added: grok/trunk/grokblog/src/grokblog/__init__.py
===================================================================
--- grok/trunk/grokblog/src/grokblog/__init__.py	2006-11-03 22:14:06 UTC (rev 71052)
+++ grok/trunk/grokblog/src/grokblog/__init__.py	2006-11-03 22:15:13 UTC (rev 71053)
@@ -0,0 +1,2 @@
+#
+

Added: grok/trunk/grokblog/src/grokblog/blog.py
===================================================================
--- grok/trunk/grokblog/src/grokblog/blog.py	2006-11-03 22:14:06 UTC (rev 71052)
+++ grok/trunk/grokblog/src/grokblog/blog.py	2006-11-03 22:15:13 UTC (rev 71053)
@@ -0,0 +1,134 @@
+from datetime import datetime, timedelta
+import grok
+
+from zope import interface, schema
+from zope.app.component.hooks import setSite, getSite
+from zope.app.component.site import LocalSiteManager
+from zope.app.component.interfaces import IPossibleSite
+from zope.app.component.site import SiteManagerContainer
+
+class Blog(grok.Container, SiteManagerContainer):
+    interface.implements(IPossibleSite)
+
+    def __init__(self):
+        super(Blog, self).__init__()
+        self['entries'] = Entries()
+
+    def traverse(self, name):
+        try:
+            year = int(name)
+        except ValueError:
+            return None
+        return Year(year)
+
+ at grok.subscribe(Blog, grok.IObjectAddedEvent)
+def blogAdded(blog, event):
+    sitemanager = LocalSiteManager(blog)
+    blog.setSiteManager(sitemanager)
+    setSite(blog)
+    
+class Entries(grok.Container):
+    pass
+
+class IEntry(interface.Interface):
+    title = schema.TextLine(title=u'Title')
+    published = schema.Datetime(title=u'Published')
+    
+class Entry(grok.Model):
+    interface.implements(IEntry)
+
+    def __init__(self, title):
+        self.title = title
+        self.published = datetime.now()
+
+class Year(grok.Model):
+    def __init__(self, year):
+        self.year = year
+        
+    def traverse(self, name):
+        try:
+            month = int(name)
+        except ValueError:
+            return None
+        if month < 1 or month > 12:
+            return None
+        return Month(self.year, month)
+
+class Month(grok.Model):
+    def __init__(self, year, month):
+        self.year = year
+        self.month = month
+        
+    def traverse(self, name):
+        try:
+            day = int(name)
+        except ValueError:
+            return None
+        # XXX should check whether day is acceptable
+        return Day(self.year, self.month, day)
+
+class Day(grok.Model):
+    def __init__(self, year, month, day):
+        self.year = year
+        self.month = month
+        self.day = day
+
+class DayIndex(grok.View):
+    grok.name('index')
+    grok.context(Day)
+    
+    def render(self):
+        from_ = datetime(self.context.year,
+                         self.context.month,
+                         self.context.day)
+        until = from_ + timedelta(days=1)
+        entries = entriesInDateRange(from_, until)
+        return "Entries: %s" % ' '.join([entry.__name__ for entry in entries])
+
+def entriesInDateRange(from_, until):
+    entries = getSite()['entries']
+    for entry in entries.values():
+        if from_ <= entry.published <= until:
+            yield entry
+       
+class BlogIndex(grok.View):
+    grok.context(Blog)
+    grok.name('index')
+
+blogindex = grok.PageTemplate('''\
+<html>
+<body>
+<form tal:attributes="action python:view.url('add_entry')" method="POST">
+id: <input type="text" name="id" value="" /><br />
+title: <input type="text" name="title" value="" /><br />
+<input type="submit" value="Add Entry" />
+</form>
+</body>
+</html>
+''')
+
+class AddEntry(grok.View):
+    grok.context(Blog)
+    grok.name('add_entry')
+
+    def render(self):
+        id = self.request.form.get('id')
+        title = self.request.form.get('title', '')
+        if id:
+            self.context['entries'][id] = Entry(title)
+        self.redirect(self.url(self.context))
+        
+class EntriesIndex(grok.View):
+    grok.context(Entries)
+    grok.name('index')
+
+    def render(self):
+        return "Entries: %s" % ' '.join(self.context.keys())
+    
+class EntryIndex(grok.View):
+    grok.context(IEntry)
+    grok.name('index')
+
+    def render(self):
+        return "Title: %s" % self.context.title
+    

Added: grok/trunk/grokblog/src/grokblog/configure.zcml
===================================================================
--- grok/trunk/grokblog/src/grokblog/configure.zcml	2006-11-03 22:14:06 UTC (rev 71052)
+++ grok/trunk/grokblog/src/grokblog/configure.zcml	2006-11-03 22:15:13 UTC (rev 71053)
@@ -0,0 +1,15 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:browser="http://namespaces.zope.org/browser"
+    xmlns:grok="http://namespaces.zope.org/grok"
+    i18n_domain="grok"
+    >
+    <grok:grok package="."/>
+
+    <browser:addMenuItem
+        class=".blog.Blog"
+        title="Grok Blog"
+        description="Grok Blog"
+        permission="zope.ManageContent"
+        />
+</configure>

Modified: grok/trunk/grokwiki/src/grokwiki/wiki.py
===================================================================
--- grok/trunk/grokwiki/src/grokwiki/wiki.py	2006-11-03 22:14:06 UTC (rev 71052)
+++ grok/trunk/grokwiki/src/grokwiki/wiki.py	2006-11-03 22:15:13 UTC (rev 71053)
@@ -20,9 +20,7 @@
 class Wiki(grok.Container):
     """This is our wiki application wich contains all wiki pages."""
 
-class WikiIndex(grok.View):
-    grok.name('index')
-
+class Index(grok.View):
     def render(self):
         self.redirect(self.url('home'))
 



More information about the Checkins mailing list