Hi,

I've got a problem with displaying output from one of my python methods,
which has 'self' as one of its input parameters. I have a DTML method,
which sets up a table using one Python method to create the table
headers (the first row) and another Python method to create the table
data (one row per result set). I think my problem can be solved (maybe)
by asking how to call a python method from DTML when 'self' is one of
the arguments expected...

Here's a rough idea of my DTML method:

<table>
 <tr>
  <dtml-let classcode="52.225"> * just for testing the 2nd python method
directly
  <dtml-var index_table_headers> * python method returning first row
 </tr>

<dtml-in get_matrics_from> *return a list of matric numbers (will be
used as an argument for next python method).
 <tr>
  *** what here to get result(s) from 'final' method using matric and
classcode as arguments? ***
 </tr>
</dtml-in>

</table>

I've *called* other methods, where self has been in the parameter list
without specifying it but in these cases it was the only parameter and
there was nothing being returned. Now, most of my errors are 'not enough
arguments; expected 3'.

I'm hoping that some sleep, some coffee, a reply or a combination of the
three will give me the answer!

Thanks a lot,

Lee

Here's the Python method (pretty disgusting looking but I'll clean it
later ;-) :

Python method 'final' with parameters 'self, matric, classcode'
---------------------------------------------------------------
table="class" + string.replace(`classcode`, ".", "")
table=string.replace(table, "'", "")

db_conn = self.Gadfly_database_connection()
SQL = ("select practicals, assignments, tutorials, bonus from classes
where classcode = " + classcode)
result=db_conn.query(SQL)
resultString = `(result[1])`
length = len(resultString)

# To take away the last 2 brackets
i=length-1
x= ""
while (i>1):
         x=x+resultString[length-1-i]
         i=i-1

# To take away the first 2 brackets
newLength=len(x)
j=newLength-1
y= ""
while (j>1):
    y=y+x[j]
    j=j-1

# To invert the string
i=len(y)-1
z=""
while (i>=0):
      z=z+y[i]
      i=i-1

components = string.split(z)

p = string.atoi(string.replace(components[0], ",", ""))
a = string.atoi(string.replace(components[1], ",", ""))
t = string.atoi(string.replace(components[2], ",", ""))
b = string.atoi(components[3])

px=p
ax=a
tx=t
bx=b

db_conn = self.Gadfly_database_connection()

SQL= "select "

i=1
while (i<=p):
       SQL = SQL + "p" + `i` + ", "
       i=i+1

i=1
while (i<=a):
       SQL = SQL + "a" + `i` + ", "
       i=i+1

i=1
while (i<=t):
       SQL = SQL + "t" + `i` + ", "
       i=i+1

i=1
while (i<=b):
       SQL = SQL + "b" + `i` + ", "
       i=i+1

SQL= SQL + " uname, fname, lname from " + table + " where matric = " +
matric

result=db_conn.query(SQL)

resultString = `(result[1])`
length = len(resultString)

# To take away the last 2 brackets
i=length-1
x= ""
while (i>1):
         x=x+resultString[length-1-i]
         i=i-1

# To take away the first 2 brackets
newLength=len(x)
j=newLength-1
y= ""
while (j>1):
    y=y+x[j]
    j=j-1

# To invert the string
i=len(y)-1
z=""
while (i>=0):
      z=z+y[i]
      i=i-1

components = string.split(z)
length=len(components)
dic = {}
control=0

p = px
a = ax
t = tx
b = bx

while (p!=0):
        tempDic = {('p'+`control+1`):
string.atoi(string.replace(components[control], ",", ""))}
        dic.update(tempDic)
        p=p-1
        control=control+1

while (a!=0):
        tempDic = {('a'+`control+1-px`):
string.atoi(string.replace(components[control], ",", ""))}
        dic.update(tempDic)
        a=a-1
        control=control+1

while (t!=0):
        tempString = string.replace(components[control], ",", "")
        tempString1 = string.replace(tempString, '"', '')
        tempString2 = string.replace(tempString1, "'", "")
        tempDic = {('t'+`control+1-px-ax`): `(tempString2)`}
        # tempDic = {('t'+`control+1-px-ax`): `(components[control])`}
        dic.update(tempDic)
        t=t-1
        control=control+1

while (b!=0):
        tempDic = {('b'+`control+1-px-ax-tx`):
string.atoi(string.replace(components[control], ",", ""))}
        dic.update(tempDic)
        b=b-1
        control=control+1

lname = string.replace(components[length-1], ",", "")
fname = string.replace(components[length-2], ",", "")
uname = string.replace(components[length-3], ",", "")

lname = string.replace(lname, "'", "")
fname = string.replace(fname, "'", "")
uname = string.replace(uname, "'", "")

HTML = '<td><input type="checkbox" name="' + matric + '" value="true">'
+ matric + '</td>\n'
HTML = HTML + '<td>' + fname + '</td>\n'
HTML = HTML + '<td>' + lname + '</td>\n'
HTML = HTML + '<td><a href="mailto:+ ' + uname + '@cs.strath.ac.uk">' +
uname + '@cs.strath.ac.uk</a></td>\n'

p = px
a = ax
t = tx
b = bx

while (p!=0):
       key="p"+`px-p+1`
       value = dic[key]
       HTML=HTML + '<td>' + `value` + '</td>\n'
       p=p-1

while (a!=0):
       key="a"+`ax-a+1`
       value = dic[key]
       HTML=HTML + '<td>' + `value` + '</td>\n'
       a=a-1

while (t!=0):
       key="t"+`tx-t+1`
       value = string.replace(dic[key], "'", "")
       HTML=HTML + '<td>' + `value` + '</td>\n'
       t=t-1

while (b!=0):
       key="b"+`bx-b+1`
       value = dic[key]
       HTML=HTML + '<td>' + `value` + '</td>\n'
       b=b-1

return HTML






_______________________________________________
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )

Reply via email to