Home Information - Your home, your data, organized.
Python
Refactored config and integration views and flows. WIP
Anthony Cassandra65b1028632c3
diff --git a/src/hi/apps/attribute/enums.py b/src/hi/apps/attribute/enums.pyindex a19373af..4c589dc0 100644--- a/src/hi/apps/attribute/enums.py+++ b/src/hi/apps/attribute/enums.py@@ -6,6 +6,10 @@ class AttributeType(LabeledEnum):PREDEFINED = ('Predefined', '' )CUSTOM = ('Custom', '' )+ @property+ def can_delete(self):+ return bool( self == AttributeType.CUSTOM )+class AttributeValueType(LabeledEnum):diff --git a/src/hi/apps/attribute/forms.py b/src/hi/apps/attribute/forms.pyindex fe1f4c88..8f0be4e1 100644--- a/src/hi/apps/attribute/forms.py+++ b/src/hi/apps/attribute/forms.py@@ -60,10 +60,10 @@ class AttributeForm( forms.ModelForm ):raise ValidationError( f'The attribute "{self.instance.name}" is not editable.' )if ( self.instance.attribute_type == AttributeType.PREDEFINEDand ( name != self.instance.name )):- raise ValidationError( 'Changing name forbidden for predefined attributes.' )-- if is_blank( name ):- self.add_error( 'name', 'A name is required' )+ raise ValidationError( 'Changing name forbidden for predefined attributes.' )+ value = cleaned_data.get('value')+ if self.instance.is_required and is_blank( value ):+ self.add_error( 'value', 'A value is required.')if self.cleaned_data.get('secret'):stripped_value = value.strip()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.htmlindex 62d610e2..0a5e3545 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@@ -21,7 +21,7 @@{% endif %}</div>-{% if attribute_form.show_as_editable and attribute_form.instance.is_editable %}+{% 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>diff --git a/src/hi/apps/common/processing_result.py b/src/hi/apps/common/processing_result.pyindex 6cf4931f..5974ca8e 100644--- a/src/hi/apps/common/processing_result.py+++ b/src/hi/apps/common/processing_result.py@@ -4,7 +4,15 @@ from typing import List@dataclassclass ProcessingResult:- """ Generic class for use in reporting the outcome of processing. """+ """+ Generic class for use in reporting the outcome of processing.+ Has two companion templates for rendering:++ common/panes/processing_result.html+ common/modals/processing_result.html++ Provide this as 'processing_result' in the template context.+ """title : strmessage_list : List[ str ] = field( default_factory = list )error_list : List[ str ] = field( default_factory = list )diff --git a/src/hi/apps/common/templates/common/modals/processing_result.html b/src/hi/apps/common/templates/common/modals/processing_result.htmlnew file mode 100644index 00000000..e0e0a448--- /dev/null+++ b/src/hi/apps/common/templates/common/modals/processing_result.html@@ -0,0 +1,9 @@+{% extends "modals/action_ok.html" %}++{% block title_text %}+{{ processing_result.title }}+{% endblock %}++{% block body %}+{% include "common/panes/processing_result.html" with processing_result=processing_result %}+{% endblock %}diff --git a/src/hi/apps/common/templates/common/processing_result.html b/src/hi/apps/common/templates/common/panes/processing_result.htmlsimilarity index 100%rename from src/hi/apps/common/templates/common/processing_result.htmlrename to src/hi/apps/common/templates/common/panes/processing_result.htmldiff --git a/src/hi/apps/common/templates/common/svg_file_form.html b/src/hi/apps/common/templates/common/panes/svg_file_form.htmlsimilarity index 100%rename from src/hi/apps/common/templates/common/svg_file_form.htmlrename to src/hi/apps/common/templates/common/panes/svg_file_form.htmldiff --git a/src/hi/apps/config/views.py b/src/hi/apps/config/views.pyindex cd564056..0085abbb 100644--- a/src/hi/apps/config/views.py+++ b/src/hi/apps/config/views.py@@ -48,7 +48,7 @@ class ConfigPageView( HiGridView ):#if view_type_changed and is_ajax( request ):redirect_url = request.get_full_path()- raise antinode.redirect_response( redirect_url )+ return antinode.redirect_response( redirect_url )request.config_page_type_list = list( ConfigPageType )request.current_config_page_type = self.config_page_typediff --git a/src/hi/apps/location/templates/location/edit/panes/location_add_form.html b/src/hi/apps/location/templates/location/edit/panes/location_add_form.htmlindex 35e0b412..e7f6e1ef 100644--- a/src/hi/apps/location/templates/location/edit/panes/location_add_form.html+++ b/src/hi/apps/location/templates/location/edit/panes/location_add_form.html@@ -19,4 +19,4 @@<p>Optionally add an image (SVG format) showing your property and/or house layout. Skip this and we'll uses a predefined image for you. You'll be able to update this image later.</p>-{% include "common/svg_file_form.html" with svg_file_form=location_add_form label='Select an SVG file:' %}+{% include "common/panes/svg_file_form.html" with svg_file_form=location_add_form label='Select an SVG file:' %}diff --git a/src/hi/apps/location/templates/location/edit/panes/location_svg_replace_form.html b/src/hi/apps/location/templates/location/edit/panes/location_svg_replace_form.htmlindex a2e9ee92..aa9050da 100644--- a/src/hi/apps/location/templates/location/edit/panes/location_svg_replace_form.html+++ b/src/hi/apps/location/templates/location/edit/panes/location_svg_replace_form.html@@ -13,4 +13,4 @@<p>Replace the background SVG image for this location.</p>-{% include "common/svg_file_form.html" with svg_file_form=location_svg_file_form label='Select a replacement SVG file:' %}+{% include "common/panes/svg_file_form.html" with svg_file_form=location_svg_file_form label='Select a replacement SVG file:' %}diff --git a/src/hi/constants.py b/src/hi/constants.pyindex 2a70406b..f7a95782 100644--- a/src/hi/constants.py+++ b/src/hi/constants.py@@ -11,6 +11,7 @@ DIVID = {# Config'INTEGRATION_TAB': 'hi-config-integration-tab','INTEGRATION_SETTINGS_PANE': 'hi-integration-settings',+ 'INTEGRATION_CONTENT_PANE': 'hi-integration-content','LOCATION_EDIT_PANE': 'hi-location-edit','LOCATION_VIEW_EDIT_PANE': 'hi-location-view-edit',diff --git a/src/hi/hi_async_view.py b/src/hi/hi_async_view.pyindex 2b505a3f..b850ae58 100644--- a/src/hi/hi_async_view.py+++ b/src/hi/hi_async_view.py@@ -39,6 +39,23 @@ class HiAsyncView( View ):return antinode.response(insert_map = { div_id: content },)++ def post_template_context( self, request, *args, **kwargs ) -> Dict[ str, str ]:+ """ Can raise exceptions like BadRequest, Http404, etc. """+ raise NotImplementedError('Subclasses must override this method.')++ def post_content( self, request, *args, **kwargs ) -> str:+ template_name = self.get_template_name()+ template = get_template( template_name )+ context = self.post_template_context( request, *args, **kwargs )+ return template.render( context, request = request )++ def post( self, request, *args, **kwargs ):+ div_id = self.get_target_div_id()+ content = self.post_content( request, *args, **kwargs )+ return antinode.response(+ insert_map = { div_id: content },+ )class HiSideView( HiAsyncView ):diff --git a/src/hi/integrations/core/integration_factory.py b/src/hi/integrations/core/integration_factory.pyindex f4ed150d..3397699b 100644--- a/src/hi/integrations/core/integration_factory.py+++ b/src/hi/integrations/core/integration_factory.py@@ -1,5 +1,5 @@import logging-from typing import List+from typing import Dict, Listfrom hi.apps.common.singleton import Singleton@@ -13,9 +13,40 @@ logger = logging.getLogger(__name__)class IntegrationFactory( Singleton ):def __init_singleton__( self ):- self._integration_gateway_map = dict()+ self._integration_gateway_map : Dict[ str, IntegrationGateway ] = dict()return+ def get_active_integration_data_list( self ) -> List[ IntegrationData ]:+ integration_data_list = list()+ integration_queryset = Integration.objects.filter( is_enabled = True )+ for integration in integration_queryset:+ integration_gateway = self._integration_gateway_map.get( integration.integration_id )+ if not integration_gateway:+ logger.error( f'Integration "{integration.integration_id }" in DB, but not registered.' )+ continue+ integration_metadata = integration_gateway.get_meta_data()+ integration_data = IntegrationData(+ integration_metadata = integration_metadata,+ integration = integration,+ )+ integration_data_list.apend( integration_data )+ continue+ integration_data_list.sort( key = lambda data : data.integration_metadata.label )+ return integration_data_list++ def get_default_integration_data( self ):+ integration_data_list = self.get_active_integration_data_list()+ if not integration_data_list:+ return None+ return integration_data_list[0]++++++++def get_integration_gateway_list( self ):integration_gateway_list = list( self._integration_gateway_map.values() )integration_gateway_list.sort( key = lambda gateway : gateway.get_meta_data().label )@@ -50,12 +81,6 @@ class IntegrationFactory( Singleton ):return self._integration_gateway_map[integration_id]raise KeyError( f'Unknown integration id "{integration_id}".' )- def get_default_integration_gateway( self ):- integration_gateway_list = self.get_integration_gateway_list()- if not integration_gateway_list:- return None- return integration_gateway_list[0]-def register( self, integration_gateway : IntegrationGateway ):integration_metadata = integration_gateway.get_meta_data()integration_id = integration_metadata.integration_iddiff --git a/src/hi/integrations/core/integration_gateway.py b/src/hi/integrations/core/integration_gateway.pyindex 985d0a5f..43ad5129 100644--- a/src/hi/integrations/core/integration_gateway.py+++ b/src/hi/integrations/core/integration_gateway.py@@ -19,7 +19,3 @@ class IntegrationGateway:# Should return a modal via antinode.modal_from_template() (called async)raise NotImplementedError('Subclasses must override this method')- def manage_pane_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:- # Should return HTML fragment for the management pane of the integration.- raise NotImplementedError('Subclasses must override this method')-diff --git a/src/hi/integrations/core/templates/core/modals/integrations_manage.html b/src/hi/integrations/core/templates/core/modals/integrations_manage.htmlindex 88f5f538..2741e0ed 100644--- a/src/hi/integrations/core/templates/core/modals/integrations_manage.html+++ b/src/hi/integrations/core/templates/core/modals/integrations_manage.html@@ -5,32 +5,29 @@ Manage Integrations{% endblock %}{% block body %}-{% for integration_data in integration_data_list %}--<div>- {{ integration_data.integration_metadata.label }}-</div>--<div class="col-2">- {% if integration_data.integration.is_enabled %}- <span class="text-success">ENABLED</span>- {% else %}- <span class="text-danger">DISABLED</span>- {% endif %}+<div class="d-flex justify-content-between">+ <div class="col-6">+ {{ integration_data.integration_metadata.label }}+ </div>+ <div class="col-3">+ {% if integration_data.integration.is_enabled %}+ <span class="text-success">ENABLED</span>+ {% else %}+ <span class="text-danger">DISABLED</span>+ {% endif %}+ </div>++ <div class="col-3">+ {% if integration_data.integration.is_enabled %}+ <a href="{% url 'integrations_action' integration_id=integration_data.integration.integration_id action='disable' %}"+ role="button" class="btn btn-danger btn-control" data-async="modal">DISABLE</a>++ {% else %}+ <a href="{% url 'integrations_action' integration_id=integration_data.integration.integration_id action='enable' %}"+ class="btn btn-success btn-control" role="button" data-async="modal">ENABLE</a>+ {% endif %}+ </div></div>--<div>- {% if integration_data.integration.is_enabled %}- <a href="{% url 'integrations_action' integration_id=integration_data.integration.integration_id action='disable' %}"- role="button" class="btn btn-danger btn-control" data-async="modal">DISABLE</a>-- {% else %}- <a href="{% url 'integrations_action' integration_id=integration_data.integration.integration_id action='enable' %}"- class="btn btn-success btn-control" role="button" data-async="modal">ENABLE</a>- {% endif %}-</div>-{% endfor %}-{% endblock %}diff --git a/src/hi/integrations/core/templates/core/pages/integration_base.html b/src/hi/integrations/core/templates/core/pages/integration_base.htmlindex 386ef236..a12232c7 100644--- a/src/hi/integrations/core/templates/core/pages/integration_base.html+++ b/src/hi/integrations/core/templates/core/pages/integration_base.html@@ -5,12 +5,13 @@<nav class="nav flex-column">{% for integration_data in request.integration_data_list %}<a class="nav-link {% if request.current_integration_metadata == integration_data.integration_metadata %}active{% endif %}"- href="{% url integration_data.integration_metadata.manage_url_name %}">+ href="{% url integration_data.integration_metadata.manage_url_name %}"+ data-async="true">{{ integration_data.integration_metadata.label }}</a>{% endfor %}</nav>- <div class=" flex-colum flex-grow-1">+ <div class="flex-colum flex-grow-1"><div class="tab-content"><div class="d-flex justify-content-between"><div class="h3">{{ request.current_integration_metadata.label }}</div>@@ -18,31 +19,11 @@<a class="btn btn-info" role="button"href="{% url 'integrations_manage' %}"data-async="modal">- ADD INTEGRATIONS+ MANAGE INTEGRATIONS</a></div></div>-- {% if error_message %}- <div class="alert alert-danger">- <b>Error</b>: {{ error_message }}- </div>- {% endif %}-- {% if info_message %}- <div class="alert alert-info">- {{ info_message }}- </div>- {% endif %}-- {% if processing_result %}- {% include "common/processing_result.html" with processing_result=processing_result %}- {% endif %}-----+{% block integration_content %}{% endblock %}</div>diff --git a/src/hi/integrations/core/views.py b/src/hi/integrations/core/views.pyindex 8cefe1eb..ba7c8144 100644--- a/src/hi/integrations/core/views.py+++ b/src/hi/integrations/core/views.py@@ -42,7 +42,7 @@ class IntegrationPageView( ConfigPageView ):"""def dispatch( self, request, *args, **kwargs ):- request.integration_data_list = IntegrationFactory().get_integration_data_list()+ request.integration_data_list = IntegrationFactory().get_active_integration_data_list()request.current_integration_metadata = self.integration_metadatareturn super().dispatch( request, *args, **kwargs )@@ -64,11 +64,11 @@ class IntegrationsHomeView( ConfigPageView ):def get_template_context( self, request, *args, **kwargs ):- integration_gateway = IntegrationFactory().get_default_integration_gateway()- if not integration_gateway:+ integration_data = IntegrationFactory().get_default_integration_data()+ if not integration_data:return dict()- redirect_url = reverse( integration_gateway.get_meta_data().manage_url_name )+ redirect_url = reverse( integration_data.integration_metadata.manage_url_name )raise ForceRedirectException( redirect_url )@@ -101,8 +101,6 @@ class IntegrationActionView( View ):return integration_gateway.enable_modal_view( request = request, *args, **kwargs )elif action == 'disable':return integration_gateway.disable_modal_view( request = request, *args, **kwargs )- elif action == 'manage':- return integration_gateway.manage_pane_view( request = request, *args, **kwargs )error_message = f'Unknown integration action "{action}".'except Exception as e:diff --git a/src/hi/integrations/hass/hass_gateway.py b/src/hi/integrations/hass/hass_gateway.pyindex 893f5d4c..4678883f 100644--- a/src/hi/integrations/hass/hass_gateway.py+++ b/src/hi/integrations/hass/hass_gateway.py@@ -22,9 +22,6 @@ class HassGateway( IntegrationGateway ):def disable_modal_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:return views.HassDisableView().get( request )-- def manage_pane_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:- return views.HassManageView().get( request, *args, **kwargs )IntegrationFactory().register( HassGateway() )diff --git a/src/hi/integrations/hass/templates/hass/panes/manage.html b/src/hi/integrations/hass/templates/hass/panes/manage.htmlindex ba804919..3ee56815 100644--- a/src/hi/integrations/hass/templates/hass/panes/manage.html+++ b/src/hi/integrations/hass/templates/hass/panes/manage.html@@ -1,5 +1,6 @@{% extends "core/pages/integration_base.html" %}{% block integration_content %}+<div class="col-2"><form action="{% url 'hass_sync' %}"method="POST" role="form" data-async="#{{ DIVID.INTEGRATION_TAB }}">diff --git a/src/hi/integrations/hass/views.py b/src/hi/integrations/hass/views.pyindex 619d6618..037b93b1 100644--- a/src/hi/integrations/hass/views.py+++ b/src/hi/integrations/hass/views.py@@ -1,8 +1,9 @@from django.core.exceptions import BadRequestfrom django.db import transaction-from django.http import HttpRequest+from django.shortcuts import renderfrom django.template.loader import get_template+from django.urls import reversefrom django.views.generic import Viewimport hi.apps.common.antinode as antinode@@ -12,12 +13,16 @@ from hi.integrations.core.helpers import IntegrationHelperMixinfrom hi.integrations.core.views import IntegrationPageViewfrom hi.constants import DIVID+from hi.hi_async_view import HiAsyncView, HiModalViewfrom .hass_metadata import HassMetaDatafrom .hass_manager import HassManager-class HassEnableView( View, IntegrationHelperMixin ):+class HassEnableView( HiModalView, IntegrationHelperMixin ):++ def get_template_name( self ) -> str:+ return 'hass/modals/hass_enable.html'def get(self, request, *args, **kwargs):@@ -34,10 +39,10 @@ class HassEnableView( View, IntegrationHelperMixin ):'show_as_editable': True,},)- return self.get_modal_response(- request = request,- integration_attribute_formset = integration_attribute_formset,- )+ context = {+ 'integration_attribute_formset': integration_attribute_formset,+ }+ return self.modal_response( request, context )def post(self, request, *args, **kwargs):@@ -54,41 +59,29 @@ class HassEnableView( View, IntegrationHelperMixin ):prefix = f'integration-{integration.id}',)if not integration_attribute_formset.is_valid():- return self.get_modal_response(- request = request,- integration_attribute_formset = integration_attribute_formset,- status = 400,- )+ context = {+ 'integration_attribute_formset': integration_attribute_formset,+ }+ return self.modal_response( request, context )with transaction.atomic():integration.is_enabled = Trueintegration.save()integration_attribute_formset.save()- return antinode.refresh_response()-- def get_modal_response( self,- request : HttpRequest,- integration_attribute_formset : IntegrationAttributeFormSet,- status : int = 200 ):- context = {- 'integration_attribute_formset': integration_attribute_formset,- }- return antinode.modal_from_template(- request = request,- template_name = 'hass/modals/hass_enable.html',- context = context,- status = status,- )+ redirect_url = reverse( 'hass_manage' )+ return self.redirect_response( request, redirect_url )-class HassDisableView( View ):+class HassDisableView( HiModalView, IntegrationHelperMixin ):- def get(self, request, *args, **kwargs):+ def get_template_name( self ) -> str:+ return 'hass/modals/hass_disable.html'+ def get(self, request, *args, **kwargs):context = {}- return render( request, 'hass/modals/hass_disable.html', context )+ return self.modal_response( request, context )class HassManageView( IntegrationPageView, IntegrationHelperMixin ):@@ -121,9 +114,15 @@ class HassManageView( IntegrationPageView, IntegrationHelperMixin ):}-class HassSettingsView( View, IntegrationHelperMixin ):+class HassSettingsView( HiAsyncView, IntegrationHelperMixin ):- def post(self, request, *args, **kwargs):+ def get_target_div_id( self ) -> str:+ return DIVID['INTEGRATION_SETTINGS_PANE']++ def get_template_name( self ) -> str:+ return 'hass/panes/hass_settings.html'++ def post_template_context( self, request, *args, **kwargs ):integration = self.get_or_create_integration(integration_metadata = HassMetaData,@@ -137,33 +136,25 @@ class HassSettingsView( View, IntegrationHelperMixin ):instance = integration,prefix = f'integration-{integration.id}',)- if not integration_attribute_formset.is_valid():- context = {- 'integration_attribute_formset': integration_attribute_formset,- }- template = get_template( 'hass/panes/hass_settings.html' )- content = template.render( context, request = request )- return antinode.response(- insert_map = {- DIVID['INTEGRATION_SETTINGS_PANE']: content,- },- )-- with transaction.atomic():- integration_attribute_formset.save()+ if integration_attribute_formset.is_valid():+ with transaction.atomic():+ integration_attribute_formset.save()- return antinode.refresh_response()+ context = {+ 'integration_attribute_formset': integration_attribute_formset,+ }+ return context-class HassSyncView( View ):+class HassSyncView( HiModalView ):++ def get_template_name( self ) -> str:+ return 'common/modals/processing_result.html'def post(self, request, *args, **kwargs):processing_result = HassManager().sync()-context = {- 'integration_metadata': HassMetaData,'processing_result': processing_result,}- return render( request, 'hass/panes/manage.html', context )-+ return self.modal_response( request, context )diff --git a/src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.html b/src/hi/integrations/zoneminder/templates/zoneminder/panes/zm_manage.htmlsimilarity index 99%rename from src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.htmlrename to src/hi/integrations/zoneminder/templates/zoneminder/panes/zm_manage.htmlindex 74571957..ed489456 100644--- a/src/hi/integrations/zoneminder/templates/zoneminder/panes/manage.html+++ b/src/hi/integrations/zoneminder/templates/zoneminder/panes/zm_manage.html@@ -1,5 +1,6 @@{% extends "core/pages/integration_base.html" %}{% block integration_content %}+<div class="col-2"><form action="{% url 'zm_sync' %}"method="POST" role="form" data-async="#{{ DIVID.INTEGRATION_TAB }}">diff --git a/src/hi/integrations/zoneminder/views.py b/src/hi/integrations/zoneminder/views.pyindex 7dde2d07..c10ec68e 100644--- a/src/hi/integrations/zoneminder/views.py+++ b/src/hi/integrations/zoneminder/views.py@@ -1,8 +1,8 @@from django.core.exceptions import BadRequestfrom django.db import transaction-from django.http import HttpRequestfrom django.shortcuts import renderfrom django.template.loader import get_template+from django.urls import reversefrom django.views.generic import Viewimport hi.apps.common.antinode as antinode@@ -12,12 +12,16 @@ from hi.integrations.core.helpers import IntegrationHelperMixinfrom hi.integrations.core.views import IntegrationPageViewfrom hi.constants import DIVID+from hi.hi_async_view import HiAsyncView, HiModalViewfrom .zm_manager import ZoneMinderManagerfrom .zm_metadata import ZmMetaData-class ZmEnableView( View, IntegrationHelperMixin ):+class ZmEnableView( HiModalView, IntegrationHelperMixin ):++ def get_template_name( self ) -> str:+ return 'zoneminder/modals/zm_enable.html'def get(self, request, *args, **kwargs):@@ -34,10 +38,10 @@ class ZmEnableView( View, IntegrationHelperMixin ):'show_as_editable': True,},)- return self.get_modal_response(- request = request,- integration_attribute_formset = integration_attribute_formset,- )+ context = {+ 'integration_attribute_formset': integration_attribute_formset,+ }+ return self.modal_response( request, context )def post(self, request, *args, **kwargs):@@ -54,41 +58,29 @@ class ZmEnableView( View, IntegrationHelperMixin ):prefix = f'integration-{integration.id}',)if not integration_attribute_formset.is_valid():- return self.get_modal_response(- request = request,- integration_attribute_formset = integration_attribute_formset,- status = 400,- )+ context = {+ 'integration_attribute_formset': integration_attribute_formset,+ }+ return self.modal_response( request, context, status_code = 400 )with transaction.atomic():integration.is_enabled = Trueintegration.save()integration_attribute_formset.save()- return antinode.refresh_response()-- def get_modal_response( self,- request : HttpRequest,- integration_attribute_formset : IntegrationAttributeFormSet,- status : int = 200 ):- context = {- 'integration_attribute_formset': integration_attribute_formset,- }- return antinode.modal_from_template(- request = request,- template_name = 'zoneminder/modals/zm_enable.html',- context = context,- status = status,- )+ redirect_url = reverse( 'zm_manage' )+ return self.redirect_response( request, redirect_url )-class ZmDisableView( View ):+class ZmDisableView( HiModalView, IntegrationHelperMixin ):- def get(self, request, *args, **kwargs):+ def get_template_name( self ) -> str:+ return 'zoneminder/modals/zm_disable.html'+ def get(self, request, *args, **kwargs):context = {}- return render( request, 'zoneminder/modals/zm_disable.html', context )+ return self.modal_response( request, context )class ZmManageView( IntegrationPageView, IntegrationHelperMixin ):@@ -98,7 +90,7 @@ class ZmManageView( IntegrationPageView, IntegrationHelperMixin ):return ZmMetaDatadef get_main_template_name( self ) -> str:- return 'zoneminder/panes/manage.html'+ return 'zoneminder/panes/zm_manage.html'def get_template_context( self, request, *args, **kwargs ):@@ -121,9 +113,15 @@ class ZmManageView( IntegrationPageView, IntegrationHelperMixin ):}-class ZmSettingsView( View, IntegrationHelperMixin ):+class ZmSettingsView( HiAsyncView, IntegrationHelperMixin ):- def post(self, request, *args, **kwargs):+ def get_target_div_id( self ) -> str:+ return DIVID['INTEGRATION_SETTINGS_PANE']++ def get_template_name( self ) -> str:+ return 'zoneminder/panes/zm_settings.html'++ def post_template_context( self, request, *args, **kwargs ):integration = self.get_or_create_integration(integration_metadata = ZmMetaData,@@ -137,33 +135,26 @@ class ZmSettingsView( View, IntegrationHelperMixin ):instance = integration,prefix = f'integration-{integration.id}',)- if not integration_attribute_formset.is_valid():- context = {- 'integration_attribute_formset': integration_attribute_formset,- }- template = get_template( 'zoneminder/panes/zm_settings.html' )- content = template.render( context, request = request )- return antinode.response(- insert_map = {- DIVID['INTEGRATION_SETTINGS_PANE']: content,- },- )-- with transaction.atomic():- integration_attribute_formset.save()+ if integration_attribute_formset.is_valid():+ with transaction.atomic():+ integration_attribute_formset.save()- return antinode.refresh_response()+ context = {+ 'integration_attribute_formset': integration_attribute_formset,+ }+ return context-class ZmSyncView( View ):+class ZmSyncView( HiModalView ):++ def get_template_name( self ) -> str:+ return 'common/modals/processing_result.html'def post(self, request, *args, **kwargs):processing_result = ZoneMinderManager().sync()-context = {- 'integration_metadata': ZmMetaData,'processing_result': processing_result,}- return render( request, 'zoneminder/panes/manage.html', context )+ return self.modal_response( request, context )diff --git a/src/hi/integrations/zoneminder/zm_gateway.py b/src/hi/integrations/zoneminder/zm_gateway.pyindex 3f591282..07dbdaf6 100644--- a/src/hi/integrations/zoneminder/zm_gateway.py+++ b/src/hi/integrations/zoneminder/zm_gateway.py@@ -21,6 +21,3 @@ class ZoneMinderGateway( IntegrationGateway ):def disable_modal_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:return views.ZmDisableView().get( request )-- def manage_pane_view( self, request : HttpRequest, *args, **kwargs ) -> HttpResponse:- return views.ZmManageView().get( request, *args, **kwargs )