Home Information - Your home, your data, organized.
Python
A few more view refactors.
Anthony Cassandra70ba8242754a
diff --git a/src/hi/apps/collection/templates/collection/edit/panes/collection_edit.html b/src/hi/apps/collection/templates/collection/edit/panes/collection_edit.htmlindex 70989c1b..6f00b60b 100644--- a/src/hi/apps/collection/templates/collection/edit/panes/collection_edit.html+++ b/src/hi/apps/collection/templates/collection/edit/panes/collection_edit.html@@ -1,6 +1,6 @@<form action="{% url 'collection_edit' collection_id=collection.id %}"method="post"- class="form" data-async="#{{ DIVID.COLLECTION_EDIT_PANE }}">+ class="form" data-async="true">{% csrf_token %}<div>diff --git a/src/hi/apps/location/edit/async_views.py b/src/hi/apps/location/edit/async_views.pyindex b80f0606..9f8603ab 100644--- a/src/hi/apps/location/edit/async_views.py+++ b/src/hi/apps/location/edit/async_views.py@@ -55,7 +55,7 @@ class LocationEditView( View, LocationViewMixin ):location_edit_form.save()location_attribute_formset.save()- # Location name/oreder can impact many parts of UI. Full refresh is safest in that case.+ # Location name/order can impact many parts of UI. Full refresh is safest in this case.if location_edit_form.has_changed():return antinode.refresh_response()@@ -148,21 +148,17 @@ class LocationViewEditView( View, LocationViewMixin ):def post( self, request, *args, **kwargs ):location_view = self.get_location_view( request, *args, **kwargs )-location_view_edit_form = forms.LocationViewEditForm( request.POST, instance = location_view )+if not location_view_edit_form.is_valid():- context = {- 'location_view': location_view,- 'location_view_edit_form': location_view_edit_form,- }- template = get_template( 'location/edit/panes/location_view_edit.html' )- content = template.render( context, request = request )- return antinode.response(- insert_map = {- DIVID['LOCATION_VIEW_EDIT_PANE']: content,- },+ return self.location_view_edit_response(+ request = request,+ location_view = location_view,+ location_view_edit_form = location_view_edit_form,+ status_code = 400,)+ # Location View name/order can impact many parts of UI. Full refresh is safest in this case.location_view_edit_form.save()return antinode.refresh_response()@@ -175,21 +171,21 @@ class LocationViewGeometryView( View, LocationViewMixin ):location_view_geometry_form = forms.LocationViewGeometryForm( request.POST, instance = location_view )if location_view_geometry_form.is_valid():location_view_geometry_form.save()+ status_code = 200else:+ # LocationViewGeometryForm is just a subset of+ # LocationViewEditForm used when Javascript mouse/key editing+ # causes a change to the geometry. This could give some visual+ # indicator to the user, but if this chag7e was successfully+ # applied in the DOM, then the only issue would be some+ # internal or API issue.logger.warning( 'LocationView geometry form is invalid.' )+ status_code = 400- location_view_edit_form = forms.LocationViewEditForm( instance = location_view )-- context = {- 'location_view': location_view,- 'location_view_edit_form': location_view_edit_form,- }- template = get_template( 'location/edit/panes/location_view_edit.html' )- content = template.render( context, request = request )- return antinode.response(- insert_map = {- DIVID['LOCATION_VIEW_EDIT_PANE']: content,- },+ return self.location_view_edit_response(+ request = request,+ location_view = location_view,+ status_code = status_code,)diff --git a/src/hi/apps/location/edit/forms.py b/src/hi/apps/location/edit/forms.pyindex 1bcaeec0..54ae850d 100644--- a/src/hi/apps/location/edit/forms.py+++ b/src/hi/apps/location/edit/forms.py@@ -64,8 +64,7 @@ class LocationEditForm( forms.ModelForm ):'name','order_id',)--+class LocationAttributeForm( AttributeForm ):class Meta( AttributeForm.Meta ):diff --git a/src/hi/apps/location/templates/location/edit/panes/location_edit.html b/src/hi/apps/location/templates/location/edit/panes/location_edit.htmlindex c6d1eeb5..25bbab08 100644--- a/src/hi/apps/location/templates/location/edit/panes/location_edit.html+++ b/src/hi/apps/location/templates/location/edit/panes/location_edit.html@@ -1,7 +1,7 @@<h5>Location</h5><form action="{% url 'location_edit_location_edit' location_id=location.id %}"method="post" enctype="multipart/form-data"- class="form" data-async="#{{ DIVID.LOCATION_EDIT_PANE }}">+ class="form" data-async="true">{% csrf_token %}<div>@@ -16,7 +16,7 @@<form action="{% url 'location_attribute_upload' location_id=location.id %}"method="post"- class="form" data-async="#{{ DIVID.LOCATION_EDIT_PANE }}">+ class="form" data-async="true">{% csrf_token %}<div>{% include "attribute/panes/attribute_upload_form.html" with attribute_upload_form=location_attribute_upload_form %}diff --git a/src/hi/apps/location/templates/location/edit/panes/location_view_edit.html b/src/hi/apps/location/templates/location/edit/panes/location_view_edit.htmlindex f937ba50..6a8e188d 100644--- a/src/hi/apps/location/templates/location/edit/panes/location_view_edit.html+++ b/src/hi/apps/location/templates/location/edit/panes/location_view_edit.html@@ -1,7 +1,7 @@<h5>Location View</h5><form action="{% url 'location_edit_location_view_edit' location_view_id=location_view.id %}"method="post"- class="form" data-async="#{{ DIVID.LOCATION_VIEW_EDIT_PANE }}">+ class="form" data-async="true">{% csrf_token %}<div>diff --git a/src/hi/apps/location/view_mixin.py b/src/hi/apps/location/view_mixin.pyindex 7e2f3854..778cccec 100644--- a/src/hi/apps/location/view_mixin.py+++ b/src/hi/apps/location/view_mixin.py@@ -40,13 +40,14 @@ class LocationViewMixin:except LocationView.DoesNotExist:raise Http404( request )- def location_edit_response( self,- request : HttpRequest,- location : Location,- location_edit_form : forms.LocationEditForm = None,- location_attribute_formset : forms.LocationAttributeFormSet = None,- location_attribute_upload_form : forms.LocationAttributeUploadForm = None,- status_code : int = 200 ):+ def location_edit_response(+ self,+ request : HttpRequest,+ location : Location,+ location_edit_form : forms.LocationEditForm = None,+ location_attribute_formset : forms.LocationAttributeFormSet = None,+ location_attribute_upload_form : forms.LocationAttributeUploadForm = None,+ status_code : int = 200 ):if not location_edit_form:location_edit_form = forms.LocationEditForm(@@ -79,4 +80,29 @@ class LocationViewMixin:insert_map = {DIVID['LOCATION_EDIT_PANE']: content,},+ status = status_code,)++ def location_view_edit_response(+ self,+ request : HttpRequest,+ location_view : LocationView,+ location_view_edit_form : forms.LocationViewEditForm = None,+ status_code : int = 200 ):++ if not location_view_edit_form:+ location_view_edit_form = forms.LocationViewEditForm( instance = location_view )++ context = {+ 'location_view': location_view,+ 'location_view_edit_form': location_view_edit_form,+ }+ template = get_template( 'location/edit/panes/location_view_edit.html' )+ content = template.render( context, request = request )+ return antinode.response(+ insert_map = {+ DIVID['LOCATION_VIEW_EDIT_PANE']: content,+ },+ status = status_code,+ )+