Skip to content

Home Information - Your home, your data, organized.

Python

Completed first pass of major attribute editing features.

Anthony Cassandraf17f5998fbef
diff --git a/src/hi/apps/attribute/forms.py b/src/hi/apps/attribute/forms.py
index 3a7a031f..fe1f4c88 100644
--- a/src/hi/apps/attribute/forms.py
+++ b/src/hi/apps/attribute/forms.py
@@ -51,14 +51,17 @@ class AttributeForm( forms.ModelForm ):
def clean(self):
cleaned_data = super().clean()
-
- form_is_bound = bool( self.instance.pk )
- if form_is_bound and not self.instance.is_editable:
- raise ValidationError( 'This attribute is not editable.' )
-
name = cleaned_data.get('name')
value = cleaned_data.get('value')
+ form_is_bound = bool( self.instance.pk )
+ if form_is_bound:
+ if not self.instance.is_editable:
+ raise ValidationError( f'The attribute "{self.instance.name}" is not editable.' )
+ if ( self.instance.attribute_type == AttributeType.PREDEFINED
+ and ( name != self.instance.name )):
+ raise ValidationError( 'Changing name forbidden for predefined attributes.' )
+
if is_blank( name ):
self.add_error( 'name', 'A name is required' )
diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html
index 9b6ffb70..bbebd7fd 100644
--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html
+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form.html
@@ -24,6 +24,7 @@
{% else %}
{% include "attribute/panes/attribute_form_new.html" %}
{% endif %}
+
</div>
{% endfor %}
</div>
diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_field_value.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_field_value.html
new file mode 100644
index 00000000..67dbed47
--- /dev/null
+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_field_value.html
@@ -0,0 +1,7 @@
+<div>
+ <textarea rows="1" cols="40"
+ id="{{ attribute_form.value.id_for_label }}"
+ name="{{ attribute_form.value.html_name }}">{{ attribute_form.value.value|default_if_none:'' }}</textarea>
+</div>
+<div class="form-error text-danger" >{{ attribute_form.value.errors }}</div>
+<script type="text/javascript">autosize($('#{{ attribute_form.value.id_for_label }}'));</script>
diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_file.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_file.html
index ad95949a..5ad751b5 100644
--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_file.html
+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_file.html
@@ -9,11 +9,7 @@
{{ attribute_form.instance.name }}
</a>
</div>
-
- <textarea rows="2" cols="40"
- id="{{ attribute_form.value.id_for_label }}"
- name="{{ attribute_form.value.html_name }}">{{ attribute_form.value.value|default_if_none:'' }}</textarea>
- <div class="form-error text-danger" >{{ attribute_form.value.errors }}</div>
+ {% include "attribute/panes/attribute_form_field_value.html" %}
{% if attribute_form.show_as_editable and attribute_form.instance.is_editable %}
<div class="">
diff --git a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_text.html b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_text.html
index d1f44e37..62d610e2 100644
--- a/src/hi/apps/attribute/templates/attribute/panes/attribute_form_text.html
+++ b/src/hi/apps/attribute/templates/attribute/panes/attribute_form_text.html
@@ -16,13 +16,9 @@
onclick="Hi.togglePasswordField( this );">
<label for="{{ attribute_form.value.id_for_label }}-show">Show</label>
</span>
- {% else %}
- <textarea rows="2" cols="40"
- id="{{ attribute_form.value.id_for_label }}"
- name="{{ attribute_form.value.html_name }}"
- >{{ attribute_form.value.value|default_if_none:'' }}</textarea>
+ {% else %}
+ {% include "attribute/panes/attribute_form_field_value.html" %}
{% endif %}
- <div class="form-error text-danger" >{{ attribute_form.value.errors }}</div>
</div>
{% if attribute_form.show_as_editable and attribute_form.instance.is_editable %}
diff --git a/src/hi/apps/location/templates/location/edit/panes/location_item_position_form.html b/src/hi/apps/location/templates/location/edit/panes/location_item_position_form.html
index 87940973..fcd7fc39 100644
--- a/src/hi/apps/location/templates/location/edit/panes/location_item_position_form.html
+++ b/src/hi/apps/location/templates/location/edit/panes/location_item_position_form.html
@@ -3,7 +3,7 @@
{% endfor %}
{% if location_item_position_form.non_field_errors %}
-<div class="non-field-errors alert alert-danger">
+<div class="non-field-errors">
{% for err in location_item_position_form.non_field_errors %}
<p class="form-error">{{ err }}</p>
{% endfor %}
diff --git a/src/hi/integrations/core/forms.py b/src/hi/integrations/core/forms.py
index 6677cfb2..b8fcae12 100644
--- a/src/hi/integrations/core/forms.py
+++ b/src/hi/integrations/core/forms.py
@@ -6,12 +6,8 @@ from .models import Integration, IntegrationAttribute
class IntegrationAttributeForm( AttributeForm ):
-
- class Meta:
+ class Meta( AttributeForm.Meta ):
model = IntegrationAttribute
- fields = (
- 'value',
- )
IntegrationAttributeFormSet = forms.inlineformset_factory(
diff --git a/src/hi/integrations/hass/views.py b/src/hi/integrations/hass/views.py
index f100895f..74c3f8d9 100644
--- a/src/hi/integrations/hass/views.py
+++ b/src/hi/integrations/hass/views.py
@@ -134,7 +134,7 @@ class HassSettingsView( View, IntegrationHelperMixin ):
context = {
'integration_attribute_formset': integration_attribute_formset,
}
- template = get_template( 'hass/panes/hass_setings.html' )
+ template = get_template( 'hass/panes/hass_settings.html' )
content = template.render( context, request = request )
return antinode.response(
insert_map = {
diff --git a/src/hi/integrations/zoneminder/views.py b/src/hi/integrations/zoneminder/views.py
index 1c66cc08..8b4e0b29 100644
--- a/src/hi/integrations/zoneminder/views.py
+++ b/src/hi/integrations/zoneminder/views.py
@@ -134,7 +134,7 @@ class ZmSettingsView( View, IntegrationHelperMixin ):
context = {
'integration_attribute_formset': integration_attribute_formset,
}
- template = get_template( 'zoneminder/panes/zm_setings.html' )
+ template = get_template( 'zoneminder/panes/zm_settings.html' )
content = template.render( context, request = request )
return antinode.response(
insert_map = {
diff --git a/src/hi/settings/base.py b/src/hi/settings/base.py
index 8a4643ff..f6e7f23b 100644
--- a/src/hi/settings/base.py
+++ b/src/hi/settings/base.py
@@ -267,6 +267,7 @@ PIPELINE = {
'source_filenames': (
'js/jquery-3.7.0.min.js',
'js/antinode.js',
+ 'js/autosize.min.js',
),
'output_filename': 'js/js_before_content.js',
},
diff --git a/src/hi/static/js/autosize.min.js b/src/hi/static/js/autosize.min.js
new file mode 100644
index 00000000..d9c6490a
--- /dev/null
+++ b/src/hi/static/js/autosize.min.js
@@ -0,0 +1 @@
+!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e||self).autosize=t()}(this,function(){var e,t,n="function"==typeof Map?new Map:(e=[],t=[],{has:function(t){return e.indexOf(t)>-1},get:function(n){return t[e.indexOf(n)]},set:function(n,o){-1===e.indexOf(n)&&(e.push(n),t.push(o))},delete:function(n){var o=e.indexOf(n);o>-1&&(e.splice(o,1),t.splice(o,1))}}),o=function(e){return new Event(e,{bubbles:!0})};try{new Event("test")}catch(e){o=function(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!1),t}}function r(e){var t=n.get(e);t&&t.destroy()}function i(e){var t=n.get(e);t&&t.update()}var l=null;return"undefined"==typeof window||"function"!=typeof window.getComputedStyle?((l=function(e){return e}).destroy=function(e){return e},l.update=function(e){return e}):((l=function(e,t){return e&&Array.prototype.forEach.call(e.length?e:[e],function(e){return function(e){if(e&&e.nodeName&&"TEXTAREA"===e.nodeName&&!n.has(e)){var t,r=null,i=null,l=null,a=function(){e.clientWidth!==i&&f()},d=function(t){window.removeEventListener("resize",a,!1),e.removeEventListener("input",f,!1),e.removeEventListener("keyup",f,!1),e.removeEventListener("autosize:destroy",d,!1),e.removeEventListener("autosize:update",f,!1),Object.keys(t).forEach(function(n){e.style[n]=t[n]}),n.delete(e)}.bind(e,{height:e.style.height,resize:e.style.resize,overflowY:e.style.overflowY,overflowX:e.style.overflowX,wordWrap:e.style.wordWrap});e.addEventListener("autosize:destroy",d,!1),"onpropertychange"in e&&"oninput"in e&&e.addEventListener("keyup",f,!1),window.addEventListener("resize",a,!1),e.addEventListener("input",f,!1),e.addEventListener("autosize:update",f,!1),e.style.overflowX="hidden",e.style.wordWrap="break-word",n.set(e,{destroy:d,update:f}),"vertical"===(t=window.getComputedStyle(e,null)).resize?e.style.resize="none":"both"===t.resize&&(e.style.resize="horizontal"),r="content-box"===t.boxSizing?-(parseFloat(t.paddingTop)+parseFloat(t.paddingBottom)):parseFloat(t.borderTopWidth)+parseFloat(t.borderBottomWidth),isNaN(r)&&(r=0),f()}function s(t){var n=e.style.width;e.style.width="0px",e.style.width=n,e.style.overflowY=t}function u(){if(0!==e.scrollHeight){var t=function(e){for(var t=[];e&&e.parentNode&&e.parentNode instanceof Element;)e.parentNode.scrollTop&&(e.parentNode.style.scrollBehavior="auto",t.push([e.parentNode,e.parentNode.scrollTop])),e=e.parentNode;return function(){return t.forEach(function(e){var t=e[0];t.scrollTop=e[1],t.style.scrollBehavior=null})}}(e);e.style.height="",e.style.height=e.scrollHeight+r+"px",i=e.clientWidth,t()}}function f(){u();var t=Math.round(parseFloat(e.style.height)),n=window.getComputedStyle(e,null),r="content-box"===n.boxSizing?Math.round(parseFloat(n.height)):e.offsetHeight;if(r<t?"hidden"===n.overflowY&&(s("scroll"),u(),r="content-box"===n.boxSizing?Math.round(parseFloat(window.getComputedStyle(e,null).height)):e.offsetHeight):"hidden"!==n.overflowY&&(s("hidden"),u(),r="content-box"===n.boxSizing?Math.round(parseFloat(window.getComputedStyle(e,null).height)):e.offsetHeight),l!==r){l=r;var i=o("autosize:resized");try{e.dispatchEvent(i)}catch(e){}}}}(e)}),e}).destroy=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],r),e},l.update=function(e){return e&&Array.prototype.forEach.call(e.length?e:[e],i),e}),l});
diff --git a/src/hi/static/js/main.js b/src/hi/static/js/main.js
index f7b7281c..ca3262be 100644
--- a/src/hi/static/js/main.js
+++ b/src/hi/static/js/main.js
@@ -65,6 +65,14 @@
window.Hi = Hi;
+
+ $(document).ready(function() {
+ $(document).on('mousedown', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
+ if ( ! Hi.isEditMode ) { return; }
+ handleMouseDown( event );
+ });
+ });
+
function _generateUniqueId() {
return 'id-' + Date.now() + '-' + Math.floor(Math.random() * 1000);
}