Bi-directional references with translations


/ Published in: Python
Save to your folder(s)

This is a general purpose Zope script for your Plone product or Plone custom skin folder. It provides LinugaPlone translation of references, either incoming, outgoing, or both.


Copy this code and paste it in your HTML
  1. ## Script (Python) "getTranslatedRefs"
  2. ##title=Gets translated refs, backrefs, or both for a given relationship.
  3. ##bind container=container
  4. ##bind context=context
  5. ##bind namespace=
  6. ##bind script=script
  7. ##bind subpath=traverse_subpath
  8. ##parameters=rel,which,sort_on=None,sort_type=None,sort_order=None
  9.  
  10. if which == "refs":
  11. refs = context.getCanonical().getRefs(relationship=rel)
  12. elif which == "brefs":
  13. refs = context.getCanonical().getBRefs(relationship=rel)
  14. elif which == "all":
  15. refs = context.getCanonical().getRefs(relationship=rel) + \
  16. context.getCanonical().getBRefs(relationship=rel)
  17. else:
  18. raise "Invalid 'which' parameter %s - must be 'refs','brefs' or 'all'."
  19.  
  20.  
  21. unique = []
  22. for b in refs:
  23. canonical = b.getCanonical()
  24. if canonical not in unique:
  25. unique.append(canonical)
  26. translated = [i.getTranslation(context.getLanguage()) or i for i in unique]
  27. if sort_on:
  28. results = sequence.sort(translated,((sort_on, sort_type, sort_order),))
  29. else:
  30. results = translated
  31.  
  32. return results

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.