Insane Problem

Victor Subervi victorsubervi at gmail.com
Thu Dec 3 10:12:06 EST 2009


On Thu, Dec 3, 2009 at 8:02 AM, Victor Subervi <victorsubervi at gmail.com>wrote:

> On Thu, Dec 3, 2009 at 6:07 AM, Victor Subervi <victorsubervi at gmail.com>wrote:
>
>> On Wed, Dec 2, 2009 at 4:08 PM, MRAB <python at mrabarnett.plus.com> wrote:
>>
>>> Victor Subervi wrote:
>>>
>>>> Hi;
>>>> I have spent 2-3 hours trying to track this bug. Here's the code
>>>> snippet:
>>>>
>>>>  form = cgi.FieldStorage()
>>>>  fn = getattr(options, 'products')
>>>>  ourOptionsNames = []
>>>>  optionsNames, doNotUse  = fn('names')
>>>>  for name in optionsNames:
>>>>    test = table + '-' + name
>>>>    print test
>>>>    check = form.getfirst(test, '')
>>>>    print check
>>>>    if check != '':
>>>>      ourOptionsNames.append(name)
>>>>  Now, when it looks through with test=='products', it doesn't report
>>>> that any of the values from the form are checked. However, when I explicitly
>>>> write out something like:
>>>> print form.getfirst('products-sizes', '')
>>>> which I checked on the form from the referring page, it does in fact
>>>> print out! My test prints show that 'products-sizes' is being passed to
>>>> "check" and should therefore be appended to "ourOptionsNames". But it isn't!
>>>> What am I missing here??
>>>>
>>>>  What do the print statements actually print? Please copy and paste
>>> their
>>> output.
>>>
>>
>> For the part in question they print __nothing__. That's the point.
>> V
>>
> I believe I mentioned in my first post that the "print test" does print the
> exact fields being called from the referring page. The "print check" prints
> nothing. Another thing that's strange is that there are two tables of fields
> in the referrer page; it will print the first of those tables--whichever of
> the two I choose--but not the latter. Perhaps this is a bug in the cgi
> interface? Perhaps I should migrate this to mod_python?
> TIA,
> V
>
Perhaps the following code, which is from the referrer, will help. I don't
see how it makes any difference at all, since all the code is printed
between the opening form and the submit button:

#!/usr/bin/python

import cgitb; cgitb.enable()
import MySQLdb
import cgi
import sys,os
sys.path.append(os.getcwd())
from login import login
import string
import options
from particulars import optionsTables, addStore

def chooseOptions():
  print '''Content-Type: text/html\r\n
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<form action='chooseOptions2.py' method='post'>
'''
  storesTables = []
  junkStores = string.join(addStore(), ', ')
  for table in optionsTables():
    if table not in ('particulars', junkStores):
      storesTables.append(table)
  bgcolors = ['F2F6D3', 'F2DDD3', 'D7DDD3']
  myOptions = []
  myMeanings = []
  for table in storesTables:
    try:
      fn = getattr(options, table)
      opts, means = fn('names')
      myOptions.append(opts)
      myMeanings.append(means)
    except:
      pass
  i = 0
  print "<font size='4'><b>Please select which of the option groups below
you would like to associate with each store. On the next page, you will have
the opportunity to select which options within each option group you would
like to have in your selection for each store.</b></font><br /><br />"
  for table in storesTables:
    print "<table align='center' bgcolor='#%s' border='1'>\n <tr>\n  <td
colspan='3'>\n" % bgcolors[i]
    print "<h1 align='center'>%s</h1>\n  </td>\n </tr>\n" %
(table[0].upper() + table[1:])
    print " <tr>\n  <td align='center'><b>Option</b></td>\n  <td
align='center'><b>Definition</b></td>\n  <td
align='center'><b>Check</b></td>\n </tr>\n"
    j = 0
    while j < len(myOptions[0]):
      print " <tr>\n  <td>%s</td>\n  <td>%s</td>\n  <td
align='center'><input type='checkbox' name='%s' /></td>\n </tr>\n" %
(myOptions[0][j], myMeanings[0][j], table + '-' + myOptions[0][j])
      j += 1
    print "</table><br /><br />\n"
    i += 1
  print '''
<div align='center'>
<input type='submit' value=' Send ' />
</div>
</form>
</body>
</html>'''

chooseOptions()

TIA,
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091203/d48bea33/attachment-0001.html>


More information about the Python-list mailing list