3 # Copyright (c) 2008, 2009, Simon Morgan <sjm@spamcop.net>
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 conn
= common
.connect()
24 form
= cgi
.FieldStorage()
26 print "Content-type: text/html; charset=UTF-8\n"
28 print '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
31 common
.print_headers(config
.TITLE
)
35 numposts
= common
.getnumposts(conn
)
37 common
.print_msg('Nothing here yet. How about you <a href="post.cgi">post</a> something interesting?')
39 if form
.has_key("id"):
40 post
= common
.getpost(conn
, form
.getvalue("id"))
42 (date
, title
, text
) = post
43 common
.print_post(title
, text
, date
)
45 common
.print_msg("No such post.")
48 if form
.has_key("offset"):
49 offset
= int(form
.getvalue("offset"))
50 posts
= common
.getposts(conn
, offset
, config
.NUMPOSTS
)
51 for (postid
, date
, title
, text
) in posts
:
52 title
= '<a href="index.cgi?id=%s">%s</a>' % (postid
, title
)
53 common
.print_post(title
, text
, date
)
55 # Only print the navigation bar if the number of posts exceeds
56 # the number to be displayed per page.
57 if numposts
> config
.NUMPOSTS
:
58 print '<div id="navigation">'
60 newoffset
= offset
- config
.NUMPOSTS
63 print '<a href="index.cgi?offset=%s">Prev</a>' % newoffset
64 if offset
+ config
.NUMPOSTS
< numposts
:
65 newoffset
= offset
+ config
.NUMPOSTS
66 print '<a href="index.cgi?offset=%s">Next</a>' % newoffset