[Grok-dev] Grok ORM wit storm.zope

Sebastian Ware sebastian at urbantalk.se
Wed Nov 21 05:22:51 EST 2007


I have looked at your code and taken a glance at Storm. My first  
impression is that this is something I want to use. Very much... :)

Mvh Sebastian

21 nov 2007 kl. 10.22 skrev Christian Klinger:

> Hi,
>
> i have developed the last days a very simple ORM application
> with grok and storm.zope [1]. This was easier then i have
> expected. :-)
>
> Unfortunatly storm.zope has no container implementation for
> zope. So i decided to work on a StormContainer for grok.
>
> I´m now ready with the StormContainer and it works nice with my
> simple example. I try to give you an impression at the end of
> this mail.
>
> Before you will see some code i have some questions:
>
> - Is this intresting for other people?
> - Should i make a megrok.storm package for the StromContainer?
> - I don´t know how to write tests for the Container with the
>  Database dependency.
>
> Christian
>
> [1] https://storm.canonical.com/
>
> contact.py
> ==========
> import grok
> from storm.locals import *
> from interfaces import IPerson
>
> class Person(grok.Model):
>    grok.implements(IPerson)
>    __storm_table__ = "DBPerson"
>
>    id = Int(primary=True)
>    name = Unicode()
>    vorname = Unicode()
>
> class Index(grok.View):
>    grok.context(Person)
>
> class Edit(grok.EditForm):
>    grok.context(Person)
>    form_fields = grok.AutoFields(IPerson)
>
>
> app.py
> ======
> import grok
> from contact import Person
> from interfaces import IPerson
> from megrok.storm.stormcontainer import StormContainer
>
> class PersonDB(grok.Application, StormContainer):
>    def __init__(self):
>        super(PersonDB, self).__init__()
>        self.setClassName('person.person.contact.Person')
>
> class PersonDelete(grok.View):
>    """ Delete the Person """
>    grok.context(PersonDB)
>    def render(self, id):
>        context = self.context
>        del(context[id])
>        self.redirect('index')
>
> class Index(grok.View):
>    grok.name('index')
>    grok.context(PersonDB)
>
>    def getPersons(self):
>        """ The DB-Entries acts as normal Objects"""
>        rc=[]
>        for obj in self.context.items():
>            o = obj[1]
>            it = {'id_name': obj[0],
>                  'name': o.name,
>                  'id': o.id,
>                  'vorname': o.vorname }
>            print it
>            rc.append(it)
>        return rc
>
> class CreatePerson(grok.AddForm):
>    grok.context(PersonDB)
>    form_fields = grok.AutoFields(IPerson)
>
>    @grok.action('Create')
>    def create(self, **kw):
>        r = Person()
>        self.applyData(r, **kw)
>        context = self.context
>        context['id'] = r
>        self.redirect(self.url(self.context))
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list