Back to index

plone3  3.1.7
Functions | Variables
plone.app.linkintegrity.handlers Namespace Reference

Functions

def findObject
def getObjectsFromLinks
def modifiedArchetype
def referenceRemoved
def referencedObjectRemoved

Variables

string referencedRelationship = 'isReferencing'

Function Documentation

def plone.app.linkintegrity.handlers.findObject (   base,
  path 
)
traverse to given path and find the upmost object 

Definition at line 16 of file handlers.py.

00016 
00017 def findObject(base, path):
00018     """ traverse to given path and find the upmost object """
00019     obj = base
00020     components = path.split('/')
00021     while components:
00022         child_id = urllib.unquote(components[0])
00023         try: child = obj.restrictedTraverse(child_id)
00024         except: return None, None
00025         if not IItem.providedBy(child):
00026             break
00027         obj = child
00028         components.pop(0)
00029     return obj, '/'.join(components)
00030 

Here is the caller graph for this function:

determine actual objects refered to by given links 

Definition at line 31 of file handlers.py.

00031 
00032 def getObjectsFromLinks(base, links):
00033     """ determine actual objects refered to by given links """
00034     objects = set()
00035     url = base.absolute_url()
00036     scheme, host, path, query, frag = urlsplit(url)
00037     site = urlunsplit((scheme, host, '', '', ''))
00038     for link in links:
00039         s, h, path, q, f = urlsplit(link)
00040         if (not s and not h) or (s == scheme and h == host):    # relative or local url
00041             obj, extra = findObject(base, path)
00042             if obj:
00043                 if IOFSImage.providedBy(obj):
00044                     obj = aq_parent(obj)    # use atimage object for scaled images
00045                 objects.add(obj)
00046     return objects
00047 

Here is the call graph for this function:

Here is the caller graph for this function:

an archetype based object was modified 

Definition at line 48 of file handlers.py.

00048 
00049 def modifiedArchetype(obj, event):
00050     """ an archetype based object was modified """
00051     try:    # TODO: is this a bug or a needed workaround?
00052         existing = set(obj.getReferences(relationship=referencedRelationship))
00053     except AttributeError:
00054         return
00055     refs = set()
00056     for field in obj.Schema().fields():
00057         if isinstance(field, TextField):
00058             accessor = field.getAccessor(obj)
00059             links = extractLinks(accessor())
00060             refs = refs.union(getObjectsFromLinks(obj, links))
00061     for ref in refs.difference(existing):   # add new references and...
00062         try:
00063             obj.addReference(ref, relationship=referencedRelationship)
00064         except ReferenceException:
00065             pass
00066     for ref in existing.difference(refs):   # removed leftovers
00067         obj.deleteReference(ref, relationship=referencedRelationship)
00068 

Here is the call graph for this function:

Here is the caller graph for this function:

check if the removal was already confirmed or redirect to the form 

Definition at line 86 of file handlers.py.

00086 
00087 def referencedObjectRemoved(obj, event):
00088     """ check if the removal was already confirmed or redirect to the form """
00089     # if the object the event was fired on doesn't have a `REQUEST` attribute
00090     # we can safely assume no direct user action was involved and therefore
00091     # never raise a link integrity exception...
00092     # (this should also fix http://plone.org/products/cachefu/issues/86)
00093     if not hasattr(obj, 'REQUEST'):
00094         return
00095     info = ILinkIntegrityInfo(obj.REQUEST)
00096 
00097     # first we check if link integrity checking was enabled
00098     if not info.integrityCheckingEnabled():
00099         return
00100 
00101     # since the event gets called for every subobject before it's
00102     # called for the item deleted directly via _delObject (event.object)
00103     # itself, but we do not want to present the user with a confirmation
00104     # form for every (referred) subobject, so we remember and skip them...
00105     info.addDeletedItem(obj)
00106     if obj is not event.object:
00107         return
00108 
00109     # if the number of expected events has been stored to help us prevent
00110     # multiple forms (i.e. in folder_delete), we wait for the next event
00111     # if we know there will be another...
00112     if info.moreEventsToExpect():
00113         return
00114 
00115     # at this point all subobjects have been removed already, so all
00116     # link integrity breaches caused by that have been collected as well;
00117     # if there aren't any (after things have been cleaned up),
00118     # we keep lurking in the shadows...
00119     if not info.getIntegrityBreaches():
00120         return
00121 
00122     # if the user has confirmed to remove the currently handled item in a
00123     # previous confirmation form we won't need it anymore this time around...    
00124     if info.isConfirmedItem(obj):
00125         return
00126 
00127     # otherwise we raise an exception and pass the object that is supposed
00128     # to be removed as the exception value so we can use it as the context
00129     # for the view triggered by the exception;  this is needed since the
00130     # view is an adapter for the exception and a request, so it gets the
00131     # exception object as the context, which is not very useful...
00132     raise LinkIntegrityNotificationException, obj
00133 
store information about the removed link integrity reference 

Definition at line 69 of file handlers.py.

00069 
00070 def referenceRemoved(obj, event):
00071     """ store information about the removed link integrity reference """
00072     assert IReference.providedBy(obj)
00073     assert obj is event.object          # just making sure...
00074     if not obj.relationship == referencedRelationship:
00075         return                          # skip for other removed references
00076     # if the object the event was fired on doesn't have a `REQUEST` attribute
00077     # we can safely assume no direct user action was involved and therefore
00078     # never raise a link integrity exception...
00079     if not hasattr(obj, 'REQUEST'):
00080         return
00081     storage = ILinkIntegrityInfo(obj.REQUEST)
00082     breaches = storage.getIntegrityBreaches()
00083     breaches.setdefault(obj.getTargetObject(), set()).add(obj.getSourceObject())
00084     storage.setIntegrityBreaches(breaches)
00085 


Variable Documentation

Definition at line 13 of file handlers.py.