Post-create update of a reference field

15 messages Options
Embed this post
Permalink
ajung () Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
Hi there,

following use case: an AT-Event derived content-type contains provides
a "create sub-event" link within its default view. Clicking on the link
will create a new event and add the new event to a referencefield within
the original event (standard master-slave relationship). This works fine
with invokeFactory() and updating the related fields within a browser view.
However I want to use portal_factory in order to avoid orphan event. Any
idea
how to update the referencefield of the master event after the creating
of the
slave event through portal_factory?

Andreas


[lists.vcf]

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[hidden email]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Gilles Lenfant () Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
Le 11 juin 09 à 10:47, Andreas Jung a écrit :

> Hi there,
>
> following use case: an AT-Event derived content-type contains provides
> a "create sub-event" link within its default view. Clicking on the  
> link
> will create a new event and add the new event to a referencefield  
> within
> the original event (standard master-slave relationship). This works  
> fine
> with invokeFactory() and updating the related fields within a  
> browser view.
> However I want to use portal_factory in order to avoid orphan event.  
> Any
> idea
> how to update the referencefield of the master event after the  
> creating
> of the
> slave event through portal_factory?

Hi,

Add a "def manage_afterPortalFactoryCreate(self)" method to your  
custom event type, and play with it. Perhaps the latest versions of  
portal_factory fire an event in that case.

See the source of the "doCreate" method of portal_factory.

HTH
--
Gilles Lenfant


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Maurits van Rees-3 () Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
In reply to this post by ajung
Andreas Jung, on 2009-06-11:

>
> Hi there,
>
> following use case: an AT-Event derived content-type contains provides
> a "create sub-event" link within its default view. Clicking on the link
> will create a new event and add the new event to a referencefield within
> the original event (standard master-slave relationship). This works fine
> with invokeFactory() and updating the related fields within a browser view.
> However I want to use portal_factory in order to avoid orphan event. Any
> idea
> how to update the referencefield of the master event after the creating
> of the
> slave event through portal_factory?

Register a zope 3 event handler for the sub event type and
Products.Archetypes.interfaces.IObjectInitializedEvent

In that handler check if the parent of the object is an instance of
your AT-Event derived content-type and set the reference field.

--
Maurits van Rees | http://maurits.vanrees.org/
            Work | http://zestsoftware.nl/
"This is your day, don't let them take it away." [Barlow Girl]


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
ajung () Re: Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
On 11.06.09 11:24, Maurits van Rees wrote:

> Andreas Jung, on 2009-06-11:
>  
>> Hi there,
>>
>> following use case: an AT-Event derived content-type contains provides
>> a "create sub-event" link within its default view. Clicking on the link
>> will create a new event and add the new event to a referencefield within
>> the original event (standard master-slave relationship). This works fine
>> with invokeFactory() and updating the related fields within a browser view.
>> However I want to use portal_factory in order to avoid orphan event. Any
>> idea
>> how to update the referencefield of the master event after the creating
>> of the
>> slave event through portal_factory?
>>    
> Register a zope 3 event handler for the sub event type and
> Products.Archetypes.interfaces.IObjectInitializedEvent
>
> In that handler check if the parent of the object is an instance of
> your AT-Event derived content-type and set the reference field.
Object subscriber won't work because the events aren't nested and the
parent container
does not know about the original object :-)

Andreas

[lists.vcf]

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[hidden email]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Maurits van Rees-3 () Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
Andreas Jung, on 2009-06-11:
>> Register a zope 3 event handler for the sub event type and
>> Products.Archetypes.interfaces.IObjectInitializedEvent
>>
>> In that handler check if the parent of the object is an instance of
>> your AT-Event derived content-type and set the reference field.
> Object subscriber won't work because the events aren't nested and the
> parent container
> does not know about the original object :-)

Ah, right, I thought you had folderish event types and were creating a
sub event inside an event.

Hm, perhaps you can pass a parameter like came_from to the link to
portal factory and hook that into the edit form of the object; then
look for that parameter in the zope 3 event handler.

The archetypes edit form has some slots that you can file, like
extra_bottom.  If you fill that slot with some template code that
checks for a came_from parameter (or just checks for a default request
parameter) it might work.

--
Maurits van Rees | http://maurits.vanrees.org/
            Work | http://zestsoftware.nl/
"This is your day, don't let them take it away." [Barlow Girl]


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Yuri-11 () Re: Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
In reply to this post by ajung
Andreas Jung ha scritto:

