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:
tekateki
|-- 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:
nama
hint
jawab
soalan
Now, to my first basic grok app.py:
import grok
class tekateki(grok.Application, grok.Container):
pass
#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):
grok.context(tekateki)
grok.name('index')
#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:
return
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):
grok.context(tekateki)
grok.name('delete')
def update(self, name=None):
if name is None:
return
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):
grok.context(ttEntry)
grok.name('index')
#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
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
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.
