You are here: Home / Documentation / How To's / How to find referring links to File and Image objects

How to find referring links to File and Image objects

by nguyen published Oct 02, 2014 05:10 PM, last modified Aug 16, 2016 10:50 AM
an External Method inspired by Paul Rentschler's pwrentch.FileReferences

Thanks go to Paul Rentschler for his very cool https://pypi.python.org/pypi/pwrentch.FileReferences product!

If you want to find what other items on a Plone site refer to (include a link to) a particular File or Image object, create an External Method called "reflist".

To invoke it, append "/reflist" to the URL of the File or Image object, e.g.

http://mysite.com/documents/somebig.pdf/reflist

It will return a list of clickable URLs for the objects (usually pages) linking to the current object.

The file system code goes into your Extensions folder.  Call it "reflist.py", with the following contents:

from Products.CMFCore.utils import getToolByName

def reflist(self):
    out = []
    reference_catalog = getToolByName(self, 'reference_catalog')
    references = reference_catalog.getBackReferences(self)
    out.append('<ul>')
    for ref in references:
        out.append('<li><a href="%s">%s</a></li>' % (ref.getSourceObject().absolute_url(), ref.getSourceObject().absolute_url() ))
    out.append('</ul>')
    return "\n".join(out)

Create the External Method in your portal_skins/custom folder, with:

  • ID "reflist"
  • module name "reflist"
  • function name "reflist"

 

Navigation