Skip to content

Home Information - Your home, your data, organized.

Python

Round trip on SVG icon drag movement to DB and back to JS. WIP

Anthony Cassandra2f923e4d007a
diff --git a/src/hi/apps/edit/views.py b/src/hi/apps/edit/views.py
index 970d3bd7..583fc253 100644
--- a/src/hi/apps/edit/views.py
+++ b/src/hi/apps/edit/views.py
@@ -124,7 +124,7 @@ class EditSvgPositionView( View, EditViewMixin ):
def post(self, request, *args, **kwargs):
if request.view_parameters.edit_mode == EditMode.OFF:
raise NotImplementedError( 'Not yet handling bad edit context' )
-
+
( item_type, item_id ) = self.parse_html_id( kwargs.get('html_id'))
location_view = request.view_parameters.location_view
diff --git a/src/hi/apps/entity/models.py b/src/hi/apps/entity/models.py
index 19388772..2726ba08 100644
--- a/src/hi/apps/entity/models.py
+++ b/src/hi/apps/entity/models.py
@@ -318,10 +318,8 @@ class EntityPosition( SvgPositionModel ):
position_x = float( self.svg_x ),
position_y = float( self.svg_y ),
bounding_box = self.entity.entity_type.svg_icon_bounding_box,
- # rotate = float( self.svg_rotate ),
- # scale = float( self.svg_scale ),
- rotate = 0,
- scale = 4.0,
+ rotate = float( self.svg_rotate ),
+ scale = float( self.svg_scale ),
)
diff --git a/src/hi/apps/location/forms.py b/src/hi/apps/location/forms.py
index d40d6c9f..73275575 100644
--- a/src/hi/apps/location/forms.py
+++ b/src/hi/apps/location/forms.py
@@ -9,22 +9,18 @@ class SvgPositionForm(forms.Form):
svg_x = forms.DecimalField(
label = 'X',
- decimal_places = 3,
required = True,
)
svg_y = forms.DecimalField(
label = 'Y',
- decimal_places = 3,
required = True,
)
svg_scale = forms.DecimalField(
label = 'Scale',
- decimal_places = 3,
required = True,
)
svg_rotate = forms.DecimalField(
label = 'Angle',
- decimal_places = 3,
required = True,
)
@@ -47,9 +43,10 @@ class SvgPositionForm(forms.Form):
)
def to_svg_position_model( self, svg_position_model : SvgPositionModel ):
- svg_position_model.svg_x = self.svg_x
- svg_position_model.svg_y = self.svg_y
- svg_position_model.svg_scale = self.svg_scale
- svg_position_model.svg_rotate = self.svg_rotate
+ cleaned_data = self.clean()
+ svg_position_model.svg_x = cleaned_data.get( 'svg_x' )
+ svg_position_model.svg_y = cleaned_data.get( 'svg_y' )
+ svg_position_model.svg_scale = cleaned_data.get( 'svg_scale' )
+ svg_position_model.svg_rotate = cleaned_data.get( 'svg_rotate' )
return
diff --git a/src/hi/static/js/antinode.js b/src/hi/static/js/antinode.js
index 2a649490..8265c815 100644
--- a/src/hi/static/js/antinode.js
+++ b/src/hi/static/js/antinode.js
@@ -117,15 +117,15 @@
});
},
- post: function( url ) {
+ post: function( url, data ) {
$.ajax({
type: 'POST',
url: url,
data: data,
async: true,
cache: false,
- contentType: false,
- processData: false,
+ contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
+ processData: true,
success: function(data, status, xhr) {
asyncUpdateData( null, null, data, xhr );
diff --git a/src/hi/static/js/edit.js b/src/hi/static/js/edit.js
index 86fee889..0549ca4f 100644
--- a/src/hi/static/js/edit.js
+++ b/src/hi/static/js/edit.js
@@ -202,8 +202,8 @@
data = {
svg_x: dragData.elementSvgCenterPoint.x,
svg_y: dragData.elementSvgCenterPoint.y,
- svg_scale: dragData.originalSvgScale,
- svg_rotate: dragData.originalSvgRotate
+ svg_scale: dragData.originalSvgScale.x,
+ svg_rotate: dragData.originalSvgRotate.angle
};
AN.post( `/edit/svg/position/${svgItemId}`, data );