[Zope] Re: Preserving Context

2006-12-13 Thread Javier Subervi
From: Jonathan [EMAIL PROTECTED]

 targetFolder = string.join(traverse_subpath, '/') #you will have to play with 
 this to get the right target folder for your app
 aFolder = context.restrictedTraverse(targetFolder)
 searchRes = aFolder.Catalog(some search string here)
 do something with search results here

First of all, thank you very much for your help.
I'm confused. I had a programmer working for me that wrote the following code:

return 0
catalog = ''
try:
catalog = getattr(context, context.superValues('ZCatalog')[0].id)
except AttributeError:
pass
if catalog:
return 1

Now, that works just fine if I leave the page template that calls it in the 
folder of a specific Web site. But when I put that template in a root folder 
that all the Web sites of the portal can call, it only gives me a printout of 
the tree of what's in the root folder. What I'm trying to accomplish is that it 
gives me the tree of the specific Web site folder from which it is called.

My problem is that I frankly don't understand what my programmer wrote...how it 
works. Research taught me that superValues returns the meta_data of ZCatalog, 
we're popping the first element of the tuple, getting it's ID, all in context 
of the call, and calling that a catalog. But why do we return 1 if we get a 
catalog? How does that print the catalog? Then, how do I incorporate your 
information to achieve my goal?
Thanks for any help you care to offer,
Javier


 

Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Re: Preserving Context

2006-12-13 Thread Maciej Wisniowski

 Yes there is a 'return 0' at the beginning.
 This code always executes and works just fine,
 as I've mentioned before, as long as the template is in the root
 folder of the given Web site. I'm trying to put this template in a
 root folder that services all the Web sites of the portal, and
 that's where I'm having trouble.
So this is not because of this code. Your script
ALWAYS returns '0' and does nothing more.
Just try to remove everything after 'return 0' and see
if it changes anything or remove 'return 0' and see
what happens then.

-- 
Maciej Wisniowski
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Re: Preserving Context

2006-12-13 Thread Javier Subervi
- Original Message 
From: Maciej Wisniowski [EMAIL PROTECTED]


So this is not because of this code. Your script
ALWAYS returns '0' and does nothing more.
Just try to remove everything after 'return 0' and see
if it changes anything or remove 'return 0' and see
what happens then.

Crap. You're right. Back to square one...
Javier


 

Need a quick answer? Get one in minutes from people who know.
Ask your question on www.Answers.yahoo.com___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: Preserving Context

2006-12-12 Thread Javier Subervi
From: Suresh V [EMAIL PROTECTED]

1. Are you using container rather than context in your script? 
2. You can pass your context as a mycontext parameter to your script.

I have this line of code in my page template for handling the 404 errors:

div align=center tal:condition=here/hasSearchEngine

I changed it thus:

div align=center tal:condition=here/hasSearchEngine(mycontext)

I tested the following script with mycontext as a passed parameter:

return 0

catalog = ''
try:
catalog = getattr(mycontext, mycontext.superValues('ZCatalog')[0].id)
except:
pass

if catalog:
return 1

This threw an error concerning mycontext.
TIA,
Javier




 

Have a burning question?  
Go to www.Answers.yahoo.com and get answers from real people who know.___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: Preserving Context

2006-12-12 Thread Suresh V

Javier Subervi wrote:



div align=center tal:condition=here/hasSearchEngine(mycontext)


And where is mycontext defined? You will need a tal:define=mycontext 
here or something.




I tested the following script with mycontext as a passed parameter:

return 0

catalog = ''
try:
catalog = getattr(mycontext, mycontext.superValues('ZCatalog')[0].id)
except:
pass
   


Bare except? You bad boy!

Use except AttributeError:

In fact remove the try/except and study the trace output.

Suresh

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Re: Preserving Context

2006-12-12 Thread Jonathan
In your root folder you could have a script that accesses the ZCatalog which 
can be called from any subfolder and can tell where it was called from... try 
the following:  create a python script (tst) in your root folder that contains 
the following code:

return str(traverse_subpath)


then invoke this script file as followings:

http:/your.web.site/tst
http:/your.web.site/tst/folderA
http:/your.web.site/tst/folderB/folderC

(substitute your own subfolders as required)

This may get you what you are looking for.

