[Grok-dev] GrokPaste: a grok pastebin app

Kevin Teague kevin at bud.ca
Fri Mar 23 23:32:58 EDT 2007


I've been doing some work on my second Grok project (my first project  
is a simple Group/User Manager app that reads/writes from LDAP which  
I've been using at work, which I plan on getting ready for release in  
soonish).

My second project is a PasteBin app called GrokPaste (although I am  
considering a better name for the app if it causes too much confusion  
with Python Paste).

Right now the app just has enough features to perform the basics of a  
pastebin app. Long term, I'd like GrokPaste to be a fairly feature  
rich pastebin app.

There is an instance running at:

http://www.bud.ca:8021/grokpaste/

The SVN repo and Trac browser are at:

https://bud.ca:9722/svn/grokpaste/trunk/
https://bud.ca:9722/wheat/browser/grokpaste/trunk

Currently the code is still very rough. I plan on applying some  
polish to, and packing it into a tarball so we can link to from the  
Grok site.

Some observations I noticed while working on this app:

Traversal
------------

Human readable URLs are not yet as easy to work with as other  
framworks, Rails/Django etc. It might be cool to have some Traversal  
conventions. Perhaps some convenience methods in the Traversal base  
class?

To support URLs such as /tags/foo/bar I wrote:

     def traverse(self, name):
         if name == 'tags':
             self.request.form['tags'] =  
self.request.getTraversalStack()
             self.request.setTraversalStack([])
             return queryMultiAdapter(
                 (self.context, self.request), name='tagsearch')
         else:
             # try to get the item from the container
             return self.context.get(name)

Something like this could be nice:

     def traverse(self, name):
         if name == 'tags':
             self.viewStackToList('tagsearch')
         else:
             # try to get the item from the container
             return self.context.get(name)

Either that or some pre-built Traversal components that perhaps  
expect a URLConfig Model to available?


Human Readable Time Deltas
-----------------------------------------

I really like web sites with "posted 4 hours ago". To that end I made  
a TimeReadable Global Utility. Right now this includes about 50 lines  
of code that I grabbed from django.utils.timesince.py.

It would be nice to eventually have this functionaly in a megrok  
package, or Grok core.

Development experience
----------------------------------

Grok rocks! w00t!

Consider the Plain-text Paste View:

class PastePlainView(grok.View):
     "Plain-text view of a single Paste"
     grok.context(Paste)
     grok.name('plain')

     def render(self):
         return self.context.body

Where in Zope 2 I might write:

/skins/grokpaste_scripts/pastePlainText.py
## Script (Python) "pastePlainText"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=Plain-text view of a single Paste

return context.body


And in Zope 2 I'd have to keep the code in a skins directory,  
floating around with a bunch of other unrelated files. And in Zope 3  
I'd have to write a bunch of ZCML. With Grok I can put all my Paste  
Views beside each other, and I only need to state the bare essence of  
what I want the app to do - yummy!



More information about the Grok-dev mailing list