[Grok-dev] Elixir ORM Mapper for grok

Martin Aspeli optilude+lists at gmail.com
Mon May 11 10:35:10 EDT 2009


Hi Patrick,

Patrick Gerken wrote:
> Hi,
> while trying to grok Martian, I wanted to try it with a small example. 
> The result is a grokker for Elixir schema definitions. It generates 
> zope.interfaces with zope.schemas for it, and make the class implement 
> some interfaces so that it can be traversed in grok.

Nice!

I'm really interested in the first part of that: turning an Elixir class 
into a schema interface.

How did you do it? What conversion algorithm did you use?

> Elixir is a module that allows you to write one class and does 
> everything whats needed for you to be able to persist it. It looks a bit 
> like a Interface with schemas:
> 
> class Movie(Entity):
>     title = Field(Unicode(30))
>     year = Field(Integer)
>     description = Field(UnicodeText)
> 
> Now, what did I get working:
> - The class at it is, will be grokked, and I create a Interface with 
> schema information out of it.
> - Together with a custom traverser, I can look at instances that I saved 
> to the database before.
> - Edit and Displayforms
> 
> Whats does not work
> - I was just playing around and I decided to stop, before the  "commit 
> the changes to the database" stuff. I tried it once in an interactive 
> shell, and that worked.
> 
> Whats too unfinished
> - I just made mappers for three different schema types, I do not 
> retrieve all attributes from the elixir schema information

Right. Are you starting from Elixir objects, or the SQLAlchemy table 
definitions it presumably generates?

> - I did not dig into relations either, might be complicated, but maybe not.
> - Somehow, my views got loaded to early, before I grokked the model 
> data. Also, the dynamically generated interface cannot be easily 
> referenced. So an EditForm looks like that currently:
> 
> class Index(EditForm):
>     grok.context(Movie)
>     def update(self):
>         self.form_fields = grok.Fields(Movie.grokked_interface)

I'd suggest that you stick it in the module as I${class_name} or 
something like that, rather than as an attribute on the class.

> I just wanted to play around with all this stuff, I have no itch 
> scratching me, so I stop here for now, and look at it at a later time 
> again, maybe at the Neanderthalsprint.
> 
> Meanwhile if somebody has an urgent interest for getting this stuff to 
> work, please contact me and I'll clean the stuff up and publish it.

I'd certainly be interested to see the code.

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book



More information about the Grok-dev mailing list