Alternatively, if you need more control over the parameters that are getting 
sent to the script file in the root folder, then you could create a script file 
in each subfolder which calls the 'root script' with the necessary 'localized' 
parameters.


Jonathan


  - Original Message - 
  From: Javier Subervi 
  To: zope@zope.org 
  Sent: Tuesday, December 12, 2006 11:55 AM
  Subject: [Zope] Re: Preserving Context


  From: Jonathan [EMAIL PROTECTED]
  
  From: Suresh V [EMAIL PROTECTED]

  In your script you could access the catalog as follows:
   
  afolder = context.restrictedTraverse('folderA/folderB/'+someLocalFolder) 
   # pass 'someLocalFolder' as a parameter
  catalog = afolder.Catalog# assuming you have named your ZCatalog 
'Catalog'

  The problem with this, is that this script is used at the base of a portal 
with several different Web sites, therefore, the root folder of each is 
different.

  And where is mycontext defined? You will need a tal:define=mycontext here 
or something.

  I added the following:

  div align=center 
 tal:define=mycontext here
 tal:condition=here/hasSearchEngine(mycontext)

  ...but that didn't seem to help any:

  Error Type: KeyError
  Error Value: 'hasSearchEngine(mycontext)'

  Concerning your comment about the except, this script was written by an 
employee of mine. I'm now picking up where he left off. I cleaned it up ;)
  TIA,
  Javier



--
  Want to start your own business? Learn how on Yahoo! Small Business.


--


  ___
  Zope maillist  -  Zope@zope.org
  http://mail.zope.org/mailman/listinfo/zope
  **   No cross posts or HTML encoding!  **
  (Related lists - 
   http://mail.zope.org/mailman/listinfo/zope-announce
   http://mail.zope.org/mailman/listinfo/zope-dev )
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: Preserving Context

2006-12-12 Thread Javier Subervi
752




From: Jonathan [EMAIL PROTECTED]


In your root folder you could have a script that 
accesses the ZCatalog which can be called from any subfolder and can tell 
where it was called from... try the following:  create a python script 
(tst) in your root folder that contains the following code:

 

return str(traverse_subpath)



 

then invoke this script file as 
followings:

 

http:/your.web.site/tst


http:/your.web.site/tst/folderA


http:/your.web.site/tst/folderB/folderC

 

(substitute your own subfolders as required)



You're going to be disappointed, but whenever I substituted in any number of 
valid folders, I got the same result:

[]

an empty set!
TIA,
Javier








 

Any questions? Get answers on any topic at www.Answers.yahoo.com.  Try it now.___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: Preserving Context

2006-12-12 Thread Javier Subervi
From: Jonathan [EMAIL PROTECTED]
 
What version of zope are you running? (I am running zope 2.9.2 on a linux box).
2.7.8

I didn't put it in 'root' since root isn't automatically called. I put it in a 
folder called 's' which is automatically called, then I also explicitly called 
it in the URL. Obviously, if the fn weren't found, Zope would have complained. 
It was in fact found.
TIA,
Javier




 

Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Re: Preserving Context

2006-12-12 Thread Jonathan
The script routine doesn't have to be located in root.  traverse_subpath is 
populated using the names of all subfolders that occur after the script file 
name in the URL.  So if your URL is:  
http:/my.web.site/folderA/scriptA/folderB/folderC, then scriptA will receive a 
traverse_subpath variable (in REQUEST namespace) that contains ['folderB', 
'folderC'].  Note: this will not work if there are any other scripts, DMTL 
methods etc in the URL after 'scriptA'.



Jonathan
  - Original Message - 
  From: Javier Subervi 
  To: zope@zope.org 
  Sent: Tuesday, December 12, 2006 1:48 PM
  Subject: [Zope] Re: Preserving Context


  From: Jonathan [EMAIL PROTECTED]
   
  What version of zope are you running? (I am running zope 2.9.2 on a linux 
box).
  2.7.8

  I didn't put it in 'root' since root isn't automatically called. I put it in 
a folder called 's' which is automatically called, then I also explicitly 
called it in the URL. Obviously, if the fn weren't found, Zope would have 
complained. It was in fact found.
  TIA,
  Javier



--
  Any questions? Get answers on any topic at Yahoo! Answers. Try it now.


--


  ___
  Zope maillist  -  Zope@zope.org
  http://mail.zope.org/mailman/listinfo/zope
  **   No cross posts or HTML encoding!  **
  (Related lists - 
   http://mail.zope.org/mailman/listinfo/zope-announce
   http://mail.zope.org/mailman/listinfo/zope-dev )
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Re: Preserving Context

2006-12-12 Thread Maciej Wisniowski
As far as I understand you have script (say it has id 'handle_404_scr')
that handles 404 errors in 'root' folder. In this script you have
something like:
div align=center
   tal:define=mycontext here
   tal:condition=here/hasSearchEngine(mycontext)

Yes? So how is this script called?


I'm not sure what exactly is your case but you may try:

div align=center
   tal:condition=here/hasSearchEngine(here/aq_inner)

or just (without passing a parameter):

div align=center
   tal:condition=here/aq_inner/hasSearchEngine()



-- 
Maciej Wisniowski
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: Preserving Context

2006-12-12 Thread Javier Subervi
From: Jonathan [EMAIL PROTECTED]

The script routine doesn't have to be located in root.  traverse_subpath is 
populated using the names of all subfolders that occur after the script file 
name in 
the URL.  So if your URL is:  
http:/my.web.site/folderA/scriptA/folderB/folderC, 
then scriptA will receive a traverse_subpath variable (in REQUEST namespace) 
that contains ['folderB', 'folderC'].  Note: this will not work if there are 
any other scripts, DMTL methods etc in the URL after 'scriptA'.

I figured out what I was doing wrong. Apparently, the script needs to be called 
*before* the folders. I had put it at the end. Okay, that works, so now how do 
I incorporate it? I'm running into trouble here. I've rewritten the following 
line several times, and several times gotten it wrong. Perhaps you could steer 
me right?

div align=center 
   tal:define=mycontext python:`here.traverse_subpath`
   tal:condition=here/hasSearchEngine(mycontext)

TIA,
Javier




 

Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Re: Preserving Context

2006-12-12 Thread Jonathan

- Original Message - 
From: Javier Subervi 
To: zope@zope.org 
Sent: Tuesday, December 12, 2006 2:29 PM
Subject: [Zope] Re: Preserving Context


The script routine doesn't have to be located in root.  traverse_subpath is 
populated using the names of all subfolders that occur after the script file 
name in 
the URL.  So if your URL is:  
http:/my.web.site/folderA/scriptA/folderB/folderC, 
then scriptA will receive a traverse_subpath variable (in REQUEST namespace) 
that contains ['folderB', 'folderC'].  Note: this will not work if there are 
any other scripts, DMTL methods etc in the URL after 'scriptA'.

I figured out what I was doing wrong. Apparently, the script needs to be 
called *before* the folders. I had put it at the end. Okay, that works, so 
now how do I incorporate it? I'm running into trouble here. I've rewritten the 
following line several times, and several times gotten it wrong. Perhaps you 
could steer me right?

div align=center 
   tal:define=mycontext python:`here.traverse_subpath`
   tal:condition=here/hasSearchEngine(mycontext)



Your page template just needs to construct a URL (that your users can access - 
eg. in an html link) that contains the name of the script file at the beginning 
of the URL (ie. before the target subfolder(s)).

The script file will have to use the traverse_subpath contents to build a 
string which you can then use to access the required folder:

targetFolder = string.join(traverse_subpath, '/')#you will have to play 
with this to get the right target folder for your app
aFolder = context.restrictedTraverse(targetFolder)
searchRes = aFolder.Catalog(some search string here)
do something with search results here



Jonathan


Any questions? Get answers on any topic at Yahoo! Answers. Try it now.



___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] Re: Preserving Context

2006-12-11 Thread Suresh V

Javier Subervi wrote:

Hi;
I have a page template which I use to catch and customize 404 errors. In 
that page, I call a script that offers site navigation. Since I have 
several sites within a portal, I decided to move all common elements 
(such as this page) to a central root location from which all sites 
could draw. However, when I did that, this page returned the navigation 
of that root dir! That's not what I want, of course. How do I preserve 
context for the called script, such that when the page is called, it 
passes the context from where it was called to the script in question?

TIA,
Javier



1. Are you using container rather than context in your script?
2. You can pass your context as a mycontext parameter to your script.

Suresh


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )