>> > > >> Now that we are at it I was wondering whether
>> > > >> something similar could be adopted for tables too. The order
>> > > >> in which the tables are defined, class table1( SQLObject ),
>> > > >> class table2( SQLObject ), etc, etc, could also be significant
>> > > >> and one might want to remember this ordering. And since there
>> > > >> is all sorts of metaclass trickery involved with class
>> > > >> creation, maybe the ordering could be stored.
>> > > >>
>> > > >> What do you think?
>> > > >
>> > > > Yes, it could be done in a metaclass or in the constructor.
>> > >
>> > > As far as I can see declarative.DeclarativeMeta is the place to
>> > > look. I'll try to come up with something.
>> >
>> > DeclarativeMeta is a generic metaclass. SQLObject-specific
>> > metaclass should become its descendant. I suppose you don't need to
>> > have .creationOrder attribute in all classes (sqlmeta?)
>> > If you only need .creationOrder in SQLObject classes (tables)
>> > it's enough to set it in __init__, right before testing for
>> > _SO_fetch_no_create.
>> > Actually I started to think .creationOrder if the tables is not
>> > that interesting because it depends on the order of import. The
>> > order of columns is more interesting and more stable.
>>
>> Oops, dammit, a classical wrong way of thinking. __init__ is about
>> creating *rows*, and you certainly is thinking about *classes*. So the
>> only right way to go is a metaclass.
>>
>
> I've done a similar thing for other classes (not SQLObject) with
> DeklaraticeMeta from SQLObject:
>
> classnr = 0
>
> class Base(object):
> __metaclass__ = declarative.DeclarativeMeta
> def __classinit__(cls, newattrs):
> log.debug("%s.__classinit__" % cls)
> global classnr
> classnr = classnr + 1
Sounds good, thanks! There is no global locking issue we need to worry
about, right? I mean there is this global variable classnr.....
Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
|