URL to content view

classic Classic list List threaded Threaded
5 messages Options
Gilles Lenfant-2 Gilles Lenfant-2
Reply | Threaded
Open this post in threaded view
|

URL to content view

Hi,

I know we should not make the URL to a content like this:

url = item.absolute_url()

This does not work for files, images, and perhaps other third party content types which "absolute_url()" is the download URL and not a regular Plone view page URL.

The workaround I found is somehow noisy (but works as expected) :

from zope.component import getMultiAdapter
...
content_view = getMultiAdapter((item, request), name=u'plone_context_state')
url = content_view.view_url()

Is there something that's less verbose around ?

Cheers
--
Gilles Lenfant

_______________________________________________
Product-Developers mailing list
[hidden email]
https://lists.plone.org/mailman/listinfo/product-developers
toutpt toutpt
Reply | Threaded
Open this post in threaded view
|

Re: URL to content view

As far as I know ... there is no other solution.

I often just import component and use component.getMultiAdapter, more easy to read and made less imports.
Only two lines of code to get the url is quite good and it works for every things.

Enjoy zope component ;)
Gilles Lenfant-2 Gilles Lenfant-2
Reply | Threaded
Open this post in threaded view
|

Re: URL to content view

yup, I made this in the utils.py of most my components

def viewURLFor(item):
    cdtate = getMultiAdapter((item, item.REQUEST), name='plone_context_state)
    return cstate.view_url()

Cheers
--
Gilles Lenfant

Le 16 févr. 2011 à 19:57, toutpt a écrit :

>
> As far as I know ... there is no other solution.
>
> I often just import component and use component.getMultiAdapter, more easy
> to read and made less imports.
> Only two lines of code to get the url is quite good and it works for every
> things.
>
> Enjoy zope component ;)
>
> -----
> Jean-Michel François aka toutpt
> http://toutpt.wordpress.com
> http://twitter.com/toutpt
>
> --
> View this message in context: http://plone.293351.n2.nabble.com/URL-to-content-view-tp6028204p6033062.html
> Sent from the Product Developers mailing list archive at Nabble.com.
> _______________________________________________
> Product-Developers mailing list
> [hidden email]
> https://lists.plone.org/mailman/listinfo/product-developers

_______________________________________________
Product-Developers mailing list
[hidden email]
https://lists.plone.org/mailman/listinfo/product-developers
Laurence Rowe Laurence Rowe
Reply | Threaded
Open this post in threaded view
|

Re: URL to content view

In reply to this post by Gilles Lenfant-2
Gilles Lenfant-2 wrote
Hi,

I know we should not make the URL to a content like this:

url = item.absolute_url()

This does not work for files, images, and perhaps other third party content types which "absolute_url()" is the download URL and not a regular Plone view page URL.

The workaround I found is somehow noisy (but works as expected) :

from zope.component import getMultiAdapter
...
content_view = getMultiAdapter((item, request), name=u'plone_context_state')
url = content_view.view_url()

Is there something that's less verbose around ?
We already have an @@absolute_url. Perhaps we need an @@view_url?

Laurence
Gilles Lenfant-2 Gilles Lenfant-2
Reply | Threaded
Open this post in threaded view
|

Re: URL to content view

Le 18 févr. 2011 à 01:49, Laurence Rowe a écrit :

>
>
> Gilles Lenfant-2 wrote:
>>
>> Hi,
>>
>> I know we should not make the URL to a content like this:
>>
>> url = item.absolute_url()
>>
>> This does not work for files, images, and perhaps other third party
>> content types which "absolute_url()" is the download URL and not a regular
>> Plone view page URL.
>>
>> The workaround I found is somehow noisy (but works as expected) :
>>
>> from zope.component import getMultiAdapter
>> ...
>> content_view = getMultiAdapter((item, request),
>> name=u'plone_context_state')
>> url = content_view.view_url()
>>
>> Is there something that's less verbose around ?
>>
>
> We already have an @@absolute_url. Perhaps we need an @@view_url?

vote += 1

>
> Laurence
> --
> View this message in context: http://plone.293351.n2.nabble.com/URL-to-content-view-tp6028204p6038269.html
> Sent from the Product Developers mailing list archive at Nabble.com.
> _______________________________________________
> Product-Developers mailing list
> [hidden email]
> https://lists.plone.org/mailman/listinfo/product-developers

_______________________________________________
Product-Developers mailing list
[hidden email]
https://lists.plone.org/mailman/listinfo/product-developers