Mailing List Archive

Problem Understanding URL
I think I have a simple question about how Zope is handling requests. My current task is to understand an already-written Zope web application.

One thing I can't wrap my head around is this URL:

https://mysite.com/UserManagement/Users/asmithS/

Speaking in Zope terms, the UserManagement object is contained in the top-level product. In the UserManagement object, there is a Users object. That's all fine and dandy, run of the mill, acquisition/containment. However, the Users object has no asmithS object. In fact, asmithS is just a username, which makes the last field in the URL essentially a parmeter on the Users object.

From examining the behavior of the webapp and the code itself, I know that the index_html method of the Users object is what is returned from this request, which is a Page Template that displays the user information based on the parameter.

All of what I've said so far could be wrong, so feel free to correct me if I've mis-spoken. The problem I have is that this asmithS guy seems magical. I can't figure out how the index_html knows to be called with the username as a parameter(obviously the index_html function doesn't explicitly require the parameter).

What I BELIEVE is happening: the asmithS argument is processed before the page template renders. For example, when asmithS is given, a lookup is performed on the database that adds variables to the REQUEST object such as FirstName, LastName, etc. I can't find this happening but I think it must exist.

From the zpt file:

<td valign="top" tal:content="here/LastName">Doe</td>

What I want to know is: How can do these URL arguments work? A more advanced question would be: how do you think these here/*** variables are being added to the context.

I'm actually using Zope 2.

Thanks for any help
Re: Problem Understanding URL [ In reply to ]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/23/2012 12:55 PM, Jared Hall wrote:
> I think I have a simple question about how Zope is handling requests.
> My current task is to understand an already-written Zope web
> application.
>
> One thing I can't wrap my head around is this URL:
>
> https://mysite.com/UserManagement/Users/asmithS/
>
> Speaking in Zope terms, the UserManagement object is contained in the
> top-level product. In the UserManagement object, there is a Users
> object. That's all fine and dandy, run of the mill,
> acquisition/containment. However, the Users object has no asmithS
> object. In fact, asmithS is just a username, which makes the last
> field in the URL essentially a parmeter on the Users object.
>
> From examining the behavior of the webapp and the code itself, I know
> that the index_html method of the Users object is what is returned
> from this request, which is a Page Template that displays the user
> information based on the parameter.
>
> All of what I've said so far could be wrong, so feel free to correct
> me if I've mis-spoken. The problem I have is that this asmithS guy
> seems magical. I can't figure out how the index_html knows to be
> called with the username as a parameter(obviously the index_html
> function doesn't explicitly require the parameter).
>
> What I BELIEVE is happening: the asmithS argument is processed before
> the page template renders. For example, when asmithS is given, a
> lookup is performed on the database that adds variables to the REQUEST
> object such as FirstName, LastName, etc. I can't find this happening
> but I think it must exist.

Check the code for your 'Users' object for one of the following methods:

- - '__bobo_traverse__'

- - '__getitem__'


I'm gueessing one of those is resposible for returning the object
corresponding to 'asmithS': that object is the "here" (context) for the
template.

Another (weirder) possibility is the '__before_publishing_traverse__'
method, which (if present) gets called when publishing traversal enters
an object: it can munge the request arbitrarily.


Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver@palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlANklkACgkQ+gerLs4ltQ6UhgCgps7jhPQDmXkCm8SYXC43sCE6
wzAAoNoZkjejtPs3pnPkXkrUexZ6czYN
=puKr
-----END PGP SIGNATURE-----

_______________________________________________
Zope maillist - Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )
Re: Problem Understanding URL [ In reply to ]
Ok I'd read about those functions a little bit in the Zope 2 book or the Developer's Guide, but they seemed like advanced techniques that I probably wouldn't need to understand.

Back on topic; I ran this awesome command in the terminal:

grep getitem x=$(find . *.*)

and turned up some random references to getitem in some dtml code, which I judge to be insignificant. There was also one very interesting usage of __getitem__ in the python code itself, and I have to investigate the code further to understand what's going on. The function definition looks suspiciously like what I would expect to find for this 'hijacking' of control:

def __getitem__(self, key):
v=self._getOb(key, None)
if v is not None: return v
if hasattr(self, 'REQUEST'):
request=self.REQUEST
method=request.get('REQUEST_METHOD', 'GET')
if request.maybe_webdav_client and not method in ('GET', 'POST'):
return NullResource(self, key, request).__of__(self)
raise KeyError, key

I read this as: look up the object in the current context and return it. The only problem with this is that I don't see when the object gets placed into the proper context for the TAL statements like here/FirstName, etc.

Thanks for your help already, and any continued guidance is appreciated.
Re: Problem Understanding URL [ In reply to ]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/23/2012 03:01 PM, Jared Hall wrote:
> Ok I'd read about those functions a little bit in the Zope 2 book or
> the Developer's Guide, but they seemed like advanced techniques that I
> probably wouldn't need to understand.
>
> Back on topic; I ran this awesome command in the terminal:
>
> grep getitem x=$(find . *.*)
>
> and turned up some random references to getitem in some dtml code,
> which I judge to be insignificant. There was also one very interesting
> usage of __getitem__ in the python code itself, and I have to
> investigate the code further to understand what's going on. The
> function definition looks suspiciously like what I would expect to
> find for this 'hijacking' of control:
>
> def __getitem__(self, key): v=self._getOb(key, None) if v is not None:
> return v if hasattr(self, 'REQUEST'): request=self.REQUEST
> method=request.get('REQUEST_METHOD', 'GET') if
> request.maybe_webdav_client and not method in ('GET', 'POST'): return
> NullResource(self, key, request).__of__(self) raise KeyError, key
>
> I read this as: look up the object in the current context and return
> it. The only problem with this is that I don't see when the object
> gets placed into the proper context for the TAL statements like
> here/FirstName, etc.

There isn't any "hijacking" going on here: Zope2 uses '__getitem__' by
preference for fetching items from a container (falling back to
'__getattr__'). The "context" for your template (aliased as "here") is
going to be the object found by the publishing traversal: in this case,
the 'v' returned from that '__getitem__'.


Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tseaver@palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlANqV4ACgkQ+gerLs4ltQ7egQCeOdxitDMAxAMD9YBHf5S/aNau
GHwAn0mraihjntJorXFBQ0/dPNs4CWEp
=0ejr
-----END PGP SIGNATURE-----

_______________________________________________
Zope maillist - Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )
Re: Problem Understanding URL [ In reply to ]
Tres, I see what you mean. You're saying that the object lookup for a request follows a pattern and that the __getitem__ function has a role in that pattern. That's fine, but even if this is returning a User object there is still a problem. I think we're beyond the point where you can help me though. The problem I'm thinking of is that I know that the /Users/asmithS URL resolves to a call to index_html method of Users which in this case is just rendering the "userView". As I've said the here/Property calls are located in this user view. Could this __getitem__ load the user into the context and then still call the index_html and return the .zpt?

Thanks
Re: Problem Understanding URL [ In reply to ]
I don't know why these are creating new threads. And I'm sorry for the formatting on that last message.
_______________________________________________
Zope maillist - Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope-dev )