Virtual Host Monster does not work with the absolute_url()
I am finding that the Virtual Host Monster does not work with the absolute_url() method of several objects. It seems to work fine for all other things, but when I try to call the URL of an object like this..... <dtml-in "thismodel.getReports()"> <A HREF="<dtml-var "_['sequence-item'].absolute_url()">?assessmentid=<dtml-var thisassessment>" TARGET="_newer"><dtml-var "getTitleOrId()"></A> </dtml-in> It always returns the path back to the real root of Zope. It completely ignores that there is a Virtual Host Monster. I am certain that my Apache rewrites are ok, Ive been using it for many months with no problem. It is just the absolute_url() method that does not work. Any hints? Tom
Tom Cameron writes:
... "_['sequence-item'].absolute_url()" Not sure, that this is related to your problem (probably not), but "_[...]" is usually calling for problems when you expect the result to be an object.
Use "_.getitem('sequence-item')" instead. Dieter
Thanks Dieter, But it makes no difference. I am guessing that perhaps the object that I am calling is not subclassed off something that it should be for the VHM to work. Does anybody know of a property or method that I should be looking for that absolute_url() might need to determine the correct Base? Thanks Tom => -----Original Message----- => From: Dieter Maurer [mailto:dieter@handshake.de] => Sent: Saturday, 10 August 2002 6:55 AM => To: tom@mooball.com => Cc: zope@zope.org => Subject: Re: [Zope] Virtual Host Monster does not work with the => absolute_url() => => => Tom Cameron writes: => > ... => > "_['sequence-item'].absolute_url()" => Not sure, that this is related to your problem (probably not), => but "_[...]" is usually calling for problems when you expect the => result to => be an object. => => Use "_.getitem('sequence-item')" instead. => => => Dieter =>
Tom Cameron wrote:
I am guessing that perhaps the object that I am calling is not subclassed off something that it should be for the VHM to work.
Does anybody know of a property or method that I should be looking for that absolute_url() might need to determine the correct Base?
What kind of object is it, and does it define its own absolute_url()? Cheers, Evan @ 4-am
Evan, it is a python product that I have built, it is subclassed on another abstract class I built and the simpleItem class. None of my classes redefine the absolute_url() method - or for that matter any related methods. Thanks Tom => -----Original Message----- => From: Evan Simpson [mailto:evan@4-am.com] => Sent: Saturday, 10 August 2002 9:27 AM => To: tom@mooball.com => Cc: zope@zope.org => Subject: Re: [Zope] Virtual Host Monster does not work with the => absolute_url() => => => Tom Cameron wrote: => > I am guessing that perhaps the object that I am calling is not => subclassed => > off something that it should be for the VHM to work. => > => > Does anybody know of a property or method that I should be => looking for that => > absolute_url() might need to determine the correct Base? => => What kind of object is it, and does it define its own absolute_url()? => => Cheers, => => Evan @ 4-am =>
Tom Cameron wrote:
Evan, it is a python product that I have built, it is subclassed on another abstract class I built and the simpleItem class.
None of my classes redefine the absolute_url() method - or for that matter any related methods.
Do any of your products do anything which might affect the acquisiton cotext of their children? (using any of the aq_ methods, using dictionries instead of attributes, etc...) cheers, Chris
Chris, We start with a base class called GenericObject... class GenericObject(Implicit, Persistent, RoleManager, Item, PropertyManager, MessageListener): It contains, amongst others, the following method (the only one in the entire product that uses a aq_ method) #---------------------------------------------------------------# def getParent(self): "Return the parent container that this object is within" return self.aq_parent #---------------------------------------------------------------#
From there we create several other base classes and sub off them a few times.
The product presently has about 40 classes with about 8 base classes from which all others are built. To narrow it down for you a bit. There is a container called a Model and it contains Reports. and it is the reports that I am getting the URL of. To get the list of reports I use the following method of the model... #---------------------------------------------------------------# def getReports(self, type=None): """ Returns a sequence of the immediate child Report(s) in this container, sorted by title. If type is specified then the results are filtered. """ #get the immediate children of the container children = self.objectValues() #filter the Report(s) only reports = [x for x in children if x.isInstanceOf("Report")] if type != None: reports = [x for x in reports if x.getReportType() == type] #sort the report by Report.getTitle() reports.sort(lambda x, y : x.getTitle() < y.getTitle()) return reports #---------------------------------------------------------------# This returns a list and then i do the .absolute_url() on each of these. Could it be the way I get the reports? Tom => -----Original Message----- => From: Chris Withers [mailto:chrisw@nipltd.com] => Sent: Saturday, 10 August 2002 9:03 PM => To: tom@mooball.com => Cc: Evan Simpson; zope@zope.org => Subject: Re: [Zope] Virtual Host Monster does not work with the => absolute_url() => => => Tom Cameron wrote: => > Evan, => > it is a python product that I have built, it is subclassed on another => > abstract class I built and the simpleItem class. => > => > None of my classes redefine the absolute_url() method - or for => that matter => > any related methods. => => Do any of your products do anything which might affect the acquisiton => cotext of their children? (using any of the aq_ methods, using => dictionries instead of attributes, etc...) => => cheers, => Chris =>
a couple things::
def getParent(self): "Return the parent container that this object is within" return self.aq_parent
if you want to ensure to always get the "physical" parent (the parent the object is actually situated in) then do it like this:: from Acquisition import aq_inner, aq_parent ... and in your method you say return aq_parent(aq_inner(self))
def getReports(self, type=None): """ Returns a sequence of the immediate child Report(s) in this container, sorted by title. If type is specified then the results are filtered. """
#get the immediate children of the container children = self.objectValues()
#filter the Report(s) only reports = [x for x in children if x.isInstanceOf("Report")]
make your life easier by having objectValues do the filtering for you:: children = self.objectValues(['Report']) jens
Jens, => => make your life easier by having objectValues do the filtering for you:: => => children = self.objectValues(['Report']) => Thanks but this will not work for me. I have many different types of reports, all of which have different metatypes. I need to be able to determine which objects were built from what baseclasses. We also found the zope isInstanceOf() not to work all the time so we built our own, hence we use reports = [x for x in children if x.isInstanceOf("Report")] Thanks Tom
Tom Cameron wrote:
Chris,
We start with a base class called GenericObject... class GenericObject(Implicit, Persistent, RoleManager, Item, PropertyManager, MessageListener):
If 'Item' in the above is SimpleItem.Item, then Implicit, Persistent and RoleManager need not be included in the above list. I note you're not inheritting from OFS.Traversable.Travesable, perhaps you should? cheers, Chris
Chris, It is the same Item, but I removed Implicit, and Persistent, and found that I then lost Persistence and acquisition in my objects - lots of errors everywhere, so I had to put them back in. Also the addition of Traversable made no difference. Thanks anyway. Tom => -----Original Message----- => From: Chris Withers [mailto:chrisw@nipltd.com] => Sent: Sunday, 11 August 2002 2:09 AM => To: tom@mooball.com => Cc: Evan Simpson; zope@zope.org => Subject: Re: [Zope] Virtual Host Monster does not work with the => absolute_url() => => => Tom Cameron wrote: => > Chris, => > => > We start with a base class called GenericObject... => > class GenericObject(Implicit, Persistent, RoleManager, Item, => > PropertyManager, MessageListener): => => If 'Item' in the above is SimpleItem.Item, then Implicit, Persistent and => RoleManager need not be included in the above list. => => I note you're not inheritting from OFS.Traversable.Travesable, => perhaps you should? => => cheers, => => Chris =>
Tom Cameron wrote:
Also the addition of Traversable made no difference.
I still think this is the key since I remember having a problem like this with Squishdot. Have a look at the methods in Traversable.py and see if any of your special functionality is causing problems with their implementation. You may need to override those methods and make them do what they should, not what they want to, as I did with Squishdot. cheers, Chris
Tom Cameron wrote:
We start with a base class called GenericObject... class GenericObject(Implicit, Persistent, RoleManager, Item, PropertyManager, MessageListener):
I agree with Chris that Traversable should be in there, otherwise you're going to pick it up through acquisition and get funky answers. You said it made no difference, though. Argh. Could you please give a concrete example of the URL that you're expecting and the one you're getting? Cheers, Evan @ 4-am
I have a product (called PathMapper) that I wrote for a couple of clients. It is subclassed off the dtml method and is used to redirect requests to different paths. It makes use of the Site Access Rule and has been working find for over a year now on 2.4.x and 2.5.x Zope sites. The other day I upgraded to 2.6.1 and the product did not work. I then did some testing and found out that in 2.6.1 you get locked out of the entire folder if you set the Site Access Rule on a dtml method. If you set it on a python script it works fine, but not on a dtml method. Is this intended behaviour or is this a bug? Tom
Tom Cameron wrote:
Is this intended behaviour or is this a bug?
I think you need to provide more info. Primarily, the contents of your access rule, but also the exception Type, Value and traceback that you recieved. cheers, Chris
Ack, disregard the Traversable comment -- you're using Item, which has that as a base class. Sorry, Evan @ 4-am
Tom Cameron writes:
Does anybody know of a property or method that I should be looking for that absolute_url() might need to determine the correct Base? Following the code of the standard "absolute_url" (to be found in "OFS/Traversable"):
def absolute_url(self, relative=0): try: req = self.REQUEST except AttributeError: req = {} rpp = req.get('VirtualRootPhysicalPath', ('',)) spp = self.getPhysicalPath() i = 0 for name in rpp[:len(spp)]: if spp[i] == name: i = i + 1 else: break path = map(quote, spp[i:]) if relative: # This is useful for physical path relative to a VirtualRoot return join(path, '/') return join([req['SERVER_URL']] + req._script + path, '/') As you see, there are several possible reasons why you may get the physical path: * your object is unable to acquire "REQUEST" (because it is not (yet) acquisition wrapped) * the 'VirtualRootPhysicalPath' in "REQUEST" is wrong (not very likely) * the SERVER_URL or "_script" in "REQUEST" are wrong (not very likely) * you happen to access a non-standard "absolute_url" (use, e.g. "DocFinder", to check that). Dieter
participants (5)
-
Chris Withers -
Dieter Maurer -
Evan Simpson -
Jens Vagelpohl -
Tom Cameron