Krys Wilken <[EMAIL PROTECTED]> writes:

> my_model_instance.my_field =
> turbogears.util.slugify(some_other_text_field_data)
>
> ... or something like that, anyway.

this is what i use on thraxil.org: 

def make_slug(title="no title"):
    title = title.strip()
    slug = re.sub(r"[\W\-]+","-",title)
    slug = re.sub(r"^\-+","",slug)
    slug = re.sub(r"\-+$","",slug)
    return slug

not very sophisticated, but it works for my purposes. i also have a
modified version that does some rough conversion of unicode down to
ascii that i wrote for the 'Wicked' product for Plone. 

one general purpose slugification routine may not be the best solution
though. some applications will have specific requirements. i've worked
with the journalism school here and they sometimes require a slug to be
in a specific format like 'authorlastname-oneworddescriptionofstory'.
other times autogenerated ones would be ok.

one other bit of advice is to prefer '-' over '_'. both are about
equally readable but search engines are smarter about '-'. if you have
/foo-bar/ in the url of a page, google will index it and relate 'foo'
and 'bar' to the page but if it's /foo_bar/, it doesn't recognize the
underscore as a word seperator so it will relate it to 'foo_bar'. 

-- 
anders pearson : http://www.columbia.edu/~anders/
   C C N M T L : http://www.ccnmtl.columbia.edu/
        weblog : http://thraxil.org/

Attachment: pgpFzBLBMCO4d.pgp
Description: PGP signature

Reply via email to