Python
Python Script/ZSQL – Alternate data over 2 columns
by Greg on Mar.31, 2006, under Linux, Programming, Python
Here’s a quick post based on a Python Script I made in Zope to display the data from a ZSQL method in a 2 column table layout. Not that big of a deal, but I wanted to save this because it took a little bit of thought and some learning.
(My original code is all mess up on this, I’ll try to find and repost it.)
## Script (Python) "genlodinfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=itemid ##title= ## # Example code: ################################### """ Author: Greg Fischer 1st Byte Solutions - greg@1stbyte.com Date: 9/24/05 License: You are free to reengineer rework, recode, redistribute, resell or alter this code in any way you see fit, but you must give credit to my original work and you must provide this same license to those that may receive your distribution if you do. (just leave my name on it, and you must offer the same freedom in your work, that's all) Purpose: This script will gather from a zsql method, cat the records into address records (with exra info), then generate a table with alternating rows. In other words, it will fill the table from left to right, then down a row, 2 columns wide. """ ################################### def iseven(n): """Return true if n is even.""" return n%2==0 def isodd(n): """Return true if n is odd.""" return not iseven(n) # 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 rs = context.sql.ap_lodging(itemid) rownum = 1 x = [] for r in rs: ritemid = str(r[0]) rtqstart = str(r[4]) rtqend = str(r[5]) rstreet1 = r[12] rstreet2 = r[13] rcity = r[14] rstate = r[15] rzip = r[16] rnotes = r[18] lodstr = rtqstart + ' - ' + rtqend + ' ' lodstr = lodstr + rstreet1 + ' ' + rstreet2 + ' ' lodstr = lodstr + rcity + ', ' + rstate + ' ' + rzip + ' ' if rnotes <> '': lodstr = lodstr + rnotes + ' ' x.append(lodstr) table = '' tablee = '
And you return the results simply by calling the script in your dtml. something like: dtml-var “path.to.script(itemid=itemid)”
As always, I hope this help someone else out there, not just myself! Good luck!
Configure and compile Python with Zlib
by Greg on Jun.26, 2005, under Linux, Python, Zope
I just spent an hour trying to figure this out, AGAIN! To compile Zlib support into your Python interpreter, do this:
1. Install the Zlib-dev package for your distribution. (you probably have zlib already, but not the dev package)
On Ubuntu it’s called ‘zlib1g-dev’, on others it might just be: zlib-dev or zlib-devel. Do a search on your distro package lists to find it.
You should end up with a ‘zlib.h’ file in your system. In mine, Ubuntu, I have /usr/include/zlib.h
2. Get your python sources to compile and run the configure script like so:
./configure –with-zlib=/usr/include
See there that I included the ‘/usr/include’ directory to find zlib.h in? After the make && make install it worked great!
Keep in mind your mileage may vary, but this might help I hope. More importantly, now I can remember how I did this! :)