ActiveRecords-like validation

4 views
Skip to first unread message

bruno.des...@gmail.com

unread,
Apr 25, 2007, 3:42:19 PM4/25/07
to SQLElixir
Hi all

One of the points that Rails ActiveRecord got right IMHO is the fact
that models should validate themselves. So I started to work on adding
rail-like validation to Elixir entities, using formencode. Here's a
first Q&D and incomplete attempt, I'm awaiting for criticism,
suggestions and other feedback.

http://sqlelixir.googlegroups.com/web/entities.py

NB : one of the main differences with ActiveRecords is that this
modules automagically adds validators based on the entity's fields.

Gaetan de Menten

unread,
Apr 25, 2007, 4:03:56 PM4/25/07
to sqle...@googlegroups.com
On 4/25/07, bruno.des...@gmail.com <bruno.des...@gmail.com> wrote:
>
> Hi all
>
> One of the points that Rails ActiveRecord got right IMHO is the fact
> that models should validate themselves. So I started to work on adding
> rail-like validation to Elixir entities, using formencode. Here's a
> first Q&D and incomplete attempt, I'm awaiting for criticism,
> suggestions and other feedback.

At first glance, it looks GREAT. I'll have a more thorough look
tomorrow and I'll try to think how and if we should include that
directly in Elixir.

--
Gaëtan de Menten
http://openhex.org

Jonathan LaCour

unread,
Apr 25, 2007, 5:02:50 PM4/25/07
to sqle...@googlegroups.com
bruno.des...@gmail.com wrote:

Wow!

I was considering adding statements exactly like these to Elixir, but it
looks like you have done all the work for us :)

I'll take a closer look as soon as I can. Some examples that illustrate
how to use your statements would be very helpful.

--
Jonathan LaCour
http://cleverdevil.org

黄毅

unread,
Apr 26, 2007, 1:18:20 AM4/26/07
to sqle...@googlegroups.com
One of the points that Rails ActiveRecord got right IMHO is the fact
that models should validate themselves. So I started to work on adding
rail-like validation to Elixir entities, using formencode. Here's a
first Q&D and incomplete attempt, I'm awaiting for criticism,
suggestions and other feedback.

Doesn't that kind of validation belong to form library ?
 

bruno.des...@gmail.com

unread,
Apr 26, 2007, 8:57:42 AM4/26/07
to SQLElixir

Nope. Forms do of course have to handle their own conversion/
validation, but this is a different issue.

> --http://codeplayer.blogspot.com/

bruno.des...@gmail.com

unread,
Apr 26, 2007, 3:41:17 PM4/26/07
to SQLElixir
Hi again

Looks like my previous answer got lost somewhere in the ether, so...

On 25 avr, 23:02, Jonathan LaCour <jonathan-li...@cleverdevil.org>
wrote:


>
> Wow!
>
> I was considering adding statements exactly like these to Elixir, but it
> looks like you have done all the work for us :)

Not quite *all* the work yet !-)

There's still a lot to do like pre/post validation hooks, more
validate_XXX statements, etc, etc, and of course test, test, test.

> I'll take a closer look as soon as I can. Some examples that illustrate
> how to use your statements would be very helpful.

Yes, indeed. Anyway, I won't go much further without first adding real
unit-tests, so there should be working examples pretty soon now.

Gaetan : if adding a dependency on formencode is not a problem for you
(I mean you three guys), I'd of course be happy (and honored) to see
this code becoming part of Elixir - when it'll be a bit less dirty
and a bit more tested.

Thanks you two for these first feedbacks. I'm awaiting your
observations and suggestions after a closer look.

Bruno

Gaetan de Menten

unread,
May 3, 2007, 10:47:20 AM5/3/07
to sqle...@googlegroups.com

> Gaetan : if adding a dependency on formencode is not a problem for you
> (I mean you three guys), I'd of course be happy (and honored) to see
> this code becoming part of Elixir - when it'll be a bit less dirty
> and a bit more tested.

Sorry for the delay. I still haven't had the opportunity to look more
closely at your code and probably won't have for some time (sorry
about that... you know... life and all that stuff).

But anyway, after giving it some thoughts, I don't thing this belongs
in. Don't get me wrong, I'm pretty sure your code is very useful (and
I'll probably use it on a later project) but if we include your code
that would be a important change of the scope of the library.

For now, it has been: "a declarative layer on top of SQLAlchemy", and
that's it nothing more.

I'm open for discussion about this, but my personal stance at the
moment is to try to keep the scope of Elixir as it is (ie quite
narrow) but fill it as well as we can rather than going in all sorts
of directions and ending up with a semi-complete-framework.

Jonathan LaCour

unread,
May 3, 2007, 11:18:02 AM5/3/07
to sqle...@googlegroups.com
Gaetan de Menten wrote:

> Sorry for the delay. I still haven't had the opportunity to look more
> closely at your code and probably won't have for some time (sorry
> about that... you know... life and all that stuff).

