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)
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)
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