예제 #1
0
    def _get_parameter_value(self, detail):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        data = sysparam.get(detail.key, detail.type, self.store)
        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % detail.key)
            return data.get_description()
        elif detail.options:
            return detail.options[int(data)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif isinstance(data, decimal.Decimal):
            return quantize(data)
        elif detail.key == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, unicode):
            # FIXME: workaround to handle locale specific data
            return _(data)

        if data is None:
            return ''
        return unicode(data)
예제 #2
0
    def _get_parameter_value(self, detail):
        """Given a ParameterData object, returns a string representation of
        its current value.
        """
        data = sysparam.get(detail.key, detail.type, self.store)
        if isinstance(data, Domain):
            if not (IDescribable in providedBy(data)):
                raise TypeError(u"Parameter `%s' must implement IDescribable "
                                "interface." % detail.key)
            return data.get_description()
        elif detail.options:
            return detail.options[int(data)]
        elif isinstance(data, bool):
            return [_(u"No"), _(u"Yes")][data]
        elif isinstance(data, decimal.Decimal):
            return quantize(data)
        elif detail.key == u'COUNTRY_SUGGESTED':
            return dgettext("iso_3166", data)
        elif isinstance(data, str):
            # FIXME: workaround to handle locale specific data
            return _(data)

        if data is None:
            return ''
        return str(data)
예제 #3
0
 def _get_model(self, store, detail):
     model = store.find(ParameterData, field_name=detail.key).one()
     if not model:
         value = sysparam.get(detail.key)
         if detail.type is bool:
             value = int(value)
         if value is not None:
             value = unicode(value)
         model = ParameterData(store=store,
                               field_name=detail.key,
                               field_value=value)
     return model
예제 #4
0
 def _get_model(self, store, detail):
     model = store.find(ParameterData, field_name=detail.key).one()
     if not model:
         value = sysparam.get(detail.key)
         if detail.type is bool:
             value = int(value)
         if value is not None:
             value = unicode(value)
         model = ParameterData(store=store,
                               field_name=detail.key,
                               field_value=value)
     return model