Skip to content.

Etria Lists

 

[quills-dev] Re: Entry description generated automatically

Maurits van Rees m.van.rees at zestsoftware.nl
Mon Dec 18 16:27:47 UTC 2006


Andrey Fedoseev, on 2006-12-17:
> If weblog entry doesn't have a description then description is generated
> from entry's full text (I use first 50 words). It's useful for me as I
> want all entries to have description but I'm too lazy to fill it
> manually :)

I did it like this in a custom Zope 2 site:

# Print the first paragraph or the first `maxchars' characters,
# whichever is shorter.

text=context.text
maxchars=1000
i=0
while i < maxchars and i < len(text):
    if text[i:i+2]=='\n\n':
        print text[:i]
        break
    i=i+1
if i == maxchars:
    print text[:maxchars] + "..."
else:
    if i == len(text):
        print text
return printed

-- 
Maurits van Rees | http://maurits.vanrees.org/ [NL]
            Work | http://zestsoftware.nl/
"Do not worry about your difficulties in computers,
 I can assure you mine are still greater."



More information about the quills-dev mailing list