Home Information - Your home, your data, organized.
Python
Added timezone attribute special forms/dropdown.
Anthony Cassandrae047b1599a7c
diff --git a/src/hi/apps/attribute/forms.py b/src/hi/apps/attribute/forms.pyindex 8f0be4e1..81244de6 100644--- a/src/hi/apps/attribute/forms.py+++ b/src/hi/apps/attribute/forms.py@@ -81,10 +81,10 @@ class AttributeForm( forms.ModelForm ):instance.is_editable = Trueinstance.is_required = False- if self.cleaned_data.get('secret'):- instance.value_type_str = str( AttributeValueType.SECRET )- else:- instance.value_type_str = str(AttributeValueType.TEXT)+ if self.cleaned_data.get('secret'):+ instance.value_type_str = str( AttributeValueType.SECRET )+ else:+ instance.value_type_str = str(AttributeValueType.TEXT)if commit:instance.save()diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form.htmlindex bbebd7fd..abd282f2 100644--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html@@ -14,9 +14,11 @@{% endif %}{% if attribute_form.instance.pk %}-+{% if attribute_form.instance.value_type.is_file %}{% include "attribute/panes/attribute_form_file.html" %}+ {% elif attribute_form.instance.value_type.is_timezone %}+ {% include "attribute/panes/attribute_form_timezone.html" %}{% else %}{% include "attribute/panes/attribute_form_text.html" %}{% endif %}diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_timezone.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_timezone.htmlnew file mode 100644index 00000000..8a80d84d--- /dev/null+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_timezone.html@@ -0,0 +1,21 @@+<input type="hidden" id="{{ attribute_form.name.id_for_label }}"+ name="{{ attribute_form.name.html_name }}"+ value="{{ attribute_form.instance.name }}" />+<div class="input-group" >+ <div class="input-group-prepend" >+ <span class="input-group-text" >{{ attribute_form.instance.name }}</span>+ </div>+ <select name="{{ attribute_form.value.html_name }}" id="{{ attribute_form.value.id_for_label }}">+ {% for tzname in TIMEZONE_NAME_LIST %}+ <option value="{{ tzname }}" {% if attribute_form.value.value == tzname %}selected="true"{% endif %}>+ {{ tzname }}+ </option>+ {% endfor %}+ </select>+</div>++{% if attribute_form.show_as_editable and attribute_form.instance.is_editable and attribute_form.instance.attribute_type.can_delete %}+<div class="">+ {{ attribute_form.DELETE }} Delete+</div>+{% endif %}diff --git a/src/hi/context_processors.py b/src/hi/context_processors.pyindex e435910a..cd48b3ef 100644--- a/src/hi/context_processors.py+++ b/src/hi/context_processors.py@@ -2,4 +2,34 @@ from .constants import DIVIDdef constants_context(request):- return { 'DIVID': DIVID }+ return {+ 'DIVID': DIVID,+ 'TIMEZONE_NAME_LIST': [+ 'UTC',+ 'America/New_York',+ 'America/Chicago',+ 'America/Denver',+ 'America/Los_Angeles',+ 'America/Toronto',+ 'America/Mexico_City',+ 'America/Sao_Paulo',+ 'Europe/London',+ 'Europe/Berlin',+ 'Europe/Paris',+ 'Europe/Moscow',+ 'Asia/Dubai',+ 'Asia/Tokyo',+ 'Asia/Seoul',+ 'Asia/Shanghai',+ 'Asia/Hong_Kong',+ 'Asia/Singapore',+ 'Asia/Kolkata',+ 'Asia/Jakarta',+ 'Australia/Sydney',+ 'Australia/Melbourne',+ 'Africa/Johannesburg',+ 'Africa/Lagos',+ 'Africa/Cairo',+ 'America/Argentina/Buenos_Aires',+ ],+ }diff --git a/src/hi/integrations/core/helpers.py b/src/hi/integrations/core/helpers.pyindex 1c7ce662..9c4bd5c8 100644--- a/src/hi/integrations/core/helpers.py+++ b/src/hi/integrations/core/helpers.py@@ -47,14 +47,19 @@ class IntegrationHelperMixin:"""new_attribute_types = set()- existing_attribute_names = set([ x.name for x in integration.attributes.all() ])+ existing_attribute_integration_keys = set([ x.integration_key+ for x in integration.attributes.all() ])AttributeType = integration_metadata.attribute_typefor attribute_type in AttributeType:- if attribute_type.label not in existing_attribute_names:+ integration_key = IntegrationKey(+ integration_id = integration.integration_id,+ integration_name = str(attribute_type),+ )+ if integration_key not in existing_attribute_integration_keys:new_attribute_types.add( attribute_type )continue-+if new_attribute_types:with transaction.atomic():for attribute_type in new_attribute_types:@@ -77,7 +82,7 @@ class IntegrationHelperMixin:name = attribute_type.label,value = attribute_type.value_type.initial_value,value_type_str = str(attribute_type.value_type),- integration_key = integration_key,+ integration_key_str = str(integration_key),attribute_type_str = AttributeType.PREDEFINED,is_editable = attribute_type.is_editable,is_required = attribute_type.is_required,diff --git a/src/hi/integrations/zoneminder/zm_manager.py b/src/hi/integrations/zoneminder/zm_manager.pyindex 51b95042..672a54b9 100644--- a/src/hi/integrations/zoneminder/zm_manager.py+++ b/src/hi/integrations/zoneminder/zm_manager.py@@ -271,13 +271,14 @@ class ZoneMinderManager( Singleton ):def get_zm_tzname(self) -> str:try:zm_integration = Integration.objects.get( integration_id = ZmMetaData.integration_id )- integration_attribute = IntegrationAttribute.objects.get(+ integration_attribute = IntegrationAttribute.objects.filter(integration = zm_integration,name = ZmAttributeType.TIMEZONE.label,- )- return integration_attribute.value- except Integration.DoesNotExist:+ ).first()+ if integration_attribute:+ return integration_attribute.valuelogger.error( 'ZoneMinder integration is not implemented.' )+except IntegrationAttribute.DoesNotExist:logger.error( 'ZoneMinder timezone not found.' )diff --git a/src/hi/middleware.py b/src/hi/middleware.pyindex 79056079..fa2fee3b 100644--- a/src/hi/middleware.py+++ b/src/hi/middleware.py@@ -85,7 +85,7 @@ class ExceptionMiddleware(object):if isinstance(response, HttpResponseNotAllowed):return views.method_not_allowed_response(request)if isinstance(response, HttpResponseServerError):- logger.warning( f'Internal error in middleware' )+ logger.warning( 'Internal error in middleware' )return views.internal_error_response(request)return response