CurrentSection.py 783 Bytes
Newer Older
Jean-Paul Smets's avatar
Jean-Paul Smets committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
## Script (Python) "change_language"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=Modify the language cookie
##

request = context.REQUEST
PARENTS = request.PARENTS
portal_root = context.portal_url.getPortalObject()
portal_root_path = portal_root.getPhysicalPath()
lang_list = context.gettext.get_available_languages()

if len(PARENTS) >= (1 + len(portal_root_path)):
  section = PARENTS[len(PARENTS) - 1
         - len(portal_root.getPhysicalPath())]
  if section.id in lang_list:
    if len(PARENTS) >= (2 + len(portal_root_path)):
      section = PARENTS[len(PARENTS) - 2
         - len(portal_root_path)]
    else:
      section = context
else:
  section = context

return section