def formatted_value(self): """ Get a human-consumable value for the attribute. The current locale is used for formatting. :return: Textual value :rtype: str """ try: if self.attribute.type == AttributeType.BOOLEAN: return yesno(self.value) if self.attribute.type in (AttributeType.INTEGER, AttributeType.DECIMAL): return format_number(self.value) if self.attribute.type == AttributeType.TIMEDELTA: a = now() b = a + self.value return timesince(a, b) if self.attribute.type in (AttributeType.DATETIME, AttributeType.DATE): return format_datetime(self.value) except: # If formatting fails, fall back to string formatting. pass return six.text_type(self.value)