Back to index

plone3  3.1.7
relation.py
Go to the documentation of this file.
00001 ##################################################################
00002 #
00003 # (C) Copyright 2006 ObjectRealms, LLC
00004 # All Rights Reserved
00005 #
00006 # This file is part of iterate.
00007 #
00008 # iterate is free software; you can redistribute it and/or modify
00009 # it under the terms of the GNU General Public License as published by
00010 # the Free Software Foundation; either version 2 of the License, or
00011 # (at your option) any later version.
00012 #
00013 # iterate is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 # GNU General Public License for more details.
00017 #
00018 # You should have received a copy of the GNU General Public License
00019 # along with CMFDeployment; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 ##################################################################
00022 """
00023 $Id: relation.py 1392 2006-06-20 01:02:17Z hazmat $
00024 """
00025 
00026 from zope.interface import implements
00027 from zope.component import adapts
00028 from zope.annotation.interfaces import IAttributeAnnotatable
00029 
00030 from Products.Archetypes import config as atconf
00031 from Products.Archetypes.ReferenceEngine import Reference
00032 
00033 from interfaces import IWorkingCopyRelation
00034 from interfaces import ICheckinCheckoutReference
00035 from interfaces import IIterateAware
00036 
00037 
00038 class WorkingCopyRelation( Reference ):
00039     """
00040     Source Object is Working Copy
00041 
00042     Target Object is Baseline Version
00043     """
00044     relationship = "Working Copy Relation"
00045 
00046     implements( IWorkingCopyRelation, IAttributeAnnotatable )
00047 
00048 
00049 class CheckinCheckoutReferenceAdapter ( object ):
00050     """
00051     default adapter for references.
00052 
00053     on checkout
00054     
00055     forward refs on baseline are copied to wc
00056     backward refs on baseline are ignored on wc
00057 
00058     on checkin
00059 
00060     forward refs on wc are kept
00061     backwards refs on wc are kept
00062 
00063     forward refs on baseline get removed
00064     backward refs on baseline are kept by virtue of UID transferance
00065     
00066     """
00067 
00068     implements( ICheckinCheckoutReference )
00069     adapts( IIterateAware )
00070     
00071     storage_key = "coci.references"
00072 
00073     def __init__(self, context ):
00074         self.context = context
00075     
00076     def checkout( self, baseline, wc, refs, storage ):
00077         for ref in refs:
00078             wc.addReference( ref.targetUID, ref.relationship, referenceClass=ref.__class__ )
00079             
00080     def checkin( self, *args ):
00081         pass
00082 
00083     checkoutBackReferences = checkinBackReferences = checkin
00084 
00085 
00086 
00087 class NoCopyReferenceAdapter( object ):
00088     """
00089     an adapter for references that does not copy them to the wc on checkout.
00090 
00091     additionally custom reference state is kept when the wc is checked in.
00092     """
00093 
00094     implements( ICheckinCheckoutReference )
00095 
00096     def __init__(self, context):
00097         self.context = context
00098     
00099     def checkin( self, baseline, wc, refs, storage ):
00100         # move the references from the baseline to the wc
00101 
00102         # one note, on checkin the wc uid is not yet changed to match that of the baseline
00103         ref_ids = [r.getId() for r in refs]
00104 
00105         baseline_ref_container = getattr( baseline, atconf.REFERENCE_ANNOTATION )
00106         clipboard = baseline_ref_container.manage_cutObjects( ref_ids )
00107 
00108         wc_ref_container = getattr( wc, atconf.REFERENCE_ANNOTATION )
00109 
00110         # references aren't globally addable w/ associated perm which default copysupport
00111         # wants to check, temporarily monkey around the issue.
00112         def _verifyObjectPaste( *args, **kw ): pass
00113         wc_ref_container._verifyObjectPaste = _verifyObjectPaste
00114         try:
00115             wc_ref_container.manage_pasteObjects( clipboard )
00116         finally:
00117             del wc_ref_container._verifyObjectPaste
00118 
00119     def checkout( self, *args ):
00120         pass
00121         
00122     checkoutBackReferences = checkinBackReferences = checkout
00123