Home Information - Your home, your data, organized.
Python
Fixed content id around SVG position form.
Anthony Cassandra0559dacb3edc
diff --git a/src/hi/apps/edit/templates/edit/panes/collection.html b/src/hi/apps/edit/templates/edit/panes/collection.htmlindex f8ce2c06..702d8c3e 100644--- a/src/hi/apps/edit/templates/edit/panes/collection.html+++ b/src/hi/apps/edit/templates/edit/panes/collection.html@@ -1,9 +1,11 @@<h4>{{ collection.name }}</h4><h5>Position</h5>-<div id="hi-edit-svg-position">- {% include "edit/panes/svg_position.html" with html_id=collection.html_id svg_position_form=svg_position_form %}+{% with collection.html_id as html_id %}+<div id="{{ svg_position_form.content_html_id }}">+ {% include "edit/panes/svg_position.html" %}</div>+{% endwith %}<h5>Views</h5><div id="hi-edit-collection-views">diff --git a/src/hi/apps/edit/templates/edit/panes/entity.html b/src/hi/apps/edit/templates/edit/panes/entity.htmlindex fd2502b1..870b6b28 100644--- a/src/hi/apps/edit/templates/edit/panes/entity.html+++ b/src/hi/apps/edit/templates/edit/panes/entity.html@@ -1,9 +1,11 @@<h4>{{ entity.name }}</h4><h5>Position</h5>-<div id="hi-edit-svg-position">- {% include "edit/panes/svg_position.html" with html_id=entity.html_id svg_position_form=svg_position_form %}+{% with entity.html_id as html_id %}+<div id="{{ svg_position_form.content_html_id }}">+ {% include "edit/panes/svg_position.html" %}</div>+{% endwith %}<h5>Attributes</h5><div id="hi-edit-entity-attributes">diff --git a/src/hi/apps/edit/templates/edit/panes/svg_position.html b/src/hi/apps/edit/templates/edit/panes/svg_position.htmlindex 75eafdc4..a1ae0526 100644--- a/src/hi/apps/edit/templates/edit/panes/svg_position.html+++ b/src/hi/apps/edit/templates/edit/panes/svg_position.html@@ -1,9 +1,5 @@-{% if not svg_position_form.instance %}-<div><em>Not positioned.</em></div>-{% endif %}--<form action="{% url 'edit_svg_position' html_id=html_id %}" method="post"- class="form" data-async="#hi-edit-svg-position">+<form action="{% url 'edit_svg_position' html_id=svg_position_form.item_html_id %}" method="post"+ class="form" data-async="#{{ svg_position_form.content_html_id }}-svg-position">{% csrf_token %}{% for hidden in svg_position_form.hidden_fields %}diff --git a/src/hi/apps/edit/views.py b/src/hi/apps/edit/views.pyindex 583fc253..f49466a2 100644--- a/src/hi/apps/edit/views.py+++ b/src/hi/apps/edit/views.py@@ -141,21 +141,23 @@ class EditSvgPositionView( View, EditViewMixin ):else:raise NotImplementedError( 'Not yet handling unknown edit detail type.' )- svg_position_form = SvgPositionForm( request.POST )+ svg_position_form = SvgPositionForm(+ request.POST,+ item_html_id = svg_position_model.svg_item.html_id,+ )if svg_position_form.is_valid():svg_position_form.to_svg_position_model( svg_position_model )svg_position_model.save()svg_position_item = svg_position_model.svg_itemcontext = {- 'html_id': svg_position_item.html_id,'svg_position_form': svg_position_form,}template = get_template('edit/panes/svg_position.html')content = template.render( context, request = request )insert_map = {- DIVID['EDIT_SVG_POSITION']: content,+ svg_position_form.content_html_id: content,}set_attributes_map = {svg_position_item.html_id: {diff --git a/src/hi/apps/location/forms.py b/src/hi/apps/location/forms.pyindex 73275575..eb6c17b2 100644--- a/src/hi/apps/location/forms.py+++ b/src/hi/apps/location/forms.py@@ -23,11 +23,25 @@ class SvgPositionForm(forms.Form):label = 'Angle',required = True,)-++ def __init__( self, *args, item_html_id = None, **kwargs ):+ super(SvgPositionForm, self).__init__(*args, **kwargs)+ self._item_html_id = item_html_id+ return++ @property+ def item_html_id(self):+ return self._item_html_id++ @property+ def content_html_id(self):+ return f'{self.item_html_id}-svg-position'+@classmethoddef from_svg_position_model( cls, svg_position_model : SvgPositionModel ):if svg_position_model:return cls(+ item_html_id = svg_position_model.svg_item.html_id,initial = {'svg_x': svg_position_model.svg_x,'svg_y': svg_position_model.svg_y,@@ -36,6 +50,7 @@ class SvgPositionForm(forms.Form):},)return cls(+ item_html_id = svg_position_model.svg_item.html_id,initial = {'svg_scale': Decimal( 1.0 ),'svg_rotate': Decimal( 0.0 ),diff --git a/src/hi/constants.py b/src/hi/constants.pyindex 1fb4f1cf..71e4b9f1 100644--- a/src/hi/constants.py+++ b/src/hi/constants.py@@ -15,11 +15,9 @@ DIVID = {'EDIT_SIDE': 'hi-edit-side-content','EDIT_ENTITY': 'hi-edit-entity','EDIT_COLLECTION': 'hi-edit-collection',- 'EDIT_SVG_POSITION': 'hi-edit-svg-position','EDIT_ENTITY_VIEWS': 'hi-edit-entity-views','EDIT_ENTITY_ATTRIBUTES': 'hi-edit-entity-attributes','EDIT_ENTITY_SENSORS': 'hi-edit-entity-sensors','EDIT_ENTITY_CONTROLLERS': 'hi-edit-entity-controllers',--+}