Adrian, excellent job abstracting the common code into
`Form._html_output()`. Now, anyone can write there own `as_method()`
as a one-liner - with one minor problem...

On 12/7/06, Adrian Holovaty <[EMAIL PROTECTED]> wrote:
>
> On 12/1/06, James Bennett <[EMAIL PROTECTED]> wrote:
> > So maybe an as_dl() method needs to go in?
>
> With as_dl(), how would error messages be displayed?

I was going to suggest
    <dt>label</dt>
    <dd>error<dd>
    <dd>field<dd>

But looking at the code, the error string is passed in first
regardless of whether `errors_on_separate_row` or not. Perhaps
`_html_output()` should use the optional mapping key for string
substitution [1]. So, for example:

    - 93               output.append(normal_row % ((bf_errors, label, bf)))
    + 93              output.append(normal_row % ({ 'error' :
bf_errors, 'label' : label, 'field' : bf}))

Then

    as_dl(self):
                return
self._html_output(u'<dt>%(label)s</dt>\n<dd>%(error)s</dd>\n
<dd>%(field)s</dd>', u'?????', '</dd>', False)

Hmm, not sure how the top_errors would display here. Maybe someone
else could enlighten us on that.

Anyway, by key mapping string substitution, that would greatly enhance
the flexibility IMHO.  It would certainly make creating custom
`as_method()` functions easier/more flexible.

As an alternative, there is also Template strings [2], but key mapping
works fine and (I believe) was in python2.3 (or earlier) while
Template strings were introduced in python2.4.

[1]: http://www.python.org/doc/current/lib/typesseq-strings.html
[2]: http://docs.python.org/lib/node40.html


-- 
----
Waylan Limberg
[EMAIL PROTECTED]

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

Reply via email to