Zope

From YobiWiki
Jump to navigation Jump to search

Installation

apt-get install zope python-zmysqldb 

On cherche une version de ZMySQLDA qui soit packagée

Le paquet n'existe pour l'instant ni en testing ni en unstable et la version stable dépend de python2.2, nous installons donc manuellement la version experimental

wget http://ftp.de.debian.org/debian/pool/main/z/zope-mysqlda/zope-mysqlda_2.0.9~b3-3_all.deb  
dpkg -i zope-mysqlda_2.0.9~b3-3_all.deb 

Chercher le nouveau produit

dzhandle list-products|grep -i sql 
=> product ZMySQLDA ZMySQLDA zope-mysqlda 2.0.9~b3-3 /usr/share/zope/Products/ZMySQLDA None 

et l'ajoutez à l'instance <myinst>:

dzhandle add-product <myinst> ZMySQLDA      
/etc/init.d/zope2.9 restart

Commentaires :
creer une nouvelle instance

makeinstance <nom_de_la_nouvelle_instance_zope> --python=/lien/vers/python/

executable sont dans /usr/bin/mysql ou python ou python2.4 ou ..

Les produits zope sont a installer dans /var/lib/zope2.9/instance/<myinst>/Products ou /var/lib/zop../lib/python/Products/

e.g. : FSCounter

cd /var/lib/zope2.9/instance/zope/Products
wget http://www.zope.org/Members/bowerymarc/FScounter/default/FSCounter12.tgz
tar xvzf FSCounter12.tgz
chown -R zope:zope ./FSCounter
/etc/init.d/zope2.9 restart

e.g. : Photo

apt-get install zope-photo zope-extfile zope-testcase python-imaging python-imaging-sane python-imaging-doc python-imaging-doc-pdf python-imaging-tk python-imaging imagemagick
cd /var/lib/zope2.9/instance/<instance_name>/Products/
wget http://www.zope.org/Members/rbickers/Photo/Photo/Photo-1.2.4.tgz
tar xvzf Photo-1.2.4.tgz
chown -R zope:zope ./Photo-1.2.4
dzhandle add-product zope Photo

e.g. : PHParser

cd /var/lib/zope2.9/instance/zope/Products
wget http://www.zope.org/Members/hewei/PHParser/1.1.5/PHParser-1.1.5.tar.gz
tar xvzf PHParser-1.1.5.tar.gz
chown -R zope:zope ./PHParser
/etc/init.d/zope2.9 restart

To get the country from the visitor on a zope page: First import the database on your MySQL db as <db_name>.csv as descibed here Add a Python Script in zope (e.g. geoip):

from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE =  request.RESPONSE
ip = context.REQUEST.REMOTE_ADDR
line = string.split(ip,'.')
ip0 = line[0]
ip1 = line[1]
ip2 = line[2]
ip3 = line[3]
ipnum = int(ip0) * 16777216 + int(ip1) * 65536 + int(ip2) * 256 + int(ip3) * 1
print ipnum
return printed

Add a Z Mysql Method (e.g. select_GeoIP) with as Arguments ipnum

SELECT cn 
from <db_name>.csv 
where start < <dtml-sqlvar ipnum type="string"> and end > <dtml-sqlvar ipnum type="string">

In a DTML Method, test :

<dtml-in expr="select_GeoIPs(ipnum=geoip())">Hoo, you are from <dtml-var cn>, Welcome !</dtml-in>

Same for latitude and longitude of the country Country Geolocalization