Re: Getting the message key?
Felix Schwarz <felix.schwarz-S0/[email protected]> Wed, 26 Mar 2008 16:01:36 +0100
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Andreas Klostermann wrote:
> Otherwise you might want to subclass the Invalid exception for
> communication between Validators and other code. You should however only
> raise an Invalid exception when the data is "invalid" which means
> unprocessable. I would not recommend to nag the user a lot about "not
> perfect" data.
Its not about "not perfect" data: A user name that is already registered can't
be registered again. But I want to show some additional help for the user and
in the current situation it is very hard to tell the difference between "user
name not allowed" (illegal syntax) and "user name already in use".
However it would be possible quite easily if I could access the message key.
One solution I thought about is to patch the messages function in formencode
so that it returns not a string but this object:
class WrappedMsg(object):
def __init__(self, msg, key=None):
self.msg = msg
self.key = key
def __repr__(self):
return "WrappedMsg<%s: %s>" % (self.key, self.msg)
def __str__(self):
return self.msg
If you use that message verbatim in a template engine like genshi, you won't
see a difference to a normal message string. Maybe this could be a flag in
formencode to active that new behavior...
If I did not get your point, please elaborate :-)
fs
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace