Posted By

wsfulmer on 06/30/06


Tagged

python plone archetypes linguaplone


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

wsfulmer
idiotkings
anayhk


Bi-directional references with translations


 / Published in: Python
 

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.

  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  

You need to login to post a comment.