#!/usr/bin/env python2 # (C) 2003 Ben Collins-Sussman under the GNU General Public License. # See the file COPYING for details. import MySQLdb, cgi # enable debugging: displays detailed exceptions in web browser. import cgitb; cgitb.enable() # temporary: eventually put 'effrecipes.py' into a standard PYTHONPATH # location, like /usr/lib/python2.3/site-packages/ import sys sys.path.append('/home/sussman/projects/effrecipes/objects') import effrecipes # ----------------------------------------------------------------- def print_header(page_title): print "Content-type: text/html\n\n"; print "Effrecipes: edit record\n" print "

", page_title, "

\n\n" def print_footer(): print "" def print_new_form(): # create an empty form, all fields editable, Id will be auto-generated print '
\n' print '

Recipe Name:


' print '
' print '

Instructions:


' print '
' print '

Commentary:


' print '
' print '

Serving History:


' print '
' print '

Attribution:


' print '
' print '

Rating (a number):


' print '
' print '' print '
\n' def print_populated_form(Id, connection): # load object from the database, pre-populate form, Id not editable. recipe = effrecipes.recipe_lookup(Id, connection) print '
\n' print 'Recipe Id:', recipe.RecipeId, '
' print '
' print '

Recipe Name:


' print '
' print '

Instructions:


' print '
' print '

Commentary:


' print '
' print '

Serving History:


' print '
' print '

Attribution:


' print '
' print '

Rating (a number):


' print '
' print '' print '' print '
\n' # Main logic conn = MySQLdb.connect(user='effuser', passwd='effuser', db='effrecipes') form = cgi.FieldStorage() val = form["Id"].value # field is either record id or 'new' if val == 'new': print_header("New Recipe Details") print_new_form() else: print_header("Edit Recipe Details") print_populated_form(int(val), conn) print_footer() conn.close()