diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 53116a5c..1211825b 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -619,7 +619,8 @@ class BenchmarkDataStorage(Benchmark): write_speed = Column(Float(decimal_return_scale=2), nullable=False) def __str__(self) -> str: - return 'Read: {} MB/s, write: {} MB/s'.format(self.read_speed, self.write_speed) + return 'Read: {0:.2f} MB/s, write: {0:.2f} MB/s'.format( + self.read_speed, self.write_speed) class BenchmarkWithRate(Benchmark): @@ -628,7 +629,7 @@ class BenchmarkWithRate(Benchmark): rate = Column(Float, nullable=False) def __str__(self) -> str: - return '{} points'.format(self.rate) + return '{0:.2f} points'.format(self.rate) class BenchmarkProcessor(BenchmarkWithRate): @@ -1022,7 +1023,10 @@ class Rate(JoinedWithOneDeviceMixin, ActionWithOneDevice): return args def __str__(self) -> str: - return '{} (v.{})'.format(self.rating_range, self.version) + if self.version: + return '{} (v.{})'.format(self.rating_range, self.version) + + return '{}'.format(self.rating_range) @classmethod def compute(cls, device) -> 'RateComputer': diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index a9efc105..215fcfb3 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -194,6 +194,33 @@ class Device(Thing): if isinstance(c, ColumnProperty) and not getattr(c, 'foreign_keys', None) and c.key not in self._NON_PHYSICAL_PROPS} + + @property + def public_properties(self) -> Dict[str, object or None]: + """Fields that describe the properties of a device than next show + in the public page. + + :return A dictionary: + - Column. + - Actual value of the column or None. + """ + non_public = ['amount', 'transfer_state', 'receiver_id'] + hide_properties = list(self._NON_PHYSICAL_PROPS) + non_public + return {c.key: getattr(self, c.key, None) + for c in inspect(self.__class__).attrs + if isinstance(c, ColumnProperty) + and not getattr(c, 'foreign_keys', None) + and c.key not in hide_properties} + + @property + def public_actions(self) -> List[object]: + """Actions than we want show in public page as traceability log section + :return a list of actions: + """ + hide_actions = ['Price'] + actions = [ac for ac in self.actions if not ac.t in hide_actions] + actions.reverse() + return actions @property def url(self) -> urlutils.URL: diff --git a/ereuse_devicehub/resources/device/templates/devices/layout.html b/ereuse_devicehub/resources/device/templates/devices/layout.html index eb672c91..de46ecf3 100644 --- a/ereuse_devicehub/resources/device/templates/devices/layout.html +++ b/ereuse_devicehub/resources/device/templates/devices/layout.html @@ -51,8 +51,8 @@