> On 11.06.09 11:24, Maurits van Rees wrote:
>  
>> Andreas Jung, on 2009-06-11:
>>  
>>    
>>> Hi there,
>>>
>>> following use case: an AT-Event derived content-type contains provides
>>> a "create sub-event" link within its default view. Clicking on the link
>>> will create a new event and add the new event to a referencefield within
>>> the original event (standard master-slave relationship). This works fine
>>> with invokeFactory() and updating the related fields within a browser view.
>>> However I want to use portal_factory in order to avoid orphan event. Any
>>> idea
>>> how to update the referencefield of the master event after the creating
>>> of the
>>> slave event through portal_factory?
>>>    
>>>      
>> Register a zope 3 event handler for the sub event type and
>> Products.Archetypes.interfaces.IObjectInitializedEvent
>>
>> In that handler check if the parent of the object is an instance of
>> your AT-Event derived content-type and set the reference field.
>>    
> Object subscriber won't work because the events aren't nested and the
> parent container
> does not know about the original object :-)
>  

I would use plone.app.relations and pass the relation to the sub object,
instead of using referencefields.

Then you can map it in the dublin core, rdf, and you web become semantic
too :D

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


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
ajung () Re: Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
On 11.06.09 11:53, Yuri wrote:

> Andreas Jung ha scritto:
>> On 11.06.09 11:24, Maurits van Rees wrote:
>>  
>>> Andreas Jung, on 2009-06-11:
>>>      
>>>> Hi there,
>>>>
>>>> following use case: an AT-Event derived content-type contains provides
>>>> a "create sub-event" link within its default view. Clicking on the
>>>> link
>>>> will create a new event and add the new event to a referencefield
>>>> within
>>>> the original event (standard master-slave relationship). This works
>>>> fine
>>>> with invokeFactory() and updating the related fields within a
>>>> browser view.
>>>> However I want to use portal_factory in order to avoid orphan
>>>> event. Any
>>>> idea
>>>> how to update the referencefield of the master event after the
>>>> creating
>>>> of the
>>>> slave event through portal_factory?
>>>>          
>>> Register a zope 3 event handler for the sub event type and
>>> Products.Archetypes.interfaces.IObjectInitializedEvent
>>>
>>> In that handler check if the parent of the object is an instance of
>>> your AT-Event derived content-type and set the reference field.
>>>    
>> Object subscriber won't work because the events aren't nested and the
>> parent container
>> does not know about the original object :-)
>>  
>
> I would use plone.app.relations and pass the relation to the sub
> object, instead of using referencefields.
>
> Then you can map it in the dublin core, rdf, and you web become
> semantic too :D
Totally unrelated to my question.

-aj

[lists.vcf]

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[hidden email]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Hedley Roos () Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
In reply to this post by ajung
Andreas Jung wrote:

> Hi there,
>
> following use case: an AT-Event derived content-type contains provides
> a "create sub-event" link within its default view. Clicking on the link
> will create a new event and add the new event to a referencefield within
> the original event (standard master-slave relationship). This works fine
> with invokeFactory() and updating the related fields within a browser view.
> However I want to use portal_factory in order to avoid orphan event. Any
> idea
> how to update the referencefield of the master event after the creating
> of the
> slave event through portal_factory?
>
> Andreas
>
>

Hi Andreas

Have you tried setting keepReferencesOnCopy=1 on the field which
references the sub-event?

There is a chance that it will work since moving an object from a temp
dir to its final location leads to a manage_afterAdd. See
Archetypes/Referenceable.py.

