Deformed Form

Victor Subervi victorsubervi at gmail.com
Thu Jun 10 13:48:18 EDT 2010


No, I think you've misunderstood because while I thought I was being clear I
probably was not. So here is the complete code of
create_edit_passengers3.py:

#!/usr/bin/python

import cgitb; cgitb.enable()
import cgi
import sys,os
sys.path.append(os.getcwd())
import MySQLdb
from login import login
import fpformat
from New_Passengers_Curr_Customers import New_Passengers_Curr_Customers
from New_Passengers_Addl_Customers import New_Passengers_Addl_Customers
from New_Passenger import New_Passenger

form = cgi.FieldStorage()

def sortedDictValues(adict):
  items = adict.items()
  items.sort()
  return [value for key, value in items]

def create_edit_passengers3():
  print "Content-Type: text/html"
  print
  print '''
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<head xmlns="http://www.w3.org/1999/xhtml">
</head>
<body>
'''
  user, passwd, db, host = login()
  database = MySQLdb.connect(host, user, passwd, db)
  cursor = database.cursor()
  cursor.execute('select id from Flights;')
  flights = [itm[0] for itm in cursor]
  cursor.execute('select id, first_name, middle_name, last_name, suffix from
Customers;')
  customers = cursor.fetchall()
  try:
    cursor.execute('select p.id, c.first_name, c.middle_name, c.last_name,
c.suffix, c.discount, p.flights_id, p.name, f.price, c.id from Customers c
join Passengers p on c.id=p.customer_id join Flights f on p.flights_id=f.id
;')
    passengers = cursor.fetchall()
    print '<form method="post" action="create_edit_passengers4.py">\n'
    start_html = "<table border='2'>\n  <tr>\n
<td><b>Delete?</b></td>\n    <td><b>Flight</b></td>\n
<td><b>Name</b></td>\n    <td><b>Discount</b></td>\n
<td><b>Price</b></td>\n  </tr>\n"
    passengers_html = []
    ids = []
    i = 0
    for passenger in passengers:
      do_delete = form.getfirst('%s:delete' % passenger[0])
      New_Passenger(passenger, do_delete)
    printHTML = sortedDictValues(dict(zip(ids, passengers_html)))
    if len(printHTML) > 0:
      print start_html
    for html in printHTML:
      print html
    print "</table>"
  except MySQLdb.ProgrammingError:
    pass
  New_Passengers_Curr_Customers(customers, flights,
new_passengers_curr_customers)
  new_passengers_addl_customers =
int(form.getfirst('new_passengers_addl_customers', 0))
  New_Passengers_Addl_Customers(customers, flights,
new_passengers_addl_customers)
  if (new_passengers_addl_customers > 0) or (new_passengers_curr_customers >
0):
    print "<input type='submit' value=' Send ' />"
  print '</body>\n</html>'
  cursor.close()

create_edit_passengers3()



Now, create_edit_passengers3() is called by the form/submit button in (you
guessed it) create_edit_passengers2.py, the latter containing a var in it
which *should* be accessible to create_edit_passengers3.py, one would think.
*However*, if I put the following line in create_edit_passengers3.py (even
in the beginning outside the fn of the same name):

  new_passengers_curr_customers =
int(form.getfirst('new_passengers_curr_customers', 0))

the value will *always* be 0. *However*, if I put that *same_line* of code
in New_Passengers.py (and fn of same name). it will give me the correct
value, which I can then pass back to the calling script
(create_edit_passengers3.py). Can you explain to me why it would behave like
that? I've never had a problem like this before and I've worked with
accessing variables by this manner in many a script.
TIA,
beno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100610/4860d5ee/attachment-0001.html>


More information about the Python-list mailing list