Dexterity: Get content from a relation field in a parent object for the view

classic Classic list List threaded Threaded
5 messages Options
andreasma andreasma
Reply | Threaded
Open this post in threaded view
|

Dexterity: Get content from a relation field in a parent object for the view

Hello,

I created a Dexterity add-on with some content types. I have a talk
object that lives first in the call for paper folder object. Later it
will be moved to a track folder object that lives in a program folder
object.

I have also a roomfolder object with room objects inside. The rootfolder
lives in the root of the site.

I created a relations field on the track object that gets a relationship
with a room. The room will be displayed in the view / page template of
the track. The room is listed behind every talk in the page template.

But the room doesn't display in the page template of the talk, neither
during his life in the call for paper folder (that's correct) nor in the
track folder (where it is copied later on).

I use the following expression in the talk page template:


        <div class="talkroom">

         <label i18n:translate="label_room">Room:</label>

         <span tal:content="view/TalkRoom" />

        </div>


Inside the view class of the talk (grok-style) I created a function:

    def TalkRoom(context):
       from collective.conference.track import ITrack
       if context is ITrack.providedBy(context):
           room = context.room
       else: room = ""
       return room

But this doesn't work as I expected. I don't get the content of the room
field from the parent ITrack object. Instead I get only the content from
the else expression.

Seemed that I don't get ITrack as context.

Thanks for any hints.

Regards,
Andreas

--
## Developer LibreOffice
## Freie Office-Suite für Linux, Mac, Windows
## http://LibreOffice.org
## Support the Document Foundation (http://documentfoundation.org)
## Meine Seite: http://www.amantke.de 


------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13.
http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
David Glick (Plone) David Glick (Plone)
Reply | Threaded
Open this post in threaded view
|

Re: Dexterity: Get content from a relation field in a parent object for the view

On 9/21/13 3:35 PM, Andreas Mantke wrote:

> Hello,
>
> I created a Dexterity add-on with some content types. I have a talk
> object that lives first in the call for paper folder object. Later it
> will be moved to a track folder object that lives in a program folder
> object.
>
> I have also a roomfolder object with room objects inside. The rootfolder
> lives in the root of the site.
>
> I created a relations field on the track object that gets a relationship
> with a room. The room will be displayed in the view / page template of
> the track. The room is listed behind every talk in the page template.
>
> But the room doesn't display in the page template of the talk, neither
> during his life in the call for paper folder (that's correct) nor in the
> track folder (where it is copied later on).
>
> I use the following expression in the talk page template:
>
>
>          <div class="talkroom">
>
>           <label i18n:translate="label_room">Room:</label>
>
>           <span tal:content="view/TalkRoom" />
>
>          </div>
>
>
> Inside the view class of the talk (grok-style) I created a function:
>
>      def TalkRoom(context):
>         from collective.conference.track import ITrack
>         if context is ITrack.providedBy(context):
>             room = context.room
>         else: room = ""
>         return room
>
> But this doesn't work as I expected. I don't get the content of the room
> field from the parent ITrack object. Instead I get only the content from
> the else expression.
>
> Seemed that I don't get ITrack as context.
>
> Thanks for any hints.
>
>
If I'm understanding correctly, you want something like this:

parent = aq_parent(self.context)  # self.context is the Talk, its
aq_parent should be either a CFP or a Track
if ITrack.providedBy(parent):
     room = parent.room  # well probably you actually want
parent.room.to_object.title, since "parent.room" is a RelationValue
else:
     room = ""
return room


------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13.
http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
ajung ajung
Reply | Threaded
Open this post in threaded view
|

Re: Dexterity: Get content from a relation field in a parent object for the view

David Glick (Plone) wrote
parent = aq_parent(self.context)  # self.context is the Talk, its
You want aq_parent(aq_inner(self.context)) in order to avoid issues with improper or bad aquisition-wrapped objects. Welcome to the Zope hell.

-aj
andreasma andreasma
Reply | Threaded
Open this post in threaded view
|

Re: Dexterity: Get content from a relation field in a parent object for the view

In reply to this post by David Glick (Plone)
Hello David,

Am 22.09.2013 00:42, schrieb David Glick (Plone):

> On 9/21/13 3:35 PM, Andreas Mantke wrote:
>> (...)
>>
>>
>> Inside the view class of the talk (grok-style) I created a function:
>>
>>      def TalkRoom(context):
>>         from collective.conference.track import ITrack
>>         if context is ITrack.providedBy(context):
>>             room = context.room
>>         else: room = ""
>>         return room
>>
>> But this doesn't work as I expected. I don't get the content of the room
>> field from the parent ITrack object. Instead I get only the content from
>> the else expression.
>>
>> Seemed that I don't get ITrack as context.
>>
>> Thanks for any hints.
>>
>>
> If I'm understanding correctly, you want something like this:
>
> parent = aq_parent(self.context)  # self.context is the Talk, its
> aq_parent should be either a CFP or a Track
> if ITrack.providedBy(parent):
>     room = parent.room  # well probably you actually want
> parent.room.to_object.title, since "parent.room" is a RelationValue
> else:
>     room = ""
> return room
>
>
yes that's what I want to do.
 
I had to change over to the to_object.title method because otherwise I
get only the reference object.

I got it to work with:


    def TalkRoom(self):
       from collective.conference.track import ITrack
       parent = aq_parent(self.context)
       if ITrack.providedBy(parent):
           room = parent.room.to_object.title
       else: room = ""
       return room


But I extended it with the hint from Andreas Jung about possible
acquisition issues to:


    def TalkRoom(self):
       from collective.conference.track import ITrack
       parent = aq_parent(aq_inner(self.context))
       if ITrack.providedBy(parent):
           room = parent.room.to_object.title
       else: room = ""
       return room

Both versions worked for me.

Thanks for your hints.

Best regards,
Andreas

--
## Developer LibreOfficei
## Freie Office-Suite für Linux, Mac, Windows
## http://LibreOffice.org
## Support the Document Foundation (http://documentfoundation.org)
## Meine Seite: http://www.amantke.de 


------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13.
http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
andreasma andreasma
Reply | Threaded
Open this post in threaded view
|

Re: Dexterity: Get content from a relation field in a parent object for the view

In reply to this post by ajung
Hello Andreas,

Am 22.09.2013 08:51, schrieb ajung:
> David Glick (Plone) wrote
>> parent = aq_parent(self.context)  # self.context is the Talk, its
> You want aq_parent(aq_inner(self.context)) in order to avoid issues with
> improper or bad aquisition-wrapped objects. Welcome to the Zope hell.
>
> -aj
>
>
thanks for the hint. I used it and try to get out of the hell ;-)

Best regards,
Andreas

--
## Developer LibreOffice
## Freie Office-Suite für Linux, Mac, Windows
## http://LibreOffice.org
## Support the Document Foundation (http://documentfoundation.org)
## Meine Seite: http://www.amantke.de 


------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/22/13.
http://pubads.g.doubleclick.net/gampad/clk?id=64545871&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users