hi to all!
a couple of questions. i'm writing a simple blog to get used to web2py
and get my hands dirty with it (and i love it so far!).

each blog post has a title. as i want that title to be in the url when
retrieving the post, i need what in django is called a "slug"  field,
or a pretty, url-friendly version of a string so that "This is
the      first POST of my awesome site!!!!! :D I like accents èàò"
becomes "this-is-the-first-post-of-my-awesome-site-i-like-accents-
aeo". using this i can have pretty urls like mysite/blog/post/show/
this-is-the-first-post-of-my-awesome-site-i-like-accents-aeo.

i've looked into the documentation but i could not find a web2py
utility to have this. i have put together my "urlify" function to
solve the problem, but i think this is a pretty common task. when it's
done, if it's not there yet and i simply couldn't find it, i'll
contribute it.

in the very same phase i had a problem populating this field. i use
SQLFORM to create the "insert new post" form. of course the "slug"
field is not visible as it is derived by another field (title). how
can i assign automatically a value to that field, in the "insert"
phase, based on another value?

this is a stripped down example of the code i use right now, but i'm
not sure it is the most elegant way to solve the problem

------------------------
# MODEL

db.define_table('post',
                    Field('title', length=100, required=True,
unique=True),
                    Field('slug', length=100, unique=True),
                    Field('text', 'text'))

# CONTROLLER

form.vars.slug = utils.urlify(request.vars.title)
form.accepts(request.vars, session)

------------------------

one last question: as far as i've seen, form.accepts works both as
"insert record" and "validate form". if i don't have validators
(requires=), how can i specify "only if the form has submitted do
form.accepts"?

thanks in advance,
gustavo
-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.


Reply via email to