4 #import cgitb; cgitb.enable()
12 def displaypost(date
, title
, body
):
13 """Formats and prints a post"""
14 print '<h1>%s</h1>' % title
15 print '<h3>%s</h1>' % date
16 print '%s' % textile
.textile(body
)
18 starttime
= time
.time()
20 form
= cgi
.FieldStorage()
22 print "Content-type: text/html; charset=UTF-8\n"
24 conn
= common
.connect()
26 numposts
= common
.getnumposts(conn
)
28 print '<p>Nothing here yet. How about you <a href="post.cgi">post</a> something interesting?</p>'
30 if form
.has_key("id"):
31 if common
.getnumposts(conn
, form
.getvalue("id")) > 0:
32 (date
, title
, text
) = conn
.execute("SELECT date, title, text FROM entries WHERE id = ?", (form
.getvalue("id"),)).fetchone()
33 displaypost(date
, title
, text
)
35 print "<p>No such post.</p>"
38 if form
.has_key("offset"):
39 offset
= int(form
.getvalue("offset"))
40 for row
in conn
.execute("SELECT * FROM entries ORDER BY date DESC LIMIT ? OFFSET ?", (config
.NUMPOSTS
, offset
)):
41 displaypost(row
[1], '<a href="index.cgi?id=%s">%s</a>' % (row
[0], row
[2]), row
[3])
42 print '<p align="center">'
44 newoffset
= offset
- config
.NUMPOSTS
47 print '<a href="index.cgi?offset=%s">Prev</a>' % newoffset
48 if offset
+ config
.NUMPOSTS
< numposts
:
49 newoffset
= offset
+ config
.NUMPOSTS
50 print '<a href="index.cgi?offset=%s">Next</a>' % newoffset
54 print '<p>Page generated in %s seconds.</p>' % (time
.time() - starttime
)