[Zope-dev] Trouble populating a dictionary of dictionaries

Anton Hughes Anton.Hughes@utas.edu.au
Fri, 6 Sep 2002 15:18:12 +1000


Hmmm..... I posted code on the end of that message. I don't know what
happened to it. Anyway, I'll post the code here:

#parameters: booking_date
# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE =  request.RESPONSE

bookings = {}   # declare the bookings dictionary
resource_hash = {} #declare the resource dictionary

#populate bookings dictionary with timeslot keys
for row in context.resources():
      resource = row['name']
      resource_hash[resource] = ''

#populate bookings dictionary with timeslot keys
for row in context.timeslots():
      slot = row['slot_name']
      bookings[slot] = resource_hash

#fill the bookings dictionary of arrays with actual bookings
for row in context.getBookings(on_date=booking_date):
     slot = row['timeslot']
     resource = row['resource'] - 1
     person = ['person']
     bookings[slot][resource] = person

return bookings

Error:
======
Error Type: TypeError
Error Value: unsupported operand type(s) for -

Traceback (innermost last):
  File D:\ongaku\lib\python\ZPublisher\Publish.py, line 150, in
publish_module
  File D:\ongaku\lib\python\ZPublisher\Publish.py, line 114, in publish
  File D:\ongaku\lib\python\Zope\__init__.py, line 159, in
zpublisher_exception_hook
    (Object: bookings)
  File D:\ongaku\lib\python\ZPublisher\Publish.py, line 98, in publish
  File D:\ongaku\lib\python\ZPublisher\mapply.py, line 88, in mapply
    (Object: render_bookings)
  File D:\ongaku\lib\python\ZPublisher\Publish.py, line 39, in call_object
    (Object: render_bookings)
  File D:\ongaku\lib\python\Shared\DC\Scripts\Bindings.py, line 252, in
__call__
    (Object: render_bookings)
  File D:\ongaku\lib\python\Shared\DC\Scripts\Bindings.py, line 283, in
_bindAndExec
    (Object: render_bookings)
  File D:\ongaku\lib\python\Products\PythonScripts\PythonScript.py, line
302, in _exec
    (Object: render_bookings)
    (Info: ({'script': <PythonScript instance at 01707050>, 'context':
<PortalFolder instance at 01CFFEE0>, 'container': <PortalFolder
instance at 01CFFEE0>, 'traverse_subpath': []}, ('9/9/02',), {}, None))
  File Script (Python), line 23, in render_bookings
TypeError: (see above)


Thanks again,

Anton


-----Original Message-----
From: Andy McKay [mailto:andy@agmweb.ca]
Sent: Friday, 6 September 2002 3:12 PM
To: Anton Hughes; zope-dev@zope.org
Subject: Re: [Zope-dev] Trouble populating a dictionary of dictionaries


> After playing around for too long on it, I can't seem to get it to work. I
> even tried pre-filling the d-o-d with empty strings. I just don't
understand
> what I am doing wrong.

Its really rather hard to say if you dont show us some code ;)
--
  Andy McKay
  Agmweb Consulting
  http://www.agmweb.ca