[Zope] Survey data to SQL - a trouble...

Alexander Chelnokov Alexander Chelnokov <alex@orto.unets.ru>
Thu, 2 Nov 2000 20:19:09 +0500


Hello All,

Problem: In a multiform survey values have to be saved into SQL DB
after last form is finished. So data have to be passed from a form to
next forms. Except this, each form must "know" which survey it belongs
to (SID is an unique survey ID) and a reference ID of the next form. If
it is last form, the reference is empty.

Solution: values of fields of previous forms and service data (SID and
a next form ID) are saved to <INPUT TYPE="HIDDEN">.
When the last form is completed, from REQUEST.form.items() we need to
extract only data fileds, without SIDs and IDs of forms. It is done by
filter.py:
==========================
def filterList (list): 
    fl = list
    res = []
    for el in fl:
      if el[0] not in ['sid','form','submit','nform']:
         res.append(el)
    return res
==========================

The Python method is called from this DTML-method:

==========================
<dtml-let fl="filterList(REQUEST.form.items())">
<dtml-call "storeResultsSQL(table_name=id, 
                            fields=fl,
                            sid=REQUEST['sid'])">
</dtml-let>
==========================
This seems to work.

Then this SQL-Method has to save data:
==========================
Arguments: table-name, fields, sid

UPDATE <dtml-var table_name> SET
<dtml-in fields>
<dtml-var sequence-key>=<dtml-sqlvar sequence-item type=nb>
<dtml-unless sequence-last>, </dtml-unless>
</dtml-in>
==========================

And after this piece of code an error appears:

Error Type: TypeError
Error Value: getattr, argument 2: expected string, int found

Traceback:


  File D:\TESTSITE\lib\python\DocumentTemplate\DT_Let.py, line 147, in render
    (Object: fl="filterList(REQUEST.form.items())")
  File D:\TESTSITE\lib\python\DocumentTemplate\DT_Util.py, line 337, in eval
    (Object: storeResultsSQL(table_name=id, fields=fl, sid=REQUEST['sid']))
    (Info: fl)
  File <string>, line 0, in ?
  File D:\TESTSITE\lib\python\Shared\DC\ZRDB\DA.py, line 443, in __call__
    (Object: storeResultsSQL)
  File D:\TESTSITE\lib\python\DocumentTemplate\DT_String.py, line 528, in __call__
    (Object: <string>)
  File D:\TESTSITE\lib\python\DocumentTemplate\DT_In.py, line 691, in renderwob
    (Object: fields)
  File D:\TESTSITE\lib\python\DocumentTemplate\DT_InSV.py, line 395, in __getitem__
  File D:\TESTSITE\lib\python\DocumentTemplate\DT_InSV.py, line 194, in last
  File D:\TESTSITE\lib\python\DocumentTemplate\DT_InSV.py, line 182, in value
[...]

Any suggestions?
THX in advance.

-- 
Best regards,
    Alexander N. Chelnokov
Ural Scientific Institute of Traumatology and Orthopaedics
7, Bankovsky str. Ekaterinburg 620014 Russia
ICQ: 25640913