Its the same response from me! I have a lot going on right now between
life and work, so I haven't had much time to spend on Elixir in a while
:/ But, I am excited by the initial code that I have seen in your
validation statements, but haven't gone over it enough to really provide
feedback.

> I'm open for discussion about this, but my personal stance at the
> moment is to try to keep the scope of Elixir as it is (ie quite
> narrow) but fill it as well as we can rather than going in all sorts
> of directions and ending up with a semi-complete-framework.

I would be open to providing an additional egg and including details
about it on the Elixir page. Ideally, I would like a lot of people
to start creating their own DSL statements for doing various things,
including validation, tagging, etc. If we get enough of these rolling,
I'd like to have something on the Elixir website that lists these
"plugins" and provides a place to hold their documentation. I'd even be
in favor of placing these plugins into our subversion repository, each
in their own separate projects.

To me, this is a great way to build up Elixir. The core provides just
what Gaetan said: a declarative layer on top of SQLAlchemy, along with a
basis for extending it with plugins.

bruno.des...@gmail.com

unread,
May 5, 2007, 4:23:24 PM5/5/07
to SQLElixir
On 3 mai, 17:18, Jonathan LaCour <jonathan-li...@cleverdevil.org>
wrote:

> Gaetan de Menten wrote:
> > Sorry for the delay. I still haven't had the opportunity to look more
> > closely at your code and probably won't have for some time (sorry
> > about that... you know... life and all that stuff).
>
> Its the same response from me! I have a lot going on right now between
> life and work, so I haven't had much time to spend on Elixir in a while

Don't worry you both and don't feel sorry - I have a life too, and had
almost no time to work on this since my OP.

(snip)


> > I'm open for discussion about this, but my personal stance at the
> > moment is to try to keep the scope of Elixir as it is (ie quite
> > narrow) but fill it as well as we can rather than going in all sorts
> > of directions and ending up with a semi-complete-framework.
>
> I would be open to providing an additional egg and including details
> about it on the Elixir page. Ideally, I would like a lot of people
> to start creating their own DSL statements for doing various things,
> including validation, tagging, etc. If we get enough of these rolling,
> I'd like to have something on the Elixir website that lists these
> "plugins" and provides a place to hold their documentation. I'd even be
> in favor of placing these plugins into our subversion repository, each
> in their own separate projects.
>
> To me, this is a great way to build up Elixir. The core provides just
> what Gaetan said: a declarative layer on top of SQLAlchemy, along with a
> basis for extending it with plugins.

All this seems quite sensible. But then it would be useful (IMHO) to
have some (more or less) standardized way to organize/package/deploy
these plugins...

My 2 cents...

bruno.des...@gmail.com

unread,
May 9, 2007, 5:16:07 PM5/9/07
to SQLElixir
On 26 avr, 21:41, "bruno.desthuilli...@gmail.com"

<bruno.desthuilli...@gmail.com> wrote:
> Hi again
>
> Looks like my previous answer got lost somewhere in the ether, so...
>
> On 25 avr, 23:02, Jonathan LaCour <jonathan-li...@cleverdevil.org>
> wrote:
>
>
>
> > Wow!
>
> > I was considering adding statements exactly like these to Elixir, but it
> > looks like you have done all the work for us :)
>
> Not quite *all* the work yet !-)
>
> There's still a lot to do like pre/post validation hooks, more
> validate_XXX statements, etc, etc, and of course test, test, test.

And of course someone already wrote part of this:
http://pylonshq.com/pasties/244
http://beachcoder.wordpress.com/2007/05/02/adding-event-callbacks-to-sqlalchemyelixir-classes/


Jonathan LaCour

unread,
May 9, 2007, 8:07:17 PM5/9/07
to sqle...@googlegroups.com
bruno.des...@gmail.com wrote:

> And of course someone already wrote part of this:
> http://pylonshq.com/pasties/244

Very cool!

These statements seem like they would make wonderful additions to
elixir, and we'd just need to contact the author of the statements about
adding them in. I would be happy to write some tests and documentation
updates for the new statements.

What does everyone (Gaetan, Daniel, etc.) think?

Gaetan de Menten

unread,
May 10, 2007, 3:15:07 AM5/10/07
to sqle...@googlegroups.com

Well, I had already seen that code (notice the reference to it in the
TODO file ;-)) and I'm fully in favor of providing an easy way to
extend the mapper, but, as I said in the TODO file:

"Beachcoder's code seem pretty cool but I wonder if it wouldn't
be possible to do something simpler." (ie less repetitive).

Btw: I've got quite a few changes in Elixir in my pipeline... Stay tuned...

Reply all
Reply to author
Forward
0 new messages