question on text area and output

10 views
Skip to first unread message

coolaid

unread,
Jun 25, 2009, 10:30:04 PM6/25/09
to web2py Web Framework
I would like to retain the the spacing information (next line, /n)
when I retrieve text data from the database.

for example, when I put following into a form

test
test
test

this is what I get out of the database in the views.

test test test

I'd like it retrieve

test
test
test

here is my code

IN CONTROLLERS (default.py, has two functions)

def create_text():
form = SQLFORM(db.task, fields=[ 'body'])
if form.accepts(request.vars, session):
session.flash = 'document saved'
redirect(URL(r=request,f='review', args = form.vars.id))
elif form.errors: response.flash = 'page not saved'
return dict(form=form)

def review():
thistask=db((db.task.id==request.args[0])&(db.task.auth_user_id
==session.auth.user.id )).select()[0]
return dict(body = thistask.body)

IN VIEWS (there are two files)

create_text.html (view to create text)

{{=form}}

review.html (view to edit text)

{{=body}}
Message has been deleted
Message has been deleted

mdipierro

unread,
Jun 26, 2009, 12:16:15 AM6/26/09
to web2py Web Framework
replace

{{=body}}

with

{{=TAG[''](*[P(p) for p in body.split('\n')]) }}

or, if you want to allow HTML tags in texts

{{=XML(body.replace('\n','<br>'),sanitize=True)}}

of you want to allow WIKI syntax

{{from gluon.contrib.markdown import WIKI}}
{{=WIK(body)}}

Massimo

Tim Michelsen

unread,
Jun 29, 2009, 3:34:05 PM6/29/09
to web...@googlegroups.com
> {{=TAG[''](*[P(p) for p in body.split('\n')]) }}
>
> or, if you want to allow HTML tags in texts
>
> {{=XML(body.replace('\n','<br>'),sanitize=True)}}
>
> of you want to allow WIKI syntax
What about rest from the wiki?
When will this be added to the devel branch?
Please do give this tip a more prominent place in the documentation...

mdipierro

unread,
Jun 29, 2009, 4:00:23 PM6/29/09
to web2py Web Framework
reST requires a relatively large third party library therefore it will
not incorporated in web2py (i.e. they will not be distributed
together). You can use reST right now if you easy_install it.

try:
from docutils import core
from docutils.writers.html4css1 import Writer,HTMLTranslator
def reSTify(string):
class NoHeaderHTMLTranslator(HTMLTranslator):
def __init__(self, document):
HTMLTranslator.__init__(self,document)
self.head_prefix = ['','','','','']
self.body_prefix = []
self.body_suffix = []
self.stylesheet = []
w = Writer()
w.translator_class = NoHeaderHTMLTranslator
return core.publish_string(string,writer=w)
WIKI=lambda text: XML(reSTify(text))
except:
from gluon.contrib.markdown import WIKI
Reply all
Reply to author
Forward
0 new messages