I believe it will work since objects in portal_factory are catalogued.
(They are removed later - can't remember how). This means there is a
window of opportunity for the references to be maintained.

Hedley

_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Chris Rossi () Re: Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
In reply to this post by Maurits van Rees-3


On Thu, Jun 11, 2009 at 5:52 AM, Maurits van Rees <[hidden email]> wrote:

Ah, right, I thought you had folderish event types and were creating a
sub event inside an event.

I wonder if that isn't the right answer.  It's a bit easier problem to solve if your container hierarchy reflects the relationship you're trying to establish.

Chris



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
ajung () Re: Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
On 11.06.09 15:31, Chris Rossi wrote:

>
>
> On Thu, Jun 11, 2009 at 5:52 AM, Maurits van Rees
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>
>     Ah, right, I thought you had folderish event types and were creating a
>     sub event inside an event.
>
>
> I wonder if that isn't the right answer.  It's a bit easier problem to
> solve if your container hierarchy reflects the relationship you're
> trying to establish.
Sorry but using hierarchies for modelling relations is lame - we have
various kind of options implementing
relations (plone.(app).relations, the Products.Relations and the bare AT
ReferenceField).

Andreas

[lists.vcf]

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[hidden email]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Raphael Ritz () Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
In reply to this post by ajung
Andreas Jung wrote:

> Hi there,
>
> following use case: an AT-Event derived content-type contains provides
> a "create sub-event" link within its default view. Clicking on the link
> will create a new event and add the new event to a referencefield within
> the original event (standard master-slave relationship). This works fine
> with invokeFactory() and updating the related fields within a browser view.
> However I want to use portal_factory in order to avoid orphan event. Any
> idea
> how to update the referencefield of the master event after the creating
> of the
> slave event through portal_factory?
>

Isn't that exactly what happens if you enable 'add item' on the
reference field itself (assuming proper configuration of target
folder and portal type on the field/widget) and have your custom
link trigger whatever the 'add' button on the default edit form
does?

Guess I'm missing something ...

Raphael


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


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
ajung () Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
In reply to this post by Hedley Roos
On 11.06.09 15:09, Hedley Roos wrote:

> Andreas Jung wrote:
>> Hi there,
>>
>> following use case: an AT-Event derived content-type contains provides
>> a "create sub-event" link within its default view. Clicking on the link
>> will create a new event and add the new event to a referencefield within
>> the original event (standard master-slave relationship). This works fine
>> with invokeFactory() and updating the related fields within a browser
>> view.
>> However I want to use portal_factory in order to avoid orphan event. Any
>> idea
>> how to update the referencefield of the master event after the creating
>> of the
>> slave event through portal_factory?
>>
>> Andreas
>>
>>
>
> Hi Andreas
>
> Have you tried setting keepReferencesOnCopy=1 on the field which
> references the sub-event?
keepReferencesOnCopy seems to be a dead horse. There is no code -
neither in Archetypes
nor Plone actually using it :-)

Andreas


--
ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany
Web: www.zopyx.com - Email: [hidden email] - Phone +49 - 7071 - 793376
Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535
Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham, UK
------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting



[lists.vcf]

begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[hidden email]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard



_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Hedley Roos () Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
>> Have you tried setting keepReferencesOnCopy=1 on the field which
>> references the sub-event?
>
> keepReferencesOnCopy seems to be a dead horse. There is no code -
> neither in Archetypes
> nor Plone actually using it :-)
>

Mmm. I have rfields=self.Schema().filterFields(type="reference",
keepReferencesOnCopy=1) in Referenceable.py. Some of my content types do
not work if I do not make use of keepRefs.

It was only introduced in Archetype 1.5.8 I think.

Hedley


_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
ajung () Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink


On Fri, Jun 12, 2009 at 13:18, Hedley Roos <[hidden email]> wrote:
Have you tried setting keepReferencesOnCopy=1 on the field which
references the sub-event?

keepReferencesOnCopy seems to be a dead horse. There is no code -
neither in Archetypes
nor Plone actually using it :-)


Mmm. I have rfields=self.Schema().filterFields(type="reference", keepReferencesOnCopy=1) in Referenceable.py. Some of my content types do not work if I do not make use of keepRefs.

It was only introduced in Archetype 1.5.8 I think.

grep through the AT sources and you won't find any code actually using it :-)

Andreas

_______________________________________________
Product-Developers mailing list
[hidden email]
http://lists.plone.org/mailman/listinfo/product-developers
Wichert Akkerman () Re: Post-create update of a reference field
Reply Threaded More More options
Print post
Permalink
On 6/12/09 1:26 PM, Andreas Jung wrote:

>
>
> On Fri, Jun 12, 2009 at 13:18, Hedley Roos <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>             Have you tried setting keepReferencesOnCopy=1 on the field which
>             references the sub-event?
>
>
>         keepReferencesOnCopy seems to be a dead horse. There is no code -
>         neither in Archetypes
>         nor Plone actually using it :-)
>
>
>     Mmm. I have rfields=self.Schema().filterFields(type="reference",
>     keepReferencesOnCopy=1) in Referenceable.py. Some of my content
>     types do not work if I do not make use of keepRefs.
>
>     It was only introduced in Archetype 1.5.8 I think.
>
>
> grep through the AT sources and you won't find any code actually using
> it :-)

Look closer, or see http://dev.plone.org/old/archetypes/changeset/9562 :)

Wichert.


--
Wichert Akkerman <[hidden email]>   It is simple to make things.
http://www.wiggy.net/                  It is hard to make things simple.

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