[Silva-general] Ghost and Links - 2 different problems, each one solved independently

Martijn Faassen faassen at infrae.com
Mon Mar 13 18:12:07 CET 2006


Hi there,

Sorry in taking a while to reply this mail - it doesn't show up in my 
mailbox for some reason.

> Now I run into another problem. Or two be precise two different problems. I
> found a solution for each of it and thought perhaps there is anybody who is
> interested in them:
> 
> I have a SilvaGhost haunting a SilvaLink document. Now what I want to do, is
> to display the url of the SilvaLink. I tried the following approach:
> 
> 1) Get the haunted object with 'item/get_haunted'.
> 
> Problem: get_hauted() does not exist for the class 'Ghost' in Ghost.py.
> 
> Solution: I added the following lines to the class 'Ghost':
>     security.declareProtected(SilvaPermissions.View,'get_haunted')
>     def get_haunted(self):
>         """get the real content object; using restrictedTraverse
> 
>             returns content object, or None on traversal failure.
>         """
>         version = self.getLastVersion()
>         return version.get_haunted()

You could use:

python: item.get_viewable().get_haunted()

and there would not be a need to add methods to Ghost in that case. In 
general we aim to keep the methods inside the versions and not replicate 
methods on the version container. Of course we break that rule in all 
kinds of places, especially for get_title(), but that has historical 
reasons.

> 2) Get the url with 'item/get_haunted/get_url'.
> 
> Problem: get_url() does not exist for the Link object in Link.py.
> 
> Solution: I added the following lines to the class 'Link'
>     security.declarePrivate('getLastVersion')
>     def getLastVersion(self):
>         """returns `latest' version of link
> 
>             link: Silva Link intance
>             returns LinkVersion
>         """
>         version_id = self.get_public_version()
>         if version_id is None:
>             version_id = self.get_next_version()
>         if version_id is None:
>             version_id = self.get_last_closed_version()
>         version = getattr(self, version_id)
>         return version

Hm, I think you can use 'get_previewable()' here instead, instead of 
introducing a new getLastVersion().

>     security.declareProtected(SilvaPermissions.View, 'get_url')
>     def get_url(self):
>         """returns the url of link
>         """
>         version = self.getLastVersion()
>         return version.get_url()
> 
> Now four questions arise:
> * Are the security declaration correct?

Yes, they look fine.

> * Why are these features not implemented in Silva from the very beginning?

Generally you'd first get the version you need (get_editable(), 
get_viewable() or get_previewable()) and then you call the right methods 
on that.

> * Would these developping fellowers implement these two patches in the next
>   release (so that I don't have to do it on my private installation :-)?

Unless you can convince us that using the methods listed is too 
cumbersome, no.

> * Are there other ways to get the same result?

See above.

I realize that it's slightly cumbersome to keep having to call 
'get_previewable' on Silva objects before accessing their API. If we got 
to rewrite Silva I might approach it differently. Then again, I think 
the current approach is quite workable, and has the advantage that you 
can specify which version you're interested in. In public sites, for 
instance, you'd want to use get_viewable(), as that is guaranteed to 
only get public content.

Regards,

Martijn



More information about the Silva-general mailing list