[Zope] Virtual HostMonster article
Cees de Groot
cg@cdegroot.com
Fri, 04 May 2001 00:52:46 +0200
jasonic@nomadicsltd.com said:
> That sound just like what I am looking for.. and for similar reasons.
> Is your product posted anywhere?
Nope. When things get quieter here, I'm planning to separate out a bunch of
goodies I wrote the last half year and post them, but at the moment I'm too
busy for that.
It's not that it is much code:
#
# $Id: VirtualHostFolder.py,v 1.2 2001/05/03 13:24:04 cg Exp $
#
from Globals import HTMLFile
from OFS import Folder
from Products.ZCatalog import CatalogAwareness
from Products.SiteAccess import SiteRoot
import string
class VirtualHostFolder(Folder.Folder, CatalogAwareness.CatalogAware):
"""A virtual host folder"""
meta_type = 'TIO Virtual Host Folder'
def __init__(self, sitename):
self.id = sitename.lower().replace('.', '_')
self.title = sitename
self.default_catalog = 'sites'
def manage_beforeDelete(self, item, container):
print "Deleting stuffsky..."
Folder.Folder.manage_beforeDelete(self, item, container)
self.unindex_object()
def manage_add_virtualhostfolder(self, sitename, REQUEST=None, submit=None):
'Add a Virtual Host Folder'
o = VirtualHostFolder(sitename)
self._setObject(o.id, o)
SiteRoot.manage_addSiteRoot(o)
getattr(self, o.id).index_object()
if REQUEST is not None:
self.manage_main(self, REQUEST, update_menu=1)
manage_add_virtualhostfolder_form = \
HTMLFile('manage_add_virtualhostfolder_form', globals())
--
and using it from an AccessRule:
def vhost(self, REQUEST):
hostname = string.split(REQUEST['HTTP_HOST'], ':')[0]
r = self.sites({ 'id': string.replace(hostname, '.', '_')})
if len(r) == 1:
path = string.split(r[0].getPath(), '/')[1:]
path.reverse()
REQUEST['TraversalRequestNameStack'].extend(path)
REQUEST.set('SiteRootPATH', '/')
else:
# I look into a SQL database here to do things like business cards
# and redirects
as you can see, still SiteRoot based. I don't even have the time to subject
VHM to a decent evaluation yet :=)
--
Cees de Groot http://www.cdegroot.com <cg@cdegroot.com>
GnuPG 1024D/E0989E8B 0016 F679 F38D 5946 4ECD 1986 F303 937F E098 9E8B