#! /usr/local/bin/python """ Add a comment. """ import cgi, time import comments_config from Comment import Comment form = cgi.FieldStorage() path = form['path'].value # # first process comments. # if form.has_key('submit') and form['submit'].value == 'add comment': person = 'Anonymous' if form.has_key('name'): person = form['name'].value webpage = '' if form.has_key('webpage'): webpage = form['webpage'].value text = '' if form.has_key('comment'): text = form['comment'].value if text: comment = Comment(person, webpage, text, time.time()) comment_dict = comments_config.load_comments() comments = comment_dict.get(path, []) comments.append(comment) comment_dict[path] = comments comments_config.save_comments(comment_dict) # # now redirect. # redirect_url = comments_config.wfiles_cgi + '/' + path print 'Status: 303 Redirect' print 'Location: %s' % (redirect_url,) print 'Content-type: text/html\n\n' print 'You should have been redirected to %s' % (redirect_url,)