[PEAK] Example using sitemap.xml and bulletins

Phillip J. Eby pje at telecommunity.com
Sat Mar 26 14:30:57 EST 2005


At 08:46 PM 3/25/05 -0100, Tiago Cogumbreiro wrote:
>I've been playing with sitemap a little further and actually managed
>to make it show something. I've used an example analogical to
>bulletins, yet it's not the same. However i'm going to "translate" the
>sitemap in order to make it simillar for simplicity's sake:
>
><location id="root" config="bulletins">
>         <import module="bulletins.app"/>
>         <import module="bulletins.model"/>
>         <import module="bulletins.storage"/>
>
>         <container object="bulletins.app.BulletinsApp()"/>
>
>         <content type="bulletins.model.Bulletin">
>                 <allow attributes="fullText"/>
>                 <view name="index_html" 
> resource="bulletins.templates/bulletin"/>
>         </content>
>
>         <content type="bulletin.storage.BulletinDM">
>                 <view name="index_html" 
> resource="bulletin.templates/list_bulletins"/>
>         </content>
>
>         <content type="bulletins.app.BulletinsApp">
>                 <allow attributes="Bulletins"/>
>                 <view name="index_html" resource="imobil.templates/main"/>
>         </content>
></location>
>
>This sitemap is supposed to create a /Bulletins location which allows
>/Bulletins/<ID> to retrieve a bulletins.model.Bulletin, using the
>bulletin.templates/bulletin template.

You need something more like this (untested):

<location config="bulletins">
    <import module="bulletins.model" />
    <import module="bulletins.storage" />

    <location name="Bulletins" />
        <container object="storage.BulletinDM()"/>
    </location>

    <content type="model.Bulletin">
       etc.

The main problem with getting this to work properly is that the bulletins 
application's structure is a bit off.  Looking at it, it's clear to me that 
the App object doesn't really belong there; it's a holdover from when I 
thought peak.web was going to work differently.

Really, everything that's in the BulletinsApp class should actually be 
configured in bulletins.ini, and then just referenced from BulletinsCmd 
where needed.  But there are some problems with doing that, because there 
currently isn't an "obvious" way to register a DMFor() using an .ini.

What I think I need to do to make this work well is:

1) Have a 'component="key"' option for <container>, so that you can specify 
an expression like 'storage.DMFor(sometype)', or 'PropertyName("foo.bar")', 
etc.  This would do a 'lookupComponent()' on the location object so you can 
obtain something you need.

2) Have a cleaner way to register DMFor() objects in an .ini  (maybe using 
a "[Data Managers]" section)

3) Refactor the bulletins example to remove BulletinsApp and do all the 
configuration in bulletins.ini, with something like:

     [Data Managers]
     bulletins.model.Bulletin = 'bulletins.storage:BulletinDM'
     bulletins.model.Category = 'bulletins.storage:CategoryDM'
     bulletins.model.User     = 'bulletins.storage:UserDM'

As part of this, I'd also get rid of the 'bulletins.databaseURL' property 
and change the 'bulletins' start file to read something like:

     [Named Services]
     bulletins.db = naming.LinkRef("sqlite:///tmp/bulletins.db")

And then I'd add 'db' and other bindings to BulletinsCmd, so that it 
wouldn't need BulletinsApp.  Finally, the sitemap would be able to refer to 
DM's using e.g.:

     <location name="Bulletins">
         <container component="storage.DMFor(model.Bulletin)"/>
         etc.


>The views inside the BulletinDM are ignored, thus the resource
>'bulletin.templates/list_bulletins' is never accessed. This happens
>because it tries to do a __getitem__ on the object first, so it sends
>an error message because it tries to access the object with an id
>index_html.

If you change the 'peak.web.defaultMethod' configuration to '@@index_html', 
or if you manually go to the URL '/Bulletins/@@index_html' this should fix 
it.  The '@@' means to look only at views, not items.  It occurs to me that 
this should probably be the default configuration for the index_html 
method, except that then objects with an 'index_html()' method would not 
work.  I probably won't be able to fix this properly until peak.web moves 
to using generic functions.


>oid's related to sql are usually int's, but they (the web controller)
>send a string. How can one intercept this procedure? Currently I'm
>converting any argument to an int inside the DM, but this feels like
>an hack.

Yes, it does.  The <container> tag probably needs an optional 'key_type' 
attribute to let you define a conversion function.

It looks like I need to make quite a few changes to make this conveniently 
usable.  That is, although it's *possible* right now to define a sitemap 
for the bulletins application, you have to do a lot of Python coding inside 
of modules, and it's pretty obscure coding at that.  I'll try to take some 
time this weekend to fix these things up a bit, and create a working 
sitemap for the bulletins example.  :(


>Can I embedd views inside of each other?

I don't understand the question.




More information about the PEAK mailing list