[Zope] automagic reindexing of objects
Peter Bengtsson
peterbe at gmail.com
Fri Jun 17 11:31:17 EDT 2005
On 6/17/05, Jürgen Herrmann <Juergen.Herrmann at xlhost.de> wrote:
>
> [ Peter Bengtsson wrote:]
> > Personally I think one should stay the hell away from transactions.
> > They're not for you to fiddle with.
> > I understand your question and even though I think it's a bit crazy I
> > can see a benefit (simplicity for the programmer).
> >
> > How about a trickery solution like this:
> >
> > class CatalogPathAware:
> > def index_object(self, *a, **k):
> > print self.__class__.__name__, "in for indexing!"
> >
> > class _MyProduct(CatalogPathAware):
> > def __init__(self, id, title=''):
> > self.id = id
> > self.title = title
> > def setTitle(self, title):
> > # could be much more complicated
> > self.title = title
> >
> > class MyProduct(_MyProduct):
> > def setTitle(self, title):
> > _MyProduct.setTitle(self, title)
> > self.index_object()
> >
> > inst = MyProduct("instanceA")
> > inst.setTitle('Peter')
> >
> > print inst.title
> >
> >
> > You would basically rename your existing class from "Whatever" to
> > "_Whatever" and continue as before. This does mean however that you
> > have to explicitly write a function for each setter.
> >
> hmm, i can't see how this would help. if i call index_object in every
> attribute getter method, the indexing is done possibly several times,
> unnecessary and (cpu)time consuming.
>
Writes happen a lot less often but they also cost a lot more.
It'd be nice to be able to hotwire the parentless class so that it
magically "wraps" all functions that match on::
re.compile('set[A-Z]\w+')
It would be hard to find out what the functions are, eg::
class MyProduct(_MyProduct):
def __init__(self, *a, **k):
_MyProduct.__init__(self, *a, **k)
for fun in dir(_MyProduct):
if camel_setters_regex.findall(fun):
print "create a wrapping method called %s" % fun
How to magically create a method upon itself with an arbitary name is
something I don't know how to do but it's not impossible because I
know that Archetypes (cmf, plone) does it.
> juergen
> _______________________________________________________________________
>
> >> XLhost.de - eXperts in Linux hosting <<
>
> Juergen Herrmann
> Weiherweg 10, 93051 Regensburg, Germany
> Fon: +49 (0)700 XLHOSTDE [0700 95467833]
> Fax: +49 (0)721 151 463027
>
> ICQ: 27139974 - IRC: #XLhost at quakenet
> WEB: http://www.XLhost.de
>
--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
More information about the Zope
mailing list