[Zope-dev] How to aquire from Context?

2001-06-17 Thread Matt Hamilton

Dear All,
  I have been trying to work out how to acquire a DTML method first by
context rather than by containment.  According to the ZDG (Great read,
thanks guys!):

-- snip --

Containment Before Context

If in the example above suppose both a and b have an color attribute:

  a=C(a)
  a.color=green
  a.b=C(b)
  a.b.color=red
  a.x=C(x)

  print a.b.x.color # prints green

Why does a.b.x.color acquire color from a and not from b? The answer is
that acquisition acquires from the containment before context.

-- snip --

Now that makes perfect sense to me and I can see why it happens as
such.  However what if I want print a.b.x.color to return red?  The
scenario is this:  I have a directory structure:

/
standard_html_header
side_bar
folderA
  foo
  bar
  side_bar
  index_html

index_html calls standard_html_header which in turn calls side_bar.  If I
access this via /folderA/index_html I still get the side_bar in the root
not the one in folderA.  This makes sense in respect to the above ZDG
stuff.  But how can I get it to work the way I want (/folderA/index_html
uses folderA/side_bar)?  I've searched zope.org and found plenty of
explainaintions why this is so, but no good examples or workarounds as how
to get around it :(

Any ideas?

-Matt

-- 
Matt Hamilton [EMAIL PROTECTED]
Netsight Internet Solutions, Ltd.  Business Vision on the Internet
http://www.netsight.co.uk   +44 (0)117 9090901
Web Hosting | Web Design  | Domain Names  |  Co-location  | DB Integration



___
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] How to aquire from Context?

2001-06-17 Thread Dieter Maurer

Matt Hamilton writes:
  
  According to the ZDG (Great read,
  thanks guys!):
  
  -- snip --
  
  (Acquisition works by: ) Containment Before Context
  
  
  Now that makes perfect sense to me and I can see why it happens as
  such.  However what if I want (Context Before Containment).
I fear, there is no simple solution.

  You can follow the context chain with 'aq_parent'.
  Thus, you can implement your own lookup. However,
  you will need an external method 'hasItself' to
  check, when you found the binding you are looking for.

def hasItself(object,attr):
  object= getattr(object,'aq_base',object)
  return hasattr(object,attr)


Dieter

___
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] How to aquire from Context?

2001-06-17 Thread Chris Withers

Matt,

Evan Simpson came up with some external methdos that do exactly what you want
about 6 months to a year ago.
If you search the zope.nipltd.com archives for [EMAIL PROTECTED] and
[EMAIL PROTECTED] you may well be able to find what you're after :-)

cheers,

Chris

Matt Hamilton wrote:
 
 Dear All,
   I have been trying to work out how to acquire a DTML method first by
 context rather than by containment.  According to the ZDG (Great read,
 thanks guys!):
 
 -- snip --
 
 Containment Before Context
 
 If in the example above suppose both a and b have an color attribute:
 
   a=C(a)
   a.color=green
   a.b=C(b)
   a.b.color=red
   a.x=C(x)
 
   print a.b.x.color # prints green
 
 Why does a.b.x.color acquire color from a and not from b? The answer is
 that acquisition acquires from the containment before context.
 
 -- snip --
 
 Now that makes perfect sense to me and I can see why it happens as
 such.  However what if I want print a.b.x.color to return red?  The
 scenario is this:  I have a directory structure:
 
 /
 standard_html_header
 side_bar
 folderA
   foo
   bar
   side_bar
   index_html
 
 index_html calls standard_html_header which in turn calls side_bar.  If I
 access this via /folderA/index_html I still get the side_bar in the root
 not the one in folderA.  This makes sense in respect to the above ZDG
 stuff.  But how can I get it to work the way I want (/folderA/index_html
 uses folderA/side_bar)?  I've searched zope.org and found plenty of
 explainaintions why this is so, but no good examples or workarounds as how
 to get around it :(
 
 Any ideas?
 
 -Matt
 
 --
 Matt Hamilton [EMAIL PROTECTED]
 Netsight Internet Solutions, Ltd.  Business Vision on the Internet
 http://www.netsight.co.uk   +44 (0)117 9090901
 Web Hosting | Web Design  | Domain Names  |  Co-location  | DB Integration
 
 ___
 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 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 )