On Tue, Feb 08, 2000 at 09:25:53AM -0800, Joseph Pallas wrote:
On Wed, 9 Feb 2000, Evan Gibson wrote:
What I _think_ is happening is that gadfly can't handle carriage returns and line feeds in the string input. (Which is why I was trying things like "virtual" to perhaps get rid of them.)
This is an all-too-frequently asked question. First, pay no attention to people who say it's a bug in gadfly. The fundamental problem is that there is no SQL standard for including linebreaks in strings. Any solution for including the linebreaks that works with one database is pretty much guaranteed not to work with another. You don't want to be locked in to using one database (I know: I've been forced to move from gadfly so that non-python tools can get to the data).
I'm halfway through moving to oracle, but for the moment I'm still in gadfly land. One thing I've found _immensely_ useful when working with gadfly is the gfplus.py script I found while trolling deja. It provides you with an interactive shell for Gadfly along the lines of sqlplus. It's at http://endeavor.med.nyu.edu/~jeff/gfplus/ But that's changing the topic... Since it's not a bug, but rather a lack of a standard, then the datbase isn't the right place to fix it. It shouldn't be left the way it is, though, since it's a big pain for newbies and pretty hard to debug (for the longest time I thought there was something wrong with my query. I'd found another place where I did dmtl instead of dtml and was looking for something similar.) I think the proper place for a fix would be Zope's typecasting features. Instead of just ":text" making the output text with linefeeds we could add ":text_clean" which takes all the text from the textarea and replaces linefeeds with single spaces, and ":text_html" which converts them to <br> [like the linefeed_to_br function, but without adding a linefeed back in after the br!]
I use a simple whitespace cleaner: _.string.join(_.string.split(textfield))
Thanks for that. And thanks to the other guys who helped too.
This is the simplest thing if you don't care about the original linebreaks (I warn my users that linebreaks will be ignored). If your text is destined only for HTML and you want to preserve line breaks, you could instead use _.string.join(_.string.split(textfield, '\n'), '<BR>'). I decided to keep HTML out of my database; you may decide otherwise.
Nod. We need formatting methods to cover both decisions.
Hope this helps. joe
-- Evan ~ThunderFoot~ Gibson ~ nihil mutatem, omni deletum ~ May the machines watch over you with loving grace.