Permalink
Browse files

more fixes to simple language changer

  • Loading branch information...
2 parents 41c18d6 + 1a6d840 commit a5bbbd9d565980eeacb62a3b67b2ea9b4db4243c Jonas Obrist committed Oct 18, 2010
Showing with 13 additions and 5 deletions.
  1. +13 −5 menus/utils.py
View
@@ -189,17 +189,25 @@ def __init__(self, request):
@property
def app_path(self):
if self._app_path is None:
- self._app_path = self.request.path[len(self.get_page_path(self.request.LANGUAGE_CODE)):]
+ page_path = self.get_page_path(self.request.LANGUAGE_CODE)
+ if page_path:
+ self._app_path = self.request.path[len(page_path):]
+ else:
+ self._app_path = self.request.path
return self._app_path
def __call__(self, lang):
return '%s%s' % (self.get_page_path(lang), self.app_path)
def get_page_path(self, lang):
- try:
- return self.request.current_page.get_absolute_url(language=lang, fallback=False)
- except Title.DoesNotExist:
- return self.request.current_page.get_absolute_url(language=lang, fallback=True)
+ if getattr(self.request, 'current_page'):
+ try:
+ return self.request.current_page.get_absolute_url(language=lang, fallback=False)
+ except Title.DoesNotExist:
+ return self.request.current_page.get_absolute_url(language=lang, fallback=True)
+ return self.request.current_page.get_absolute_url(language=lang)
+ else:
+ return ''
def simple_language_changer(func):
def _wrapped(request, *args, **kwargs):

0 comments on commit a5bbbd9

Please sign in to comment.