#!/usr/bin/env python2 import cgi # enable debugging: displays detailed exceptions in web browser. import cgitb; cgitb.enable() import MySQLdb # 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 # ----------------------------------------------------------------- # Initialize database connection conn = MySQLdb.connect(user='effuser', passwd='effuser', db='effrecipes') # Grab the object from the database form = cgi.FieldStorage() val = form["Id"].value # this better be a valid ID recipe = effrecipes.recipe_lookup(int(val), conn) recipe_ingredients = recipe.ingredientlist(conn) # Initial generic HTML 'header' output print "Content-type: text/html\n\n"; print "Effrecipes -- Recipe Display\n" print '

Recipe: "' + recipe.Name + '"

\n\n' # Show ingredient list print '

Ingredients

' print '

(Change ingredient list)

' print "\n" for record in recipe_ingredients: unit = effrecipes.unit_lookup(record.UnitId, conn) ingredient = effrecipes.ingredient_lookup(record.IngId, conn) print '' print '' print '' print '' print '
' print "
Amount = ' + str(record.Amount) + '' + unit.Name + '' + ingredient.Name + '

" # Show the recipe record itself print '

Details

' print '

(Change these details)

' print '\n' print '' print '' print '' print '' print '' print '' print '' print "
Recipe ID ', recipe.RecipeId, '
Name ' + recipe.Name + '
Rating ', recipe.Rating, '
Instructions ' + recipe.Instructions + '
Commentary ' + recipe.Commentary + '
Serving History ' + recipe.ServingHistory \ + '
Attribution ' + recipe.Attribution + '

" # Cleanup and exit print "" conn.close()