[Zope] Question about Python with Zope/ZSQL

John Tynan john.tynan at riomail.maricopa.edu
Wed Aug 25 12:04:46 EDT 2004


I have, a question about using python with zope/zsql methods and wondered
if anyone might be able to offer some advice.

I have a python script called:
  addNewSurvey
which, before adding a new record to a database,
checks for two things:
  an existing surveyid
  and
  an existing listenerid
both of which are colums in the same 'surveys' table.

I have two python scripts:
  checkforsurvey(suveryid)
    and
  checkforlistener(listenerid)
each of which which, on their own, successfully return a string of 'true'
if a duplicate value exists.

My problem, and my question, arises in the in the addNewSurvey script (see
attached). What might be wrong with my syntax in addNewSurvey that is preventing
me from adding a record successuflly? There are no error messages when it
runs, but no visible results either?

Any suggestions you might have are appreciated.

John Tynan - webmaster
KJZZ.org / KBAQ.or
480.774.8462


-------------- next part --------------
test = context.checkforsurvey(surveyid=surveyid)
true = 'true'

def match(test, true):
  if test == true:
    return 'redirect'
    target = '../duplicatesurvey'
    return context.REQUEST.RESPONSE.redirect(target)
  else:
    return 'add survey'
    test2 = context.checkforlistener(listenerid=listenerid)
    def match(test2, true):
      if test == true:
        context.sqlAddSurvey(surveyid=surveyid, listenerid=listenerid, region=region, firstname=firstname, lastname=lastname, updates=updates, question01=question01, question02=question02, question03=question03, question04=question04,  question05=question05, question06=question06, question07=question07, question08=question08, question09=question09, question10=question10, question11=question11, completed=completed)
        target = '../calls/newcall?surveyid=' + surveyid
        return context.REQUEST.RESPONSE.redirect(target)
      else:
        return 'redirect'
        target = '../duplicatesurvey'
        return context.REQUEST.RESPONSE.redirect(target)
# print true
# return printed
-------------- next part --------------
# see: http://zope.org/Documentation/Books/ZopeBook/2_6Edition/RelationalDatabases.stx

result = context.sqlGetSurveyByListenerID(listenerid=listenerid)

# number of rows
# return len(result.dictionaries())

# list of tuples
# return result.tuples()

# what we're looking for:
# return result.tuples()[0][0]

# see: http://www.python.org/doc/current/tut/node10.html#SECTION0010300000000000000000
try: 
  result = result.tuples()[0][0]
  print 'true'
except IndexError: 
  print 'false'

return printed
-------------- next part --------------
# see: http://zope.org/Documentation/Books/ZopeBook/2_6Edition/RelationalDatabases.stx

result = context.sqlGetSurvey(surveyid=surveyid)

# number of rows
# return len(result.dictionaries())

# list of tuples
# return result.tuples()

# what we're looking for:
# return result.tuples()[0][0]

# see: http://www.python.org/doc/current/tut/node10.html#SECTION0010300000000000000000
try: 
  result = result.tuples()[0][0]
  print 'true'
except IndexError: 
  print 'false'

return printed


More information about the Zope mailing list