Re: [pylons-discuss] Re: Traversal over a filesystem

68 views
Skip to first unread message

Mike Orr

unread,
Sep 30, 2016, 1:39:01 AM9/30/16
to pylons-...@googlegroups.com
In my slowly-renovating personal site I've got traversal over a
directory of HTML files working. My code so far is attached. It
traverses to an HTML file and serves it as a Mako template. It
supports an implicit "index.html" in directories, and appends ".html"
to the filename if missing. Longer term I want to extract the resource
class and default view from meta tags in the file.

<meta name="resource":
class name, looked up in a dict, default to a generic HTML resource.
<meta name="view":
default view name if user doesn't specify. Defaults to basic HTML view.

So I have two questions:

1) Right now I'm doing the 'context["index.html"]' lookup in the view
because I don't know how to do it during traversal. The problem is
that when I'm in a traversal level that's a directory, there are two
possible outcomes. If I'm in the middle of the URL, I should allow it
to traverse normally to the next subdirectory or file. But if I'm at
the end of the URL (no child but maybe a view afterward), then I want
to implicitly append the "index.html" file as a child. One, can I do
that, and two, is it possible to tell in a traversal level whether
it's the last one or not (i.e.,whether there's a child in the URL)?

2) Is it possible for a resource to offer a default view? Kotti has
some feature where a resource (a database record) has a default view
field that can be customized by the site admin. I don't know how that
works. Is it feasable to do this without hacking up the view lookup
mechanism severely?
resources_py.txt
views_py.txt

Tres Seaver

unread,
Sep 30, 2016, 2:29:50 AM9/30/16
to pylons-...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/30/2016 01:38 AM, Mike Orr wrote:

> 1) Right now I'm doing the 'context["index.html"]' lookup in the view
> because I don't know how to do it during traversal. The problem is
> that when I'm in a traversal level that's a directory, there are two
> possible outcomes. If I'm in the middle of the URL, I should allow it
> to traverse normally to the next subdirectory or file. But if I'm at
> the end of the URL (no child but maybe a view afterward), then I want
> to implicitly append the "index.html" file as a child. One, can I do
> that, and two, is it possible to tell in a traversal level whether
> it's the last one or not (i.e.,whether there's a child in the URL)?

If the default view (see below) for your directory class just does a
redirect to 'index.html', and you register a view named 'index.html' for
it, that should work: if there is an item named 'index.html', it's
default view will be served; otherwise, the 'index.html' view.

> 2) Is it possible for a resource to offer a default view? Kotti has
> some feature where a resource (a database record) has a default view
> field that can be customized by the site admin. I don't know how that
> works. Is it feasable to do this without hacking up the view lookup
> mechanism severely?

A default view is just a view with the empty string for its name. You
may be looking at it already, but the "Traveral Agorithm" docs explain
this in detail:


http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/traversal.htm
l#the-traversal-algorithm

BTW, your application sounds startlingly similar to 'repoze.virginia',
and early proof-of-concept for the publishing logic which became
'repoze.bfg' and later Pyramid:

http://svn.repoze.org/repoze.virginia/trunk/


Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 tse...@palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJX7gY2AAoJEPKpaDSJE9HYZ2kP/1CYGn3QX4zdUV/DG9UwN/0i
n9WSFKozo6Vwy2oxgy6Y21+lC06wkCk18QiN8ahEfzZe4loy07+wUMf8ythRrzMM
b+SsMOZNUGdySaRErpCBhfrUKDbOmVqnwjg01aLFJE/B97/Ga88MS0DX/XB7qS1o
hNs/a0r3MFl+uXLKHstAE5u13iuMCeF0SS8xs5xmgMp/xbC2Z0yUmsGxhGeMJ/d9
cjbSmBkQuhbKZooVgd36uY8YvSq5Yw1p807+2pza1gTXJcaTrdzt9qNrMdW7DCaE
J7uNFJ3ucOYIlWGz2A+5Svdg8SXUOKS50kpRDsxB376Njc0e/CT+776yBQKT1UH0
wRFEXLAbeOmSjlKWSLz68JHbnJydH2HHqBNXBOLqUQ78SB+y1QaMH7bv9WYQKwmk
S+Nb3AAzx1IeS4UJ3PQsHzP22Ox4w627304QdCzTTMrpXogopqYVZs4xCgyzsupN
vpcZLmsi3rWNLPybdU/ipSz9J9UGVpt+rBwfByut5h91cRfijYA5LeRPjw6wpz15
BbG0SndidNrkWU10cQzr0Kpo3LF0HFSjXLkCvnRlljScJ0Tx1/V64mN/ZrVjLve2
GJ6A+dg4f6ddMYH75+KxC7Ww04OlJrVjRi+c2OWfJNIBXOovvyDOeAvjllSupn/7
WhZWqwFVFORlquscYrYM
=IeR6
-----END PGP SIGNATURE-----

Mike Orr

unread,
Oct 1, 2016, 1:48:51 AM10/1/16
to pylons-...@googlegroups.com
On Thu, Sep 29, 2016 at 11:29 PM, Tres Seaver <tse...@palladion.com> wrote:
> http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/traversal.htm
> l#the-traversal-algorithm
>
> BTW, your application sounds startlingly similar to 'repoze.virginia',
> and early proof-of-concept for the publishing logic which became
> 'repoze.bfg' and later Pyramid:
>
> http://svn.repoze.org/repoze.virginia/trunk/

I can actually read this sort of. What does this mean in the ZCML file?


<view
for=".interfaces.IFile"
view=".views.raw_view"
name=".html"
/>

Is this expecting a URL like /abc/.html? Or does BFG allow a URL
/abc/d.html to match a resource "d" without a slash before the view
name?
Reply all
Reply to author
Forward
0 new messages