Permalink
Browse files

silenced all exceptions in the get_translated_value template tag if n…

…ot in TEMPLATE_DEBUG mode

thanks @sn-devdev for the tip!

closes #7
  • Loading branch information...
1 parent d5a12b4 commit d3e0f8d047a5696d1b7158c6d4b5f62e9713eacd @beniwohli committed Aug 2, 2011
Showing with 21 additions and 16 deletions.
  1. +21 −16 cms_search/search_helpers/templatetags/cms_search_tags.py
@@ -33,22 +33,27 @@ def get_value(self, context, obj, field_name):
the languages defined in `settings.LANGUAGES`.
"""
- language = get_language()
- value = self.get_translated_value(obj, field_name, language)
- if value:
- return value
- if self.FALLBACK:
- for lang, lang_name in settings.LANGUAGES:
- if lang == language:
- # already tried this one...
- continue
- value = self.get_translated_value(obj, field_name, lang)
- if value:
- return value
- untranslated = getattr(obj, field_name)
- if self._is_truthy(untranslated):
- return untranslated
- else:
+ try:
+ language = get_language()
+ value = self.get_translated_value(obj, field_name, language)
+ if value:
+ return value
+ if self.FALLBACK:
+ for lang, lang_name in settings.LANGUAGES:
+ if lang == language:
+ # already tried this one...
+ continue
+ value = self.get_translated_value(obj, field_name, lang)
+ if value:
+ return value
+ untranslated = getattr(obj, field_name)
+ if self._is_truthy(untranslated):
+ return untranslated
+ else:
+ return self.EMPTY_VALUE
+ except Exception:
+ if settings.TEMPLATE_DEBUG:
+ raise
return self.EMPTY_VALUE
def get_translated_value(self, obj, field_name, language):

0 comments on commit d3e0f8d

Please sign in to comment.