Re: [Zope-dev] Trouble populating a dictionary of dictionaries
From: Anton Hughes [EMAIL PROTECTED] 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. Your not thinking object oriented enough. Encapsulate, encapsulate, encapsulate. :-) Make objects of everything instead, and thank me later. :-) Then you index the objects in a ZCatalog so you can do searches. Best Regards Lennart Regebro, Torped http://www.easypublisher.com/ ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
[Zope-dev] Trouble populating a dictionary of dictionaries
Hi All, I'm trying to implement a computer booking system for staff members here. At the moment I have a table with date, timeslot (eg 8:00 - 9:00), resource (eg. PC 1) and person. I want to draw a table showing the bookings for the day looking something like this: |Time| PC 1 | PC 2 | PC 3 | ++--+--+--+ |8:00| AH | | | ++--+--+--+ |9:00| | BC | MD | ++--+--+--+ etc... I thought the best way to do it would be use the table to populate a dictionary of dictionaries like: booking['8:00']['PC 1'] = 'AH' Then when I'm rendering the table using ZPT I can use a nested loop to look through the timeslots and resources and fill table cells with the booking[slot][resource] value if it exists. 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. Thanks, Anton Code: = #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': lt;PythonScript instance at 01707050gt;, 'context': lt;PortalFolder instance at 01CFFEE0gt;, 'container': lt;PortalFolder instance at 01CFFEE0gt;, 'traverse_subpath': []}, ('9/9/02',), {}, None)) File Script (Python), line 23, in render_bookings TypeError: (see above) Anton Hughes Data Administrator Childhood Determinants of Adult Health Project Menzies Centre for Population Health Research GPO Box 252-23, Hobart Tasmania 7001 Email: [EMAIL PROTECTED] Web: http://www.menzies.utas.edu.au/cohort/CDAH.htm Phone: +61 (0) 3 6226 7761 =+=+=+===+++=+=+ Sattinger's Law: It works better if you plug it in. ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
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 ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
RE: [Zope-dev] Trouble populating a dictionary of dictionaries
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': lt;PythonScript instance at 01707050gt;, 'context': lt;PortalFolder instance at 01CFFEE0gt;, 'container': lt;PortalFolder instance at 01CFFEE0gt;, '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:[EMAIL PROTECTED]] Sent: Friday, 6 September 2002 3:12 PM To: Anton Hughes; [EMAIL PROTECTED] 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 ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Trouble populating a dictionary of dictionaries
Error Type: TypeError Error Value: unsupported operand type(s) for - resource = row['resource'] - 1 You should check that row['resource'] is a data type that supports subtraction. If for example row['resource'] is a string, this will raise the error. Try: resource = int(row['resource']) - 1 -- Andy McKay Agmweb Consulting http://www.agmweb.ca ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
RE: [Zope-dev] Trouble populating a dictionary of dictionaries
Thanks Andy, Error Type: TypeError Error Value: unsupported operand type(s) for - resource = row['resource'] - 1 ^^^ That was pretty stupid of me. A hangover from my earlier attempt at a 2D array :( Anton ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )