[Zope-dev] ZFormulator review...
Martijn Pieters
mj@digicool.com
Tue, 11 Jan 2000 10:40:41 -0500
> -----Original Message-----
> From: Chris McDonough [mailto:chrism@digicool.com]
>
> I'm working on a product that does a similar thing (except
> the object is
> a "font manager"). I'd be very interested to see how you're doing it
> Martijn...
>
Here's what I do:
def initialize(context):
# Add the scheduler to the Zope root, and make it undeletable.
# I know, this is an extreme hack. But supplying a patch for
# OFS/Application.py is just not practical.
# We also add a hook to the Product object, so we can make
# the scheduler object removable again when this Product is deleted.
app = context._ProductContext__app # Don't you love private name
mangling
if not hasattr(app, 'Scheduler'):
oScheduler = ZScheduler.ZScheduler()
app._setObject('Scheduler', oScheduler)
prod = context._ProductContext__prod
setattr(prod, 'manage_beforeDelete', beforeDeleteHook())
get_transaction().note('Added Scheduler')
get_transaction().commit()
if 'Scheduler' not in app._reserved_names:
app._reserved_names = app._reserved_names + ('Scheduler',)
# initialize ZEvent objects
context.registerClass(
ZEvent.OneTimeZEvent,
permission = 'Add ZEvent',
constructors = (
ZEvent.manage_addOneTimeZEventForm,
ZEvent.manage_addOneTimeZEvent),
icon = 'www/OneTimeZEvent.gif')
class beforeDeleteHook(Persistent):
""" Make sure that the Scheduler object can be deleted
This should be persistent....
"""
def __call__(self, prod, products):
app = products.aq_parent.aq_parent
rn = list(app._reserved_names)
try:
rn.remove('Scheduler')
app._reserved_names = tuple(rn)
except ValueError:
pass
The beforeDeleteHook object makes sure that if you _manually_ delete the
ZScheduler Product in the management interface, the protection on the
Scheduler object is removed. As this code is removed when you delete the
actual Product subdir from the filesystem this does not get executed
when you uninstall your Product that way.
--
Martijn Pieters, Software Engineer
| Digital Creations http://www.digicool.com
| Creators of Zope http://www.zope.org
| mailto:mj@digicool.com ICQ: 4532236
| PGP:
http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
-------------------------------------------