Document the configuration directives in config.py.
[bloggy.git] / post.cgi
blobdb762fe157e87c22f9413b66d5465250c6871a2e
1 #!/usr/bin/env python
3 import cgi
4 #import cgitb; cgitb.enable()
5 import sqlite3
7 import common
9 title = "Please enter a title."
10 text = "Type something interesting."
12 form = cgi.FieldStorage()
14 print 'Content-type: text/html; charset=UTF-8\n'
16 conn = common.connect()
18 if form.has_key("delete"):
19 for postid in form.getlist("delete"):
20 conn.execute("DELETE FROM entries WHERE id = ?", (postid,))
21 elif form.has_key("edit"):
22 (title, text) = conn.execute("SELECT title, text FROM entries WHERE id = ?", (form.getvalue("edit"),)).fetchone()
23 elif form.has_key("title") and form.has_key("text"):
24 if form.has_key("update"):
25 conn.execute("UPDATE entries SET title = ?, text = ? WHERE id = ?", (form.getvalue("title"), form.getvalue("text"), form.getvalue("update")))
26 else:
27 conn.execute("INSERT INTO entries VALUES (NULL, current_timestamp, ?, ?)", (form.getvalue("title"), form.getvalue("text")))
29 print '<form action="post.cgi" method="post">'
31 if common.getnumposts(conn) == 0:
32 print '<p>Nothing here yet.</p>'
33 else:
34 print '<table border="1">'
35 print '<tr><th>ID</th><th>Date</th><th>Title</th><th>Delete</th><th>Update</th></tr>'
36 for row in conn.execute("SELECT id, date, title FROM entries ORDER BY date DESC"):
37 print '<tr>'
38 print '<td>%s</td>' % row[0]
39 print '<td>%s</td>' % row[1]
40 print '<td>%s</td>' % ('<a href="index.cgi?id=' + str(row[0]) + '">' + row[2] + '</a>')
41 print '<td><input type="checkbox" name="delete" value="%s"></td>' % row[0]
42 print '<td><input type="radio" name="edit" value="%s"></td>' % row[0]
43 print '</tr>'
44 print '</table>'
46 if form.has_key("edit"):
47 print '<p><b>Editing post %s.</b></p>' % form.getvalue("edit")
48 print '<input type="hidden" name="update" value="%s">' % form.getvalue("edit")
50 print '<p><input name="title" type="text" value="%s"></p>' % cgi.escape(title, True)
51 print '<textarea name="text" id="text">%s</textarea>' % cgi.escape(text, True)
53 print '<p><button type="submit" name="submit">Submit</button></p>'
55 print '</form>'
57 conn.commit()
58 conn.close()