Random ...
May 2018
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Tags ...

python+zope++:: Grok for dum-dums: continuing the journey
Posted at 24.Apr,2008 11:47  Comments 2 / Trackbacks 0 / Like this post!
Technorati tag(s):

I've played around with grok: some time back. Thought that it's a good time to revisit grok, now with some targets in mind.

Hopefully, by the end of this journey, I'll have a site up, replacing a small site.

Now grok have better documentations and I hope I'm wiser :P.

First off, install virtualenv. This will make handling multiple grok instances manageable.

easy_install virtualenv

Once installed, create aour virtualenv:

  virtualenv --no-site-packages vgrok

Activate the env:

  source /path/to/vgrok/bin/activate
  (vgrok) projek]$

Once we're in virtualenv, let's install grokproject:

  easy_install grokproject

To exit the virtualenv:

  (vgrok) projek$ deactivate

Once installed, create a new grok project:

  grokproject tekateki

This will create a tree:

  |-- bin
  |-- develop-eggs
  |-- parts
  |   |-- app
  |   |-- data
  |   |-- i18n
  |   |-- test
  |   `-- zopectl
  `-- src
      |-- tekateki
      |   `-- app_templates
      `-- tekateki.egg-info

The src directory is where all necessary files and templates will be. Initially, there is only app.py (the main class, our application) and the templates.

Here's my try in mapping grok's stuff to zope2's products et all.

In grok the app.py, is our application. In grok, app.py is it. We can add more grok.Model (the content type), or grok.Container (Folderish object) and make use of grok.View to set the Views or presentation.

In zope2, we can have many products that we tie with Script (Python), External Methods, ZSQL Methods, etc to make an application. And we have to create site (application) TTW by making use of Products and other objects.

The site I'm trying to replace has a list of simple contents with a these attributes:


Now, to my first basic grok app.py:

  import grok

  class tekateki(grok.Application, grok.Container):
  #this is our app.  everything else hangs of this.  it's an Application and Container
  class ttEntry(grok.Model):
    def __init__(self, soalan, jawab, hint, nama):
        self.nama = nama
        self.hint = hint
        self.jawab = jawab
        self.soalan = soalan
  #here's my content type.  in zope2, i have a productwith these attribs.  in grok, we still have it, subclassed of grok.Model

  class SampleIndex(grok.View):
  #here's our main view, the site's default index_html (it ties to the tekateki app).  we can call it anything we want (grok.name('index.html'))

    def update(self, name=None, soalan=None, jawab=None, hint=None, nama=None):
        if name is None or nama is None or soalan is None or jawab is None:
        print nama
        self.context[name] = ttEntry(soalan, jawab, hint, nama)
  #update will be like our constructor/method in zope2 product. XXX correct me here

  class DelIndex(grok.View):

    def update(self, name=None):
        if name is None:
        del self.context[name]
  #update will be like our constructor/method in zope2 product. XXX correct me here.  a form will have its action tied to delete, and update will do the necessary.  for views to work, we need to have the PT in app_templates with the same name as the class, but lowercase

    #def render(self):
     #   self.redirect(self.url(self.context))

  class EntryIndex(grok.View):
  #this is our model's default index (tied to ttEntry - our model).  we can call it anything (grok.name('index.html')).  if we don't tie this calss to anything, the default will be the calssname, lowercased

This is the first step for me in the journey grokking grok. Next, I will look at using formlib and schema.

There's a great grok primer and seeing it, I see my journey will take some time :P

Bookmark and Share

Is this entry helpful? Comments/Donate/Click some google ads.  
Trackback is http://myzope.kedai.com.my/blogs/kedai/189/tbping 


i wonder which 'dum-dum' you are talking about, cf this listing: http://en.wikipedia.org/wiki/Dum_Dums

d2m  at 26.Apr,2008 09:18
it's me!

It's slang, for dummies. http://www.thefreedictionary.com/dum-dums

the dum-dum here is me :P

We should edit wikipedia to include this too.

kedai  at 26.Apr,2008 09:25
Post a comment