def getLocalAttribute(self, id, lang=None):
     """Returns a local property"""
     if id not in self._local_properties:
         return ""
     # No language, look for the first non-empty available version or def.
     if lang is None:
         request = get_request()
         i18n = get_i18n_context()
         if i18n is None:  # didn't traverse any portal yet, e.g. zmi root
             lang = "en"
         else:
             neg = NyNegotiator(request=request, cookie_id=i18n["cookie_id"])
             # need to negotiate lang based on available langs for this prop.
             lang = neg.getLanguage(self._local_properties[id].keys(), fallback=False)
         if lang is None:
             # eg: we ask default (en), id has only 'de', lang is then None
             # because fallback=False (or else it would have been `de`)
             lang = i18n["default_language"]
     if lang not in self._local_properties[id]:
         return ""
     value = self._local_properties[id][lang]
     if isinstance(value, tuple):  # (value, timestamp)
         return value[0]
     else:
         return value
 def get_negotiator(self):
     """ Return NyNegotiator instance, based on current request """
     try:
         return NyNegotiator(request=self.getSite().REQUEST)
     except AttributeError:
         # maybe debug/testing environment?
         return NyNegotiator()
 def getLocalAttribute(self, id, lang=None):
     """Returns a local property"""
     if id not in self._local_properties:
         return ''
     # No language, look for the first non-empty available version or def.
     if lang is None:
         request = get_request()
         i18n = get_i18n_context()
         if i18n is None: # didn't traverse any portal yet, e.g. zmi root
             lang = 'en'
         else:
             neg = NyNegotiator(request=request, cookie_id=i18n['cookie_id'])
             # need to negotiate lang based on available langs for this prop.
             lang = neg.getLanguage(self._local_properties[id].keys(),
                                    fallback=False)
         if lang is None:
             # eg: we ask default (en), id has only 'de', lang is then None
             # because fallback=False (or else it would have been `de`)
             lang = i18n['default_language']
     if lang not in self._local_properties[id]:
         return ''
     value = self._local_properties[id][lang]
     if isinstance(value, tuple): # (value, timestamp)
         return value[0]
     else:
         return value
示例#4
0
    def getLocalAttribute(self, id, lang=None, langFallback=False):
        """Returns a local property
        Note that langFallback is fallback to the bitter end - it will both try
        to find a non default language present and yet other languages
        if the one it found had empty values."""
        if id not in self._local_properties:
            return ''
        # No language, look for the first non-empty available version or def.
        if lang is None:
            request = get_request()
            i18n = get_i18n_context()
            if i18n is None:  # didn't traverse any portal yet, e.g. zmi root
                lang = 'en'
            else:
                neg = NyNegotiator()
                # need to negotiate lang based on available langs for this prop.
                lang = neg.getLanguage(self._local_properties[id].keys(),
                                       request,
                                       fallback=langFallback)
            if lang is None:
                # eg: we ask default (en), id has only 'de', lang is then None
                # because fallback=False (or else it would have been `de`)
                if i18n['default_language'] in self._local_properties[id]:
                    lang = i18n['default_language']
                else:
                    lang = 'en'

        if lang not in self._local_properties[id]:
            return ''

        value = self._getValue(id, lang)
        # perhaps we found a non default language but the values there are empty
        # TODO: do we really want such aggressive behaviour?
        # what if the client wants empty value for some languages?
        if langFallback and not value:
            for ln in self._local_properties[id]:
                value = self._getValue(id, ln)
                if value:
                    break
        return value
    def getLocalAttribute(self, id, lang=None, langFallback=False):
        """Returns a local property
        Note that langFallback is fallback to the bitter end - it will both try
        to find a non default language present and yet other languages
        if the one it found had empty values."""
        if id not in self._local_properties:
            return ''
        # No language, look for the first non-empty available version or def.
        if lang is None:
            request = get_request()
            i18n = get_i18n_context()
            if i18n is None: # didn't traverse any portal yet, e.g. zmi root
                lang = 'en'
            else:
                neg = NyNegotiator()
                # need to negotiate lang based on available langs for this prop.
                lang = neg.getLanguage(self._local_properties[id].keys(),
                                       request, fallback=langFallback)
            if lang is None:
                # eg: we ask default (en), id has only 'de', lang is then None
                # because fallback=False (or else it would have been `de`)
                if i18n['default_language'] in self._local_properties[id]:
                    lang = i18n['default_language']
                else:
                    lang = 'en'

        if lang not in self._local_properties[id]:
            return ''

        value = self._getValue(id, lang)
        # perhaps we found a non default language but the values there are empty
        # TODO: do we really want such aggressive behaviour?
        # what if the client wants empty value for some languages?
        if langFallback and not value:
            for ln in self._local_properties[id]:
                value = self._getValue(id, ln)
                if value:
                    break
        return value
示例#6
0
 def get_negotiator(self):
     """ Return NyNegotiator instance, based on current request """
     return NyNegotiator()