[Grok-dev] distinguish between a create or an edit situation in a formlib constraint
Dr. Volker Jaenisch
volker.jaenisch at inqbus.de
Thu Jul 30 21:18:43 EDT 2009
Hi Grok-People!
Maybe this should go better to the formlib people
but Grok wrapps formlib in a special way ..
I have property "name" that should be unique
class IKvmInstance(interface.Interface):
"""Defines a KVM instance."""
name = schema.TextLine(
title = u'KVM Name',
default = u'VM1',
required = True,
constraint = validateVMName,
)
In validateVMName I check for the existance of a VM with the same name
and reject
the request if a VM with the given name already exists.
from zope.schema import ValidationError
class VMNameAlreadyInUse(ValidationError):
"VM Name already in use"
def validateVMName( name ):
# Why the heck this is called at grok boot-time??
if grok.getSite() == None : return True
if grok.getSite().kvmManager.kvmContainer.has_key( name ):
raise VMNameAlreadyInUse
return True
This work fine for the creation but fails on editing a KVMInstance. Is
there a generically way to do it?
Or will I have to impose a flag on the instance that I check to see that
the instance is already created?
How can I seperate the creating and the edition use-case programmatically.
Any Hints appreciated
Best Reagards
Volker
--
====================================================
inqbus it-consulting +49 ( 341 ) 5643800
Dr. Volker Jaenisch http://www.inqbus.de
Herloßsohnstr. 12 0 4 1 5 5 Leipzig
N O T - F Ä L L E +49 ( 170 ) 3113748
====================================================
More information about the Grok-dev
mailing list