Home Information - Your home, your data, organized.
Python
Feature/139 Show Settings Descriptions (#256)
Thiago Trautwein Santos67c09386f8df
diff --git a/src/hi/apps/attribute/models.py b/src/hi/apps/attribute/models.pyindex 81b1aaea..9c6bf1f5 100644--- a/src/hi/apps/attribute/models.py+++ b/src/hi/apps/attribute/models.py@@ -90,6 +90,10 @@ class AttributeModel(models.Model):def get_attribute_default_value(self):return None+ @property+ def display_description( self ):+ return None+def __str__(self):return f'Attr: {self.name}={self.value} [{self.value_type_str}] [{self.attribute_type_str}]'diff --git a/src/hi/apps/attribute/templates/attribute/components/regular_attribute_card.html b/src/hi/apps/attribute/templates/attribute/components/regular_attribute_card.htmlindex e9705dd1..c89b7e72 100644--- a/src/hi/apps/attribute/templates/attribute/components/regular_attribute_card.html+++ b/src/hi/apps/attribute/templates/attribute/components/regular_attribute_card.html@@ -39,7 +39,12 @@ Individual attribute attribute card with value editing and actions<div class="{{ DIVID.ATTR_V2_ATTRIBUTE_HEADER_CLASS }}">{% if attribute_form.instance.pk %}<div class="{{ DIVID.ATTR_V2_ATTRIBUTE_NAME_CLASS }}">- {% include "attribute/components/name_field.html" %}+ <div class="d-flex flex-column align-items-start w-100">+ {% include "attribute/components/name_field.html" %}+ {% if attribute_form.instance.display_description %}+ <div class="text-muted small mt-1">{{ attribute_form.instance.display_description|safe }}</div>+ {% endif %}+ </div></div>{% if attribute_form.name.errors %}diff --git a/src/hi/apps/config/models.py b/src/hi/apps/config/models.pyindex 3389c623..d446120f 100644--- a/src/hi/apps/config/models.py+++ b/src/hi/apps/config/models.py@@ -64,6 +64,14 @@ class SubsystemAttribute( AttributeModel ):return enum.definition.initial_valueexcept (ValueError, ImportError, AttributeError, TypeError):return None++ @property+ def display_description( self ):+ try:+ enum = SettingEnum.from_key( self.setting_key )+ return enum.definition.description or ''+ except (ValueError, ImportError, AttributeError, TypeError):+ return ''class SubsystemAttributeHistory(AttributeValueHistoryModel):diff --git a/src/hi/apps/config/tests/test_views.py b/src/hi/apps/config/tests/test_views.pyindex 5069761f..31eb1c95 100644--- a/src/hi/apps/config/tests/test_views.py+++ b/src/hi/apps/config/tests/test_views.py@@ -234,6 +234,27 @@ class TestConfigSettingsView(DualModeViewTestCase):self.assertIn(f'data-default-value="{expected_default}"', content)self.assertIn(f"Hi.attr.restoreDefaultValue('{attribute.id}')", content)+ def test_setting_description_is_rendered(self):+ """Config settings page should show SettingDefinition descriptions."""+ SubsystemAttribute.objects.create(+ subsystem=self.subsystem,+ setting_key=SecuritySetting.SECURITY_NIGHT_START.key,+ name='Security Night Start',+ value='23:00',+ value_type_str=str(AttributeValueType.ENUM),+ attribute_type_str=str(AttributeType.PREDEFINED),+ )++ url = reverse('config_settings', kwargs={'subsystem_id': self.subsystem.id})+ response = self.client.get(url)++ self.assertSuccessResponse(response)+ self.assertHtmlResponse(response)++ content = response.content.decode('utf-8')+ expected_description = SecuritySetting.SECURITY_NIGHT_START.definition.description+ self.assertIn(expected_description, content)+def test_restore_subsystem_confirm_modal(self):"""Subsystem reset confirmation is rendered by a server modal view."""url = reverse(