On 2/27/07, Yves-Eric <[EMAIL PROTECTED]> wrote:
> I am sorry but I must say, I am finding quite underwhelming having to
> jump through such hoops and loops just to display a simple error
> message with meaningful field names... Either I am doing something
> fundamentally wrong in the way I am using FormEncode (but again, I am
> just using simple schema-based validation, straight from the Pylons
> documentation), or there is a serious design flaw in FormEncode...
>
> Anyway, I got something working for now, but it is very
> unsatisfactory: I copy/pasted schema.py's format_compound_error() into
> my code, and customized it to lookup the field name in an
> internal_name->display_name dictionary. Looks like this:
>
>     display_names = {
>         'ptypes': 'Party types',
>         'itypes': 'Invoice types',
>         'pstates': 'Party states',
>         sstates': 'Sent states',
>     }
>
> and in my custom format_compound_error():
>
>     [...]
>     elif isinstance(v, dict):
>         l = v.items()
>         l.sort()
>         return ('%s\n' % (' '*indent)).join(
>             ["%s: %s" % (display_names.get(k, k),
> format_local_compound_error(value, indent=len(k)+2))
>              for k, value in l
>              if value is not None])
>
>
> While it works and will get the customer off my back for a while, this
> is very unsatisfactory because:
>
> 1) copy/paste programming BAD! (TM)
>
> 2) the display name of the field is separated from its definition in
> the schema, not nice.
>
> 3) As the display_names dictionary is global, I cannot have "itypes"
> mean "Invoice types" on one form, and "Inbox types" on another.
>
>
> Any suggestion on how this could be done more nicely?

Maybe you should bring it up on the Paste or the FormEncode mailing
lists?  I'm not trying to get rid of you, but maybe someone there will
have a quick response.

Best Regards,
-jj

-- 
http://jjinux.blogspot.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to