[ZPT] namespace questions

daniel.a.fulton@delphiauto.com daniel.a.fulton@delphiauto.com
Fri, 18 May 2001 20:57:53 +0800


have a question on namespace, well actually 2.

1.  How do I call an attribute from python script and make it globally available
within the page template?  The first line of the below template is giving me
problems - ie.

Error Type: TALESError
Error Value: exceptions.AttributeError on last_month in ""

the repeats are ZSQL Methods.

     <table tal:define="global last_month python:here.month_logic(month,
year).last_month">
   <tr><span tal:repeat="records here/ap_month1_totals">
       <td tal:content="recordsdivision">division</td>
       <td tal:content="records/sum_div1">sum_div1</td>
       <td tal:content="records/sum_co1">sum_co1</td>
       <td tal:content="records/sum_total1">sum_total1</td>
       </span>
       <span tal:repeat="next_month_records here/ap_month2_totals">
       <td tal:content="next_month_records/sum_div2">sum_div2</td>
       <td tal:content="next_month_records/sum_co2">sum_co2</td>
       <td tal:content="next_month_records/sum_total2">sum_total2</td>
       </span>
        <span tal:repeat="next_last_month_records here/ap_month3_totals">
       <td tal:content="next_last_month_records/sum_div3">sum_div3</td>
       <td tal:content="next_last_month_records/sum_co2">sum_co3</td>
       <td tal:content="next_last_month_records/sum_total3">sum_total3</td>
       </span>
         </tr>
    </table>

where:

## Script (Python) "month_logic"
##bind container=container
##bind context=context
##bind namespace=_
##bind script=script
##bind subpath=traverse_subpath
##parameters=month1,year1
##title=
##
from DateTime import DateTime
from string import atoi

y = atoi(year)
m = atoi(month)
d = atoi(day)
dt = DateTime(y,m,d,0,0,0.0)

if m == 1:
   last_month = 12
   nl_month = 11
   last_year = y - 1
   nl_y = y - 1

elif m == 2:
   last_month = m - 1
   nl_month = 12
   last_year = y
   nl_year = y - 1

else:
  last_month = m - 1
  nl_month = m - 2
  last_year = y
  nl_year = y

#return last_month, nl_month, last_year, nl_year

2.  This second question is ZSQL related and not really ZPT, but does pertain to
 the above page.
Does ZSQL methods only look in the REQUEST namespace or can I pass it a
calculated variable like
<dtml-sqlvar last_month type=int> which is coming from the above PythonScript?

Much thanks for taking the time read all of this.
Daniel