#!/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 'Enter new name:
' print '
' print '' print '
\n' def print_populated_form(Id, connection): # load object from the database, pre-populate form, Id not editable. unit = effrecipes.unit_lookup(Id, connection) print '
\n' print 'Record Id:', unit.UnitId, '
' print '
' print 'Change the name:
' 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' print_header("Editing a 'Unit' Record") if val == 'new': print_new_form() else: print_populated_form(int(val), conn) print_footer() conn.close()