getLocalizedPath.py 1.18 KB
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43
## Script (Python) "transformation_identity_update"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=lang
##title=
##

from ZTUtils import make_query

request = context.REQUEST
query = make_query(request.form)

# Try to get the id of the DTML method / PT / etc.
method_id = request.URL0[len(request.URL1):]
my_id = context.id
if callable(my_id): my_id = my_id()
if '/' + my_id == method_id:
  method_id = ''
relative_url = context.portal_url.getRelativeUrl(context)

# Chop useless language information
for l in context.gettext.get_available_languages():
  if relative_url[0:len(l) + 1] == l + '/':
    relative_url = relative_url[len(l) + 1:]

# Chop useless /
if relative_url == '':
  if len(method_id) > 0:
    if method_id[0] == '/':
      method_id = method_id[1:]

# Build the new URL
if query == '':
  return '%s/%s/%s%s' % (context.portal_url.getPortalObject().absolute_url(), lang,
                     relative_url,
                     method_id)
else:
  return '%s/%s/%s%s?%s' % (context.portal_url.getPortalObject().absolute_url(), lang,
                     relative_url,
                     method_id, query)