On Thu, Dec 3, 2009 at 10:53 AM, Carsten Haese <carsten.ha...@gmail.com>wrote:
> Victor Subervi wrote: > > In order to help you diagnose the problem, we need to see the *exact* > > code you're running, we need to see the *exact* inputs going into it, > > and we need to see the *exact* output coming out of it. > > > > > > Let's see your answers and see if you're right that the above output > > helps you arrive at the correct conclusion. > > No, it doesn't, because you've only provided one third of what I asked > for. I also asked for the code and the inputs that go into it. > I provided those earlier. To be sure I don't miss anything that may be important, here is the entire code for chooseOptions.py, the referrer. What I consider to be the important code is between the <SNIPPETS>: #!/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 = [] <SNIPPET> for table in storesTables: try: fn = getattr(options, table) opts, means = fn('names') myOptions.append(opts) myMeanings.append(means) except: pass </SNIPPET> 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 />" <SNIPPET> 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 <SNIPPET> print ''' <div align='center'> <input type='submit' value=' Send ' /> </div> </form> </body> </html>''' chooseOptions() Here is the pared-down code (to the "products") from options.py: def products(which='', specificTables=[]): code = [] names = [] meanings = [] code.append(['Extra-small', 'Small', 'Medium', 'Large', 'XLarge', 'XXLarge', 'XXXLarge']) meanings.append('The standard sizes.') names.append('sizes') if which == 'names': for name in colors('products', 'names'): names.append(name) for meaning in colors('products', 'meanings'): meanings.append(meaning) return names, meanings elif which == 'specificTables': whichTablesToReturn = [] colorsTables, colorsNames = colors('products', 'specificTables', specificTables) for name in colorsNames: names.append(name) for table in colorsTables: code.append(table) i = 0 while i < len(names): # We utilize the name of the table to determine where it is in the code tuple for table in specificTables: if names[i] == table: whichTablesToReturn.append(i) i += 1 returnTheseTables = [] for table in whichTablesToReturn: returnTheseTables.append(code[table]) returnTheseNames = [] for table in whichTablesToReturn: returnTheseNames.append(names[table]) i = 0 all = '' table = '' while i < len(returnTheseNames): table += "<table border='1'>\n <tr>\n <td colspan='16' align='center'><b>%s</b></td>\n </tr>" % returnTheseNames[i] j = 0 for elt in code[i]: if (j + 8) % 8 == 0: table += ' <tr>\n' table += ' <td>%s</td>\n' % code[i][j] table += " <td><input type='checkbox' name='%s' value='%s' /></td>" % (returnTheseNames[i], returnTheseTables[i][j]) if (j + 1) % 8 == 0: table += ' </tr>\n' j += 1 if table[-6:] != '</tr>\n': table += ' </tr>\n' table += '</table>\n' all += table + '<br /><br />' i += 1 print all else: i = 0 all = '' if which != '': # I place a dummy value in here to get what I want ourCode = [] ourMeanings = [] ourNames = specificTables i = 0 for name in names: for check in ourNames: if name == check: ourCode.append(code[i]) ourMeanings.append(meanings[i]) i += 1 else: ourCode = code ourMeanings = meanings ourNames = names ourColors = [] i = 0 while i < len(ourNames): if ourNames[i] in names: table = '<i>%s</i>\n' % ourMeanings[i] table += "<table border='1'>\n <tr>\n <td colspan='16' align='center'><b>%s</b></td>\n </tr>" % ourNames[i] j = 0 for elt in ourCode[i]: if (j + 8) % 8 == 0: table += ' <tr>\n' table += ' <td>%s</td>\n' % ourCode[i][j] table += " <td><input type='checkbox' name='%s' value='%s' /></td>" % (ourNames[i], ourCode[i][j]) if (j + 1) % 8 == 0: table += ' </tr>\n' j += 1 if table[-6:] != '</tr>\n': table += ' </tr>\n' table += '</table>\n' all += table + '<br /><br />' else: # This must be a color option ourColors.append(ourNames[i]) i += 1 all += colors('products', 'junk', ourColors) return all Here is the chooseOptions2.py, with <SNIPPET>: #! /usr/bin/python import cgitb; cgitb.enable() import cgi import sys,os sys.path.append(os.getcwd()) from login import login import string import options from particulars import optionsTables, addStore def optionsPrintout(table): form = cgi.FieldStorage() fn = getattr(options, table) ourOptionsNames = [] optionsNames, doNotUse = fn('names') <SNIPPET> for name in optionsNames: check = form.getfirst(table + '-' + name, '') if check != '': ourOptionsNames.append(name) try: return fn('junk', ourOptionsNames) except: pass <SNIPPET> def chooseOptions2(): print '''Content-Type: text/html\r\n <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <form action='chooseOptions3.py' method='post'> ''' print '<h2>Which options shall we associate with the items in each shop?</h2><br />' storesTables = [] junkStores = string.join(addStore(), ', ') for table in optionsTables(): if table not in ('particulars', junkStores): storesTables.append(table) bgcolors = ['F2F6D3', 'F2DDD3', 'D7DDD3'] i = 0 for table in storesTables: try: fn = getattr(options, table) # This is only here to trigger the try statement print "<table border='1' bgcolor='#%s'>\n <tr>\n <td>\n" % bgcolors[i] print '<h1 align="center">%s</h1>' % (table[0].upper() + table[1:]) print optionsPrintout(table) print " </td>\n </tr>\n</table><br /><br />\n" except: # All tables must have the products options in them by defualt print "<table border='1' bgcolor='#%s'>\n <tr>\n <td>\n" % bgcolors[i] print '<h1 align="center">%s</h1>' % (table[0].upper() + table[1:]) # print optionsPrintout('products') print " </td>\n </tr>\n</table><br /><br />\n" i += 1 print ''' </td></tr></table><br /><br /> <div align='center'> <input type='submit' value=' Send ' /> </div> </body> </html>''' chooseOptions2() TIA, V
-- http://mail.python.org/mailman/listinfo